Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
esilverberg committed Jun 19, 2011
0 parents commit 706fe38
Show file tree
Hide file tree
Showing 30 changed files with 3,498 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .gitignore
@@ -0,0 +1,71 @@
# Mac OS X Finder and whatnot
.DS_Store


# Sparkle distribution Private Key (Don't check me in!)
dsa_priv.pem


# XCode (and ancestors) per-user config (very noisy, and not relevant)
*.mode1
*.mode1v3
*.mode2v3
*.perspective
*.perspectivev3
*.pbxuser


# Generated files
VersionX-revision.h


# build products
build/
*.[o]

# Other source repository archive directories (protects when importing)
.hg
.svn
CVS


# automatic backup files
*~.nib
*.swp
*~
*(Autosaved).rtfd/
Backup[ ]of[ ]*.pages/
Backup[ ]of[ ]*.key/
Backup[ ]of[ ]*.numbers/

*.pyc
*~
.*.swp
.svn
tags
.DS_Store
Thumbs.db
appversion.py
scripts/scrape_data/*
static/images/Thumbs.db

Resources/Icon.png
Resources/*/Localizable.strings
Resources/*/Custom.strings
Resources/Config.strings
Resources/Config.strings
Resources/iPhone-bg.png
Resources/iPhone-logo.png
Resources/iPhone-logo@2x.png
Resources/quickedit-logo.png
Resources/tos.html
Resources/UserTypes.plist
Resources/LookingFor.plist
Resources/browse-logo.png

Resources-iPad/iPad-logo.png
Resources-iPad/iPad-bg.png
Resources-iPad/IconPad.png
Husband Material.xcodeproj/project.xcworkspace/*
Husband Material.xcodeproj/xcuserdata/*

37 changes: 37 additions & 0 deletions Classes/Curve/BezierCurve.h
@@ -0,0 +1,37 @@
//
// BezierCurve.h
// Curve
//
// BezierCurve is an abstract class representing a Bezier curve of any degree. It should not be instantiated
// directly. Use LinearBezierCurve, QuadraticBezierCurve, and CubicBezierCurve instead.
//
// Created by Bryan Spitz on 10-01-26.
// Copyright 2010 Bryan Spitz. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface BezierCurve : NSObject {
CGPoint p1, p2;
}

// Start point
@property (nonatomic, readonly) CGPoint p1;
// End point
@property (nonatomic, readonly) CGPoint p2;

// An array of two Bezier curves of the same degree as the original.
// These two curves, placed together, encompass exactly the same points
// as the original.
-(NSArray *)subdivided;

// Returns whether the curve may be treated as linear for drawing or other purposes.
-(BOOL)isNearLinear;

// Returns an array of NSValues representing CGPoints dividing the curve into near-linear subsections.
-(NSArray *)asPointArray;

// The same as asPointArray, but adds points to an existing array for efficiency.
-(void)addToPointArray:(NSMutableArray *)pointArray;
@end
34 changes: 34 additions & 0 deletions Classes/Curve/BezierCurve.m
@@ -0,0 +1,34 @@
//
// BezierCurve.m
// Curve
//
// Created by Bryan Spitz on 10-01-26.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "BezierCurve.h"


@implementation BezierCurve
@synthesize p1, p2;

- (NSArray *)subdivided {
[self doesNotRecognizeSelector:_cmd];
return nil;
}

- (BOOL)isNearLinear {
[self doesNotRecognizeSelector:_cmd];
return NO;
}

- (NSArray *)asPointArray {
[self doesNotRecognizeSelector:_cmd];
return nil;
}

- (void)addToPointArray:(NSMutableArray *)pointArray {
[self doesNotRecognizeSelector:_cmd];
}

@end
20 changes: 20 additions & 0 deletions Classes/Curve/CGPointArithmetic.h
@@ -0,0 +1,20 @@
/*
* CGPointArithmetic.h
* Curve
*
* A set of tools for doing CGPoint calculations. For efficiency, these are preprocessor macros
* instead of C functions.
*
* Created by Bryan Spitz on 10-01-26.
* Copyright 2010 Bryan Spitz. All rights reserved.
*
*/

#import <math.h>

