/
JCPolygonSet.mm
95 lines (76 loc) · 2.8 KB
/
JCPolygonSet.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// JCPolygonSet.m
// Graphic3DMatrixExample
//
// Created by Jamie Cho on 2010-11-17.
// Copyright 2010 Jamie Cho. All rights reserved.
//
#import "JCPolygonSet.h"
@implementation JCPolygonSet
@synthesize polygons;
+(JCPolygonSet *)speedSignPolygonSet {
JCPolygonSet *polygons = [[[JCPolygonSet alloc] init] autorelease];
// Model the post
std::vector<jcho::Matrix<double> > postPoints;
postPoints.push_back(makePoint(-.25, 0, 0));
postPoints.push_back(makePoint(.25, 0, 0));
postPoints.push_back(makePoint(.25, 5, 0));
postPoints.push_back(makePoint(-.25, 5, 0));
JCPolygon *post = [[[JCPolygon alloc] initWithPoints:postPoints andColor:[NSColor grayColor]] autorelease];
[polygons.polygons addObject:post];
// Model the sign
std::vector<jcho::Matrix<double> > signPoints;
signPoints.push_back(makePoint(-1, 5, 0));
signPoints.push_back(makePoint(1, 5, 0));
signPoints.push_back(makePoint(1, 8, 0));
signPoints.push_back(makePoint(-1, 8, 0));
JCPolygon *sign = [[[JCPolygon alloc] initWithPoints:signPoints andColor:[NSColor whiteColor]] autorelease];
[polygons.polygons addObject:sign];
return polygons;
}
+(JCPolygonSet *)warningSignPolygonSet {
JCPolygonSet *polygons = [[[JCPolygonSet alloc] init] autorelease];
// Model the post
std::vector<jcho::Matrix<double> > postPoints;
postPoints.push_back(makePoint(-.25, 0, 0));
postPoints.push_back(makePoint(.25, 0, 0));
postPoints.push_back(makePoint(.25, 5, 0));
postPoints.push_back(makePoint(-.25, 5, 0));
JCPolygon *post = [[[JCPolygon alloc] initWithPoints:postPoints andColor:[NSColor grayColor]] autorelease];
[polygons.polygons addObject:post];
// Model the sign
std::vector<jcho::Matrix<double> > signPoints;
signPoints.push_back(makePoint(0, 9, 0));
signPoints.push_back(makePoint(-1.5, 5 , 0));
signPoints.push_back(makePoint(1.5, 5, 0));
JCPolygon *sign = [[[JCPolygon alloc] initWithPoints:signPoints andColor:[NSColor yellowColor]] autorelease];
[polygons.polygons addObject:sign];
return polygons;
}
-(id)init {
if (self = [super init]) {
polygons = [[NSMutableSet alloc] init];
}
return self;
}
-(id)initWithPolygonSet:(JCPolygonSet *)polygonSet andTransform:(const jcho::Matrix<double> &)transform {
if (self = [self init]) {
for(JCPolygon *polygon in polygonSet.polygons)
[polygons addObject:[[[JCPolygon alloc] initWithPolygon:polygon andTransform:transform] autorelease]];
}
return self;
}
-(void)dealloc {
[polygons release];
[super dealloc];
}
-(NSString *)description {
NSMutableString *description = [NSMutableString string];
[description appendString:@"JCPolygonSet {\n"];
for(JCPolygon *polygon in polygons) {
[description appendString:[polygon description]];
}
[description appendString:@"}\n"];
return description;
}
@end