From 2d3de20b2a1ebfe925dd8fd7292eb692dbafb386 Mon Sep 17 00:00:00 2001 From: Jakub Suder Date: Thu, 22 Mar 2012 22:30:58 +0100 Subject: [PATCH] renamed triangle to shape --- MovingShapes.xcodeproj/project.pbxproj | 12 ++++++------ MovingShapes/{Triangle.h => Shape.h} | 4 ++-- MovingShapes/{Triangle.m => Shape.m} | 6 +++--- MovingShapes/ShapeView.h | 4 ++-- MovingShapes/ShapeView.m | 24 ++++++++++++------------ MovingShapes/ViewController.h | 4 ++-- MovingShapes/ViewController.m | 20 ++++++++++---------- 7 files changed, 37 insertions(+), 37 deletions(-) rename MovingShapes/{Triangle.h => Shape.h} (87%) rename MovingShapes/{Triangle.m => Shape.m} (86%) diff --git a/MovingShapes.xcodeproj/project.pbxproj b/MovingShapes.xcodeproj/project.pbxproj index 95f5066..b994483 100644 --- a/MovingShapes.xcodeproj/project.pbxproj +++ b/MovingShapes.xcodeproj/project.pbxproj @@ -15,7 +15,7 @@ 5878DA5B151B9A03003B758C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 5878DA5A151B9A03003B758C /* AppDelegate.m */; }; 5878DA5E151B9A03003B758C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5878DA5D151B9A03003B758C /* ViewController.m */; }; 5878DA61151B9A03003B758C /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5878DA5F151B9A03003B758C /* ViewController.xib */; }; - 9598E398151B9C5E000F1A36 /* Triangle.m in Sources */ = {isa = PBXBuildFile; fileRef = 9598E397151B9C5E000F1A36 /* Triangle.m */; }; + 9598E398151B9C5E000F1A36 /* Shape.m in Sources */ = {isa = PBXBuildFile; fileRef = 9598E397151B9C5E000F1A36 /* Shape.m */; }; 9598E39D151B9D35000F1A36 /* ShapeView.m in Sources */ = {isa = PBXBuildFile; fileRef = 9598E39C151B9D35000F1A36 /* ShapeView.m */; }; 9598E3A1151B9F77000F1A36 /* HKPoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 9598E3A0151B9F77000F1A36 /* HKPoint.m */; }; 9598E3B3151BB437000F1A36 /* Gyroscopic.m in Sources */ = {isa = PBXBuildFile; fileRef = 9598E3B2151BB437000F1A36 /* Gyroscopic.m */; }; @@ -36,8 +36,8 @@ 5878DA5C151B9A03003B758C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 5878DA5D151B9A03003B758C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 5878DA60151B9A03003B758C /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = ""; }; - 9598E396151B9C5E000F1A36 /* Triangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Triangle.h; sourceTree = ""; }; - 9598E397151B9C5E000F1A36 /* Triangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Triangle.m; sourceTree = ""; }; + 9598E396151B9C5E000F1A36 /* Shape.h */ = {isa = PBXFileReference; fileEncoding = 4; path = Shape.h; sourceTree = ""; }; + 9598E397151B9C5E000F1A36 /* Shape.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Shape.m; sourceTree = ""; }; 9598E39B151B9D35000F1A36 /* ShapeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShapeView.h; sourceTree = ""; }; 9598E39C151B9D35000F1A36 /* ShapeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShapeView.m; sourceTree = ""; }; 9598E39F151B9F77000F1A36 /* HKPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HKPoint.h; sourceTree = ""; }; @@ -123,8 +123,8 @@ 9598E3B2151BB437000F1A36 /* Gyroscopic.m */, 9598E39F151B9F77000F1A36 /* HKPoint.h */, 9598E3A0151B9F77000F1A36 /* HKPoint.m */, - 9598E396151B9C5E000F1A36 /* Triangle.h */, - 9598E397151B9C5E000F1A36 /* Triangle.m */, + 9598E396151B9C5E000F1A36 /* Shape.h */, + 9598E397151B9C5E000F1A36 /* Shape.m */, ); name = Model; sourceTree = ""; @@ -203,7 +203,7 @@ 5878DA57151B9A03003B758C /* main.m in Sources */, 5878DA5B151B9A03003B758C /* AppDelegate.m in Sources */, 5878DA5E151B9A03003B758C /* ViewController.m in Sources */, - 9598E398151B9C5E000F1A36 /* Triangle.m in Sources */, + 9598E398151B9C5E000F1A36 /* Shape.m in Sources */, 9598E39D151B9D35000F1A36 /* ShapeView.m in Sources */, 9598E3A1151B9F77000F1A36 /* HKPoint.m in Sources */, 9598E3B3151BB437000F1A36 /* Gyroscopic.m in Sources */, diff --git a/MovingShapes/Triangle.h b/MovingShapes/Shape.h similarity index 87% rename from MovingShapes/Triangle.h rename to MovingShapes/Shape.h index 4e3a838..542809b 100644 --- a/MovingShapes/Triangle.h +++ b/MovingShapes/Shape.h @@ -1,5 +1,5 @@ // -// Triangle.h +// Shape.h // MovingShapes // // Created by Karol Mazur on 3/22/12. @@ -9,7 +9,7 @@ #import #import "HKPoint.h" -@interface Triangle : NSObject +@interface Shape : NSObject - (id)initWithPoints:(NSArray *)points; - (void) updatePoints: (NSArray *) points; diff --git a/MovingShapes/Triangle.m b/MovingShapes/Shape.m similarity index 86% rename from MovingShapes/Triangle.m rename to MovingShapes/Shape.m index 1b98eb2..db0ece1 100644 --- a/MovingShapes/Triangle.m +++ b/MovingShapes/Shape.m @@ -1,15 +1,15 @@ // -// Triangle.m +// Shape.m // MovingShapes // // Created by Karol Mazur on 3/22/12. // Copyright (c) 2012 mazur.me. All rights reserved. // -#import "Triangle.h" +#import "Shape.h" #import "HKPoint.h" -@implementation Triangle +@implementation Shape @synthesize points = _points; diff --git a/MovingShapes/ShapeView.h b/MovingShapes/ShapeView.h index b043f66..ecf258c 100644 --- a/MovingShapes/ShapeView.h +++ b/MovingShapes/ShapeView.h @@ -8,7 +8,7 @@ #import #import "HKPoint.h" -#import "Triangle.h" +#import "Shape.h" @protocol ShapeViewDelegate @@ -26,6 +26,6 @@ } @property (assign, nonatomic) id delegate; -@property (assign, nonatomic) Triangle *triangle; +@property (assign, nonatomic) Shape *shape; @end diff --git a/MovingShapes/ShapeView.m b/MovingShapes/ShapeView.m index 785ba1e..505ba04 100644 --- a/MovingShapes/ShapeView.m +++ b/MovingShapes/ShapeView.m @@ -13,7 +13,7 @@ @implementation ShapeView -@synthesize delegate, triangle; +@synthesize delegate, shape; - (void) awakeFromNib { vertex = -1; @@ -36,9 +36,9 @@ - (BOOL) rayForPoint: (HKPoint *) point crossesLineSegmentFrom: (HKPoint *) poin (trailingPoint.y - pointOnPolygon.y) + pointOnPolygon.x); } -- (BOOL) isPointWithinTriangle: (HKPoint *) point { +- (BOOL) isPointWithinShape: (HKPoint *) point { // shamelessly stolen from http://jakescruggs.blogspot.com/2009/07/point-inside-polygon-in-ruby.html - NSArray *points = [triangle points]; + NSArray *points = [shape points]; BOOL contains = false; NSInteger i = -1; NSInteger j = points.count - 1; @@ -94,11 +94,11 @@ - (void) resetTouches: (UIEvent *) event { fingers = [touches count]; vertex = -1; - if (triangle) { + if (shape) { if (fingers == 1) { CGPoint touch = [[touches objectAtIndex: 0] locationInView: self]; - for (NSInteger i = 0; i < [[triangle points] count]; i++) { - HKPoint *point = [[triangle points] objectAtIndex: i]; + for (NSInteger i = 0; i < [[shape points] count]; i++) { + HKPoint *point = [[shape points] objectAtIndex: i]; if (pow(point.x - touch.x, 2) + pow(point.y - touch.y, 2) < pow(maxDistance, 2)) { vertex = i; break; @@ -107,7 +107,7 @@ - (void) resetTouches: (UIEvent *) event { } else if (fingers == 2) { HKPoint *point1 = [[HKPoint alloc] initWithCGPoint: [[touches objectAtIndex: 0] locationInView: self]]; HKPoint *point2 = [[HKPoint alloc] initWithCGPoint: [[touches objectAtIndex: 0] locationInView: self]]; - if ([self isPointWithinTriangle: point1] && [self isPointWithinTriangle: point2]) { + if ([self isPointWithinShape: point1] && [self isPointWithinShape: point2]) { startingPoint = [self middlePointForTwoTouches: touches]; } else { startingPoint = nil; @@ -138,14 +138,14 @@ -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { - if (self.triangle) { - HKPoint *aPoint = [self.triangle.points objectAtIndex:0]; + if (self.shape) { + HKPoint *aPoint = [self.shape.points objectAtIndex:0]; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextBeginPath(ctx); CGContextMoveToPoint (ctx, aPoint.x, aPoint.y); // top left - for (int i = 1; i < [self.triangle.points count]; i++) { - aPoint = [self.triangle.points objectAtIndex:i]; + for (int i = 1; i < [self.shape.points count]; i++) { + aPoint = [self.shape.points objectAtIndex:i]; CGContextAddLineToPoint(ctx, aPoint.x, aPoint.y); } CGContextClosePath(ctx); @@ -155,7 +155,7 @@ - (void)drawRect:(CGRect)rect { if (vertex > -1) { CGContextSetRGBFillColor(ctx, 0, 0, 1, 1); - HKPoint *point = [[triangle points] objectAtIndex: vertex]; + HKPoint *point = [[shape points] objectAtIndex: vertex]; CGRect rect = CGRectMake(point.x - indicatorRadius, point.y - indicatorRadius, 2 * indicatorRadius, 2 * indicatorRadius); CGContextFillEllipseInRect(ctx, rect); diff --git a/MovingShapes/ViewController.h b/MovingShapes/ViewController.h index b7a469c..aac8f4c 100644 --- a/MovingShapes/ViewController.h +++ b/MovingShapes/ViewController.h @@ -8,13 +8,13 @@ #import #import "ShapeView.h" -#import "Triangle.h" +#import "Shape.h" #import "Gyroscopic.h" @class Gyroscopic; @interface ViewController : UIViewController { - Triangle *triangle; + Shape *shape; } @property (strong, nonatomic) Gyroscopic *gyroscopic; diff --git a/MovingShapes/ViewController.m b/MovingShapes/ViewController.m index cd8f31f..fd3ac32 100644 --- a/MovingShapes/ViewController.m +++ b/MovingShapes/ViewController.m @@ -7,7 +7,7 @@ // #import "ViewController.h" -#import "Triangle.h" +#import "Shape.h" #import "ShapeView.h" #import "Gyroscopic.h" @@ -23,9 +23,9 @@ - (void)didReceiveMemoryWarning - (void)shapeViewDidMoveVertex: (NSInteger) vertex toPoint: (HKPoint *) point { NSLog(@"moved point %d: %@", vertex, point); - NSMutableArray *points = [NSMutableArray arrayWithArray: [triangle points]]; + NSMutableArray *points = [NSMutableArray arrayWithArray: [shape points]]; [points replaceObjectAtIndex: vertex withObject: point]; - [triangle updatePoints: points]; + [shape updatePoints: points]; [self.view setNeedsDisplay]; } @@ -35,23 +35,23 @@ - (void)shapeViewDidTouchWithOnePoint:(HKPoint *)point { - (void)shapeViewDidMoveByX: (CGFloat) x y: (CGFloat) y { NSLog(@"moved by: %f %f", x, y); - NSMutableArray *points = [NSMutableArray arrayWithCapacity: [[triangle points] count]]; - for (HKPoint *point in [triangle points]) { + NSMutableArray *points = [NSMutableArray arrayWithCapacity: [[shape points] count]]; + for (HKPoint *point in [shape points]) { HKPoint *modified = [[HKPoint alloc] initWithCGPoint: CGPointMake(point.x + x, point.y + y)]; [points addObject: modified]; } - [triangle updatePoints: points]; + [shape updatePoints: points]; [self.view setNeedsDisplay]; } - (void)shapeViewDidTouchWithThreePoints:(NSArray *)points { NSLog(@"3 points: %@", points); - if (triangle) { - [triangle updatePoints: points]; + if (shape) { + [shape updatePoints: points]; } else { - triangle = [[Triangle alloc] initWithPoints: points]; - [(ShapeView *) self.view setTriangle: triangle]; + shape = [[Shape alloc] initWithPoints: points]; + [(ShapeView *) self.view setShape: shape]; } [self.view setNeedsDisplay];