5
// Created by döme on 06.08.2009.
6
// Copyright 2009 __MyCompanyName__. All rights reserved.
9
#import "JigsawPiece.h"
10
#import "Triangulation.h"
13
@implementation JigsawPiece
17
if (!(self = [super init]))
20
neighbours = [[NSMutableDictionary alloc] init];
21
fillDrawables = [[NSMutableArray alloc] init];
22
outlineDrawables = [[NSMutableArray alloc] init];
23
outlines = [[NSMutableArray alloc] init];
27
// body = cpBodyNew(1, 1);
34
[fillDrawables release];
35
[outlineDrawables release];
37
// cpBodyDestroy(body);
44
- (void) setOutlineColor: (v3*) cptr
49
- (void) rotateByAngle: (float) alpha aroundPoint: (CGPoint) p
51
CGPoint r = CGPointSub(position, p);
53
CGAffineTransform R = CGAffineTransformMakeRotation(alpha);
56
position = CGPointAdd(p, CGPointTransform(r, R));
60
NSString* FillDrawablesKey = @"fillDrawables";
62
- (id) initWithCoder: (NSCoder*) coder
64
if (!(self = [super init]))
67
NSArray* array = [coder decodeObjectForKey: @"outlines"];
68
outlines = [[NSMutableArray alloc] init];
69
for (id data in array)
70
[outlines addObject: [(id)CreateBezierPathFromData(data) autorelease]];
72
orientation = [coder decodeFloatForKey: @"orientation"];
73
initialPos.x = [coder decodeFloatForKey: @"initialPos.x"];
74
initialPos.y = [coder decodeFloatForKey: @"initialPos.y"];
75
position.x = [coder decodeFloatForKey: @"position.x"];
76
position.y = [coder decodeFloatForKey: @"position.y"];
78
NSArray* nkeys = [coder decodeObjectForKey: @"neighbourKeys"];
79
NSArray* nvals = [coder decodeObjectForKey: @"neighbourValues"];
81
neighbours = [[NSMutableDictionary alloc] init];
82
for (size_t i = 0; i < [nkeys count]; ++i)
84
[neighbours setObject: [nvals objectAtIndex: i] forKey: [NSValue valueWithPointer: [nkeys objectAtIndex: i]]];
87
fillDrawables = [[coder decodeObjectForKey: FillDrawablesKey] mutableCopy];
88
outlineDrawables = [[coder decodeObjectForKey: @"outlineDrawables"] mutableCopy];
95
- (void) encodeWithCoder: (NSCoder*) coder
97
NSMutableArray* array = [NSMutableArray array];
98
for (id outline in outlines)
100
[array addObject: BezierPathToData((CGPathRef)outline)];
102
[coder encodeObject: array forKey: @"outlines"];
104
[coder encodeFloat: initialPos.x forKey: @"initialPos.x"];
105
[coder encodeFloat: initialPos.y forKey: @"initialPos.y"];
106
[coder encodeFloat: position.x forKey: @"position.x"];
107
[coder encodeFloat: position.y forKey: @"position.y"];
108
[coder encodeFloat: orientation forKey: @"orientation"];
110
NSMutableArray* keys = [NSMutableArray array];
111
NSMutableArray* values = [NSMutableArray array];
113
for (id key in neighbours)
115
[keys addObject: (id)[key pointerValue]];
116
[values addObject: [neighbours objectForKey: key]];
119
[coder encodeObject: keys forKey: @"neighbourKeys"];
120
[coder encodeObject: values forKey: @"neighbourValues"];
121
[coder encodeObject: fillDrawables forKey: FillDrawablesKey];
122
[coder encodeObject: outlineDrawables forKey: @"outlineDrawables"];
126
@synthesize fillDrawables, outlineDrawables, outlines, initialPos, position, orientation, neighbours, outlineColor, ghostZoom;
130
@implementation JigsawNeighbour
132
- (id) initWithCoder: (NSCoder*) coder
134
if (!(self = [super init]))
137
attachmentPoint.x = [coder decodeFloatForKey: @"attachmentPoint.x"];
138
attachmentPoint.y = [coder decodeFloatForKey: @"attachmentPoint.y"];
139
direction = [coder decodeIntegerForKey: @"direction"];
144
- (void) encodeWithCoder: (NSCoder*) coder
146
[coder encodeFloat: attachmentPoint.x forKey: @"attachmentPoint.x"];
147
[coder encodeFloat: attachmentPoint.y forKey: @"attachmentPoint.y"];
148
[coder encodeInteger: direction forKey: @"direction"];
158
@synthesize attachmentPoint, direction;