Skip to content

Commit

Permalink
Smooth constant-width paths
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraskelton committed May 19, 2015
1 parent 8c49e23 commit 139f131
Show file tree
Hide file tree
Showing 34 changed files with 194 additions and 354 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PODS:
- Expecta (~> 0.3)
- FBSnapshotTestCase (= 1.6)
- FBSnapshotTestCase (1.6)
- jot (0.1.0):
- jot (0.1.1):
- Masonry (~> 0.6.1)
- Masonry (0.6.1)
- OCHamcrest (4.1.1)
Expand All @@ -27,7 +27,7 @@ SPEC CHECKSUMS:
Expecta: 78b4e8b0c8291fa4524d7f74016b6065c2e391ec
Expecta+Snapshots: 40c5ec43b43da3bae957f14fed5dc9177d08ec8b
FBSnapshotTestCase: 9d5fe43b29ae3a0ed8fc829477971b281038f748
jot: a511770e707de67e980043b873a42d50588fadcc
jot: e9a25948a903a5c3098b246fe401e5c6ffb4dfe7
Masonry: 4972309f2f134de9dd312f4dc4a21359b50e6caa
OCHamcrest: 6f03ffa81d12feab872638490a44ab0a6d3aca10
OCMockito: 4981140c9a9ec06c31af40f636e3c0f25f27e6b2
Expand Down
4 changes: 0 additions & 4 deletions Example/jot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
FA9118201AFA80CA00BBB7B5 /* JotTouchPointSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = FA91181F1AFA80CA00BBB7B5 /* JotTouchPointSpec.m */; };
FA9118241AFA872B00BBB7B5 /* UIImageJotSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = FA9118231AFA872B00BBB7B5 /* UIImageJotSpec.m */; };
FA9118261AFA894300BBB7B5 /* JotDrawViewSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = FA9118251AFA894300BBB7B5 /* JotDrawViewSpec.m */; };
FA9118301AFA98E200BBB7B5 /* JotConstantWidthBezierSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = FA91182F1AFA98E200BBB7B5 /* JotConstantWidthBezierSpec.m */; };
FA9FDFBD1AFAC37B00369A2B /* JotTestImage.png in Resources */ = {isa = PBXBuildFile; fileRef = FA91182D1AFA97A200BBB7B5 /* JotTestImage.png */; };
FA9FDFC01AFACCFA00369A2B /* JotTextViewSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = FA9FDFBF1AFACCFA00369A2B /* JotTextViewSpec.m */; };
FAD909731AF32D9100B34300 /* fontawesome-webfont.ttf in Resources */ = {isa = PBXBuildFile; fileRef = FAD909721AF32D9100B34300 /* fontawesome-webfont.ttf */; };
Expand Down Expand Up @@ -58,7 +57,6 @@
FA9118231AFA872B00BBB7B5 /* UIImageJotSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIImageJotSpec.m; sourceTree = "<group>"; };
FA9118251AFA894300BBB7B5 /* JotDrawViewSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JotDrawViewSpec.m; sourceTree = "<group>"; };
FA91182D1AFA97A200BBB7B5 /* JotTestImage.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = JotTestImage.png; sourceTree = "<group>"; };
FA91182F1AFA98E200BBB7B5 /* JotConstantWidthBezierSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JotConstantWidthBezierSpec.m; sourceTree = "<group>"; };
FA9FDFBF1AFACCFA00369A2B /* JotTextViewSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JotTextViewSpec.m; sourceTree = "<group>"; };
FAD909721AF32D9100B34300 /* fontawesome-webfont.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "fontawesome-webfont.ttf"; sourceTree = "<group>"; };
FAEA30E31AFA73BB00417AD8 /* JotTouchBezierSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JotTouchBezierSpec.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -149,7 +147,6 @@
FA0B14E51AF30EB300441BBD /* jotTests */ = {
isa = PBXGroup;
children = (
FA91182F1AFA98E200BBB7B5 /* JotConstantWidthBezierSpec.m */,
FA9118251AFA894300BBB7B5 /* JotDrawViewSpec.m */,
FA0E74081AFBDC9B002EF483 /* JotTextEditViewSpec.m */,
FA9FDFBF1AFACCFA00369A2B /* JotTextViewSpec.m */,
Expand Down Expand Up @@ -372,7 +369,6 @@
FA9FDFC01AFACCFA00369A2B /* JotTextViewSpec.m in Sources */,
FA9118201AFA80CA00BBB7B5 /* JotTouchPointSpec.m in Sources */,
FA0E74091AFBDC9B002EF483 /* JotTextEditViewSpec.m in Sources */,
FA9118301AFA98E200BBB7B5 /* JotConstantWidthBezierSpec.m in Sources */,
FA9118241AFA872B00BBB7B5 /* UIImageJotSpec.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
98 changes: 0 additions & 98 deletions Example/jotTests/JotConstantWidthBezierSpec.m

This file was deleted.

102 changes: 75 additions & 27 deletions Example/jotTests/JotDrawViewSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(90.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(170.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(120.f, 70.f)];
[drawView drawTouchEnded];
#ifdef IS_RECORDING
expect(drawView).to.recordSnapshotNamed(@"ConstantWidthBezierDrawing");
Expand Down Expand Up @@ -115,9 +121,15 @@
[drawView drawTouchEnded];

drawView.constantStrokeWidth = YES;
[drawView drawTouchBeganAtPoint:CGPointMake(60.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 180.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(90.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(170.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(120.f, 70.f)];
[drawView drawTouchEnded];

#ifdef IS_RECORDING
Expand All @@ -135,6 +147,12 @@
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(90.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(170.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(120.f, 70.f)];
[drawView drawTouchEnded];
[drawView clearDrawing];
#ifdef IS_RECORDING
Expand Down Expand Up @@ -201,6 +219,12 @@
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(90.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(170.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(120.f, 70.f)];
[drawView drawTouchEnded];

[drawView clearDrawing];
Expand All @@ -215,13 +239,17 @@
drawView.strokeColor = [UIColor magentaColor];
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(140.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(130.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchEnded];

drawView.strokeColor = [UIColor cyanColor];
[drawView drawTouchBeganAtPoint:CGPointMake(100.f, 50.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 40.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 0.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(200.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(180.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(200.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 40.f)];
[drawView drawTouchEnded];
#ifdef IS_RECORDING
expect(drawView).to.recordSnapshotNamed(@"ConstantWidthColorChangeBezierDrawing");
Expand Down Expand Up @@ -287,13 +315,17 @@
drawView.strokeWidth = 10.f;
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(140.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(130.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchEnded];

drawView.strokeWidth = 4.f;
[drawView drawTouchBeganAtPoint:CGPointMake(100.f, 50.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 40.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 0.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(200.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(180.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(200.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 40.f)];
[drawView drawTouchEnded];
#ifdef IS_RECORDING
expect(drawView).to.recordSnapshotNamed(@"ConstantWidthWidthChangeBezierDrawing");
Expand Down Expand Up @@ -360,14 +392,18 @@
drawView.strokeWidth = 10.f;
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(140.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(130.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchEnded];

drawView.strokeColor = [UIColor cyanColor];
drawView.strokeWidth = 4.f;
[drawView drawTouchBeganAtPoint:CGPointMake(100.f, 50.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 40.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 0.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(200.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(180.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(200.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 40.f)];
[drawView drawTouchEnded];

drawView.constantStrokeWidth = NO;
Expand Down Expand Up @@ -400,14 +436,18 @@
drawView.strokeWidth = 10.f;
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(140.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(130.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchEnded];

drawView.strokeColor = [UIColor cyanColor];
drawView.strokeWidth = 4.f;
[drawView drawTouchBeganAtPoint:CGPointMake(100.f, 50.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 40.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 0.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(200.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(180.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(200.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 40.f)];
[drawView drawTouchEnded];

drawView.constantStrokeWidth = NO;
Expand Down Expand Up @@ -457,14 +497,18 @@
drawView.strokeWidth = 10.f;
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(140.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(130.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchEnded];

drawView.strokeColor = [UIColor cyanColor];
drawView.strokeWidth = 4.f;
[drawView drawTouchBeganAtPoint:CGPointMake(100.f, 50.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 40.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 0.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(200.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(180.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(200.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 40.f)];
[drawView drawTouchEnded];

drawView.constantStrokeWidth = NO;
Expand Down Expand Up @@ -497,14 +541,18 @@
drawView.strokeWidth = 10.f;
[drawView drawTouchBeganAtPoint:CGPointMake(0.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 150.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(140.f, 180.f)];
[drawView drawTouchMovedToPoint:CGPointMake(130.f, 170.f)];
[drawView drawTouchMovedToPoint:CGPointMake(40.f, 20.f)];
[drawView drawTouchEnded];

drawView.strokeColor = [UIColor cyanColor];
drawView.strokeWidth = 4.f;
[drawView drawTouchBeganAtPoint:CGPointMake(100.f, 50.f)];
[drawView drawTouchMovedToPoint:CGPointMake(10.f, 40.f)];
[drawView drawTouchMovedToPoint:CGPointMake(100.f, 0.f)];
[drawView drawTouchBeganAtPoint:CGPointMake(200.f, 0.f)];
[drawView drawTouchMovedToPoint:CGPointMake(150.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(180.f, 100.f)];
[drawView drawTouchMovedToPoint:CGPointMake(200.f, 120.f)];
[drawView drawTouchMovedToPoint:CGPointMake(20.f, 40.f)];
[drawView drawTouchEnded];

drawView.constantStrokeWidth = NO;
Expand Down
28 changes: 27 additions & 1 deletion Example/jotTests/JotTouchBezierSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
expect(imageView).to.haveValidSnapshotNamed(@"AnotherVariableWidthBezierImage");
});

it(@"draws a constant width cubic bezier curve", ^{
it(@"draws a constant width cubic bezier curve if velocity is constant", ^{

bezier.startPoint = CGPointMake(0.f, 0.f);
bezier.endPoint = CGPointMake(200.f, 100.f);
Expand All @@ -113,6 +113,32 @@
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
#ifdef IS_RECORDING
expect(imageView).to.recordSnapshotNamed(@"SameStartAndEndWidthBezierImage");
#endif
expect(imageView).to.haveValidSnapshotNamed(@"SameStartAndEndWidthBezierImage");
});

it(@"draws a constant width cubic bezier curve if constantwidth is true", ^{

bezier.startPoint = CGPointMake(0.f, 0.f);
bezier.endPoint = CGPointMake(200.f, 100.f);
bezier.controlPoint1 = CGPointMake(122.f, 14.f);
bezier.controlPoint2 = CGPointMake(42.f, 77.f);
bezier.constantWidth = YES;

bezier.startWidth = 4.f;
bezier.endWidth = 6.f;

bezier.strokeColor = [UIColor blueColor];

CGSize imageSize = CGSizeMake(200.f, 100.f);
UIGraphicsBeginImageContextWithOptions(imageSize, NO, 2.f);
[bezier jotDrawBezier];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
#ifdef IS_RECORDING
expect(imageView).to.recordSnapshotNamed(@"ConstantWidthBezierImage");
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 139f131

Please sign in to comment.