Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.

Commit 706fe38

Browse files
committed
First commit
0 parents  commit 706fe38

30 files changed

+3498
-0
lines changed

.gitignore

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Mac OS X Finder and whatnot
2+
.DS_Store
3+
4+
5+
# Sparkle distribution Private Key (Don't check me in!)
6+
dsa_priv.pem
7+
8+
9+
# XCode (and ancestors) per-user config (very noisy, and not relevant)
10+
*.mode1
11+
*.mode1v3
12+
*.mode2v3
13+
*.perspective
14+
*.perspectivev3
15+
*.pbxuser
16+
17+
18+
# Generated files
19+
VersionX-revision.h
20+
21+
22+
# build products
23+
build/
24+
*.[o]
25+
26+
# Other source repository archive directories (protects when importing)
27+
.hg
28+
.svn
29+
CVS
30+
31+
32+
# automatic backup files
33+
*~.nib
34+
*.swp
35+
*~
36+
*(Autosaved).rtfd/
37+
Backup[ ]of[ ]*.pages/
38+
Backup[ ]of[ ]*.key/
39+
Backup[ ]of[ ]*.numbers/
40+
41+
*.pyc
42+
*~
43+
.*.swp
44+
.svn
45+
tags
46+
.DS_Store
47+
Thumbs.db
48+
appversion.py
49+
scripts/scrape_data/*
50+
static/images/Thumbs.db
51+
52+
Resources/Icon.png
53+
Resources/*/Localizable.strings
54+
Resources/*/Custom.strings
55+
Resources/Config.strings
56+
Resources/Config.strings
57+
Resources/iPhone-bg.png
58+
Resources/iPhone-logo.png
59+
60+
Resources/quickedit-logo.png
61+
Resources/tos.html
62+
Resources/UserTypes.plist
63+
Resources/LookingFor.plist
64+
Resources/browse-logo.png
65+
66+
Resources-iPad/iPad-logo.png
67+
Resources-iPad/iPad-bg.png
68+
Resources-iPad/IconPad.png
69+
Husband Material.xcodeproj/project.xcworkspace/*
70+
Husband Material.xcodeproj/xcuserdata/*
71+

Classes/Curve/BezierCurve.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// BezierCurve.h
3+
// Curve
4+
//
5+
// BezierCurve is an abstract class representing a Bezier curve of any degree. It should not be instantiated
6+
// directly. Use LinearBezierCurve, QuadraticBezierCurve, and CubicBezierCurve instead.
7+
//
8+
// Created by Bryan Spitz on 10-01-26.
9+
// Copyright 2010 Bryan Spitz. All rights reserved.
10+
//
11+
12+
#import <Foundation/Foundation.h>
13+
14+
15+
@interface BezierCurve : NSObject {
16+
CGPoint p1, p2;
17+
}
18+
19+
// Start point
20+
@property (nonatomic, readonly) CGPoint p1;
21+
// End point
22+
@property (nonatomic, readonly) CGPoint p2;
23+
24+
// An array of two Bezier curves of the same degree as the original.
25+
// These two curves, placed together, encompass exactly the same points
26+
// as the original.
27+
-(NSArray *)subdivided;
28+
29+
// Returns whether the curve may be treated as linear for drawing or other purposes.
30+
-(BOOL)isNearLinear;
31+
32+
// Returns an array of NSValues representing CGPoints dividing the curve into near-linear subsections.
33+
-(NSArray *)asPointArray;
34+
35+
// The same as asPointArray, but adds points to an existing array for efficiency.
36+
-(void)addToPointArray:(NSMutableArray *)pointArray;
37+
@end

Classes/Curve/BezierCurve.m

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//
2+
// BezierCurve.m
3+
// Curve
4+
//
5+
// Created by Bryan Spitz on 10-01-26.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "BezierCurve.h"
10+
11+
12+
@implementation BezierCurve
13+
@synthesize p1, p2;
14+
15+
- (NSArray *)subdivided {
16+
[self doesNotRecognizeSelector:_cmd];
17+
return nil;
18+
}
19+
20+
- (BOOL)isNearLinear {
21+
[self doesNotRecognizeSelector:_cmd];
22+
return NO;
23+
}
24+
25+
- (NSArray *)asPointArray {
26+
[self doesNotRecognizeSelector:_cmd];
27+
return nil;
28+
}
29+
30+
- (void)addToPointArray:(NSMutableArray *)pointArray {
31+
[self doesNotRecognizeSelector:_cmd];
32+
}
33+
34+
@end

Classes/Curve/CGPointArithmetic.h

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* CGPointArithmetic.h
3+
* Curve
4+
*
5+
* A set of tools for doing CGPoint calculations. For efficiency, these are preprocessor macros
6+
* instead of C functions.
7+
*
8+
* Created by Bryan Spitz on 10-01-26.
9+
* Copyright 2010 Bryan Spitz. All rights reserved.
10+
*
11+
*/
12+
13+
#import <math.h>
14+
15+
#define CGPointDifference(p1,p2) (CGPointMake(((p1.x) - (p2.x)), ((p1.y) - (p2.y))))
16+
#define CGPointMagnitude(p) sqrt(p.x*p.x + p.y*p.y)
17+
#define CGPointSlope(p) (p.y / p.x)
18+
#define CGPointScale(p, d) CGPointMake(p.x * d, p.y * d)
19+
#define CGPointAdd(p1, p2) CGPointMake(p1.x + p2.x, p1.y + p2.y)
20+
#define CGPointMidpoint(p1, p2) CGPointMake((p1.x + p2.x)/2., (p1.y + p2.y)/2.)

Classes/Curve/CatmullRomSpline.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// CatmullRomSpline.h
3+
// Curve
4+
//
5+
// CatmullRomSpline is a class representing a Catmull-Rom Spline (i.e. a spline with
6+
// continuous derivative, passing through a set of arbitrary control points). The tangent
7+
// of the spline at any control point (except the first and last) is parallel to the
8+
// line connecting the previous control point with the next one.
9+
//
10+
// Most of the segments of a CatmullRomSpline are cubic bezier curves. The last segment is
11+
// a quadratic curve. When a new point is added, the last segment is removed and replaced with a
12+
// cubic curve making use of the new control point information, and a new quadratic curve is
13+
// added to the end. Application that attempt to cache data related to the spline should be
14+
// aware that the final points are subject to change.
15+
//
16+
// Created by Bryan Spitz on 10-01-28.
17+
// Copyright 2010 Bryan Spitz. All rights reserved.
18+
//
19+
20+
#import <Foundation/Foundation.h>
21+
#import "Spline.h"
22+
23+
@interface CatmullRomSpline : Spline {
24+
CGPoint p3, p2, p1, p;
25+
}
26+
27+
+(CatmullRomSpline *)catmullRomSplineAtPoint:(CGPoint)start;
28+
29+
// Add a control point, through which the spline must pass, to the end of the spline.
30+
-(void)addPoint:(CGPoint)point;
31+
32+
@end

Classes/Curve/CatmullRomSpline.m

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//
2+
// CatmullRomSpline.m
3+
// Curve
4+
//
5+
// Created by Bryan Spitz on 10-01-28.
6+
// Copyright 2010 __MyCompanyName__. All rights reserved.
7+
//
8+
9+
#import "CatmullRomSpline.h"
10+
#import "CGPointArithmetic.h"
11+
12+
13+
@implementation CatmullRomSpline
14+
15+
16+
+(CatmullRomSpline *)catmullRomSplineAtPoint:(CGPoint)start {
17+
return [[[CatmullRomSpline alloc] initAtPoint:start] autorelease];
18+
}
19+
20+
21+
-(id)initAtPoint:(CGPoint)start {
22+
if (self = [super initAtPoint:start]) {
23+
p = start;
24+
p1 = start;
25+
p2 = start;
26+
p3 = start;
27+
}
28+
29+
return self;
30+
}
31+
32+
-(void)addPoint:(CGPoint)point {
33+
CGPoint diff = CGPointMake(point.x - p.x, point.y - p.y);
34+
double length = sqrt(pow(diff.x, 2) + pow(diff.y, 2));
35+
36+
37+
38+
if ([curves count] > 0) {
39+
[self removeLastCurve];
40+
}
41+
42+
43+
if (length >= 15) {
44+
p3 = p2;
45+
p2 = p1;
46+
p1 = p;
47+
p = point;
48+
49+
CGPoint tangent = CGPointMake((p1.x - p3.x), (p1.y - p3.y));
50+
CGFloat tangentLength = CGPointMagnitude(tangent);
51+
CGPoint unitTangent = (tangentLength == 0.)?tangent:CGPointScale(tangent, 1. / tangentLength);
52+
CGPoint diff = CGPointDifference (p1, p2);
53+
CGFloat desiredLength = CGPointMagnitude(diff) / 3.;
54+
CGPoint desiredTangent = CGPointScale(unitTangent, desiredLength);
55+
56+
CGPoint ctrl1 = CGPointMake(p2.x + desiredTangent.x, p2.y + desiredTangent.y);
57+
58+
tangent = CGPointMake((p.x - p2.x), (p.y - p2.y));
59+
tangentLength = CGPointMagnitude(tangent);
60+
unitTangent = (tangentLength == 0.)?tangent:CGPointScale(tangent, 1. / tangentLength);
61+
desiredTangent = CGPointScale(unitTangent, desiredLength);
62+
63+
CGPoint ctrl2 = CGPointMake(p1.x - desiredTangent.x, p1.y - desiredTangent.y);
64+
65+
[self addCubicCurveWithControl1:ctrl1 control2:ctrl2 toPoint:p1];
66+
67+
68+
}
69+
70+
CGPoint currtemp = current;
71+
CGPoint tangent2 = CGPointMake((p.x - p2.x)/5., (p.y - p2.y)/5.);
72+
CGPoint ctrl = CGPointMake(p1.x + tangent2.x, p1.y + tangent2.y);
73+
[self addQuadCurveWithControl:ctrl toPoint:point];
74+
current = currtemp;
75+
76+
77+
}
78+
@end

Classes/Curve/CubicBezierCurve.h

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// CubicBezierCurve.h
3+
// Curve
4+
//
5+
// Created by Bryan Spitz on 10-01-28.
6+
// Copyright 2010 Bryan Spitz. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "BezierCurve.h"
11+
12+
@interface CubicBezierCurve : BezierCurve {
13+
CGPoint ctrl1, ctrl2;
14+
}
15+
16+
+(CubicBezierCurve *)cubicCurveWithStart:(CGPoint)start controlPoint1:(CGPoint)control1 controlPoint2:(CGPoint)control2 end:(CGPoint)end;
17+
-(id)initWithStart:(CGPoint)start controlPoint1:(CGPoint)control1 controlPoint2:(CGPoint)control2 end:(CGPoint)end;
18+
19+
@end

0 commit comments

Comments
 (0)