#define CGPointDifference(p1,p2) (CGPointMake(((p1.x) - (p2.x)), ((p1.y) - (p2.y))))
#define CGPointMagnitude(p) sqrt(p.x*p.x + p.y*p.y)
#define CGPointSlope(p) (p.y / p.x)
#define CGPointScale(p, d) CGPointMake(p.x * d, p.y * d)
#define CGPointAdd(p1, p2) CGPointMake(p1.x + p2.x, p1.y + p2.y)
#define CGPointMidpoint(p1, p2) CGPointMake((p1.x + p2.x)/2., (p1.y + p2.y)/2.)
32 changes: 32 additions & 0 deletions Classes/Curve/CatmullRomSpline.h
@@ -0,0 +1,32 @@
//
// CatmullRomSpline.h
// Curve
//
// CatmullRomSpline is a class representing a Catmull-Rom Spline (i.e. a spline with
// continuous derivative, passing through a set of arbitrary control points). The tangent
// of the spline at any control point (except the first and last) is parallel to the
// line connecting the previous control point with the next one.
//
// Most of the segments of a CatmullRomSpline are cubic bezier curves. The last segment is
// a quadratic curve. When a new point is added, the last segment is removed and replaced with a
// cubic curve making use of the new control point information, and a new quadratic curve is
// added to the end. Application that attempt to cache data related to the spline should be
// aware that the final points are subject to change.
//
// Created by Bryan Spitz on 10-01-28.
// Copyright 2010 Bryan Spitz. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Spline.h"

@interface CatmullRomSpline : Spline {
CGPoint p3, p2, p1, p;
}

+(CatmullRomSpline *)catmullRomSplineAtPoint:(CGPoint)start;

// Add a control point, through which the spline must pass, to the end of the spline.
-(void)addPoint:(CGPoint)point;

@end
78 changes: 78 additions & 0 deletions Classes/Curve/CatmullRomSpline.m
@@ -0,0 +1,78 @@
//
// CatmullRomSpline.m
// Curve
//
// Created by Bryan Spitz on 10-01-28.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "CatmullRomSpline.h"
#import "CGPointArithmetic.h"


@implementation CatmullRomSpline


+(CatmullRomSpline *)catmullRomSplineAtPoint:(CGPoint)start {
return [[[CatmullRomSpline alloc] initAtPoint:start] autorelease];
}


-(id)initAtPoint:(CGPoint)start {
if (self = [super initAtPoint:start]) {
p = start;
p1 = start;
p2 = start;
p3 = start;
}

return self;
}

-(void)addPoint:(CGPoint)point {
CGPoint diff = CGPointMake(point.x - p.x, point.y - p.y);
double length = sqrt(pow(diff.x, 2) + pow(diff.y, 2));



if ([curves count] > 0) {
[self removeLastCurve];
}


if (length >= 15) {
p3 = p2;
p2 = p1;
p1 = p;
p = point;

CGPoint tangent = CGPointMake((p1.x - p3.x), (p1.y - p3.y));
CGFloat tangentLength = CGPointMagnitude(tangent);
CGPoint unitTangent = (tangentLength == 0.)?tangent:CGPointScale(tangent, 1. / tangentLength);
CGPoint diff = CGPointDifference (p1, p2);
CGFloat desiredLength = CGPointMagnitude(diff) / 3.;
CGPoint desiredTangent = CGPointScale(unitTangent, desiredLength);

CGPoint ctrl1 = CGPointMake(p2.x + desiredTangent.x, p2.y + desiredTangent.y);

tangent = CGPointMake((p.x - p2.x), (p.y - p2.y));
tangentLength = CGPointMagnitude(tangent);
unitTangent = (tangentLength == 0.)?tangent:CGPointScale(tangent, 1. / tangentLength);
desiredTangent = CGPointScale(unitTangent, desiredLength);

CGPoint ctrl2 = CGPointMake(p1.x - desiredTangent.x, p1.y - desiredTangent.y);

[self addCubicCurveWithControl1:ctrl1 control2:ctrl2 toPoint:p1];


}

CGPoint currtemp = current;
CGPoint tangent2 = CGPointMake((p.x - p2.x)/5., (p.y - p2.y)/5.);
CGPoint ctrl = CGPointMake(p1.x + tangent2.x, p1.y + tangent2.y);
[self addQuadCurveWithControl:ctrl toPoint:point];
current = currtemp;


}
@end
19 changes: 19 additions & 0 deletions Classes/Curve/CubicBezierCurve.h
@@ -0,0 +1,19 @@
//
// CubicBezierCurve.h
// Curve
//
// Created by Bryan Spitz on 10-01-28.
// Copyright 2010 Bryan Spitz. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "BezierCurve.h"

@interface CubicBezierCurve : BezierCurve {
CGPoint ctrl1, ctrl2;
}

+(CubicBezierCurve *)cubicCurveWithStart:(CGPoint)start controlPoint1:(CGPoint)control1 controlPoint2:(CGPoint)control2 end:(CGPoint)end;
-(id)initWithStart:(CGPoint)start controlPoint1:(CGPoint)control1 controlPoint2:(CGPoint)control2 end:(CGPoint)end;

@end

0 comments on commit 706fe38

Please sign in to comment.