Skip to content

Commit

Permalink
renamed triangle to shape
Browse files Browse the repository at this point in the history
  • Loading branch information
mackuba committed Mar 22, 2012
1 parent 65a4ada commit 2d3de20
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 37 deletions.
12 changes: 6 additions & 6 deletions MovingShapes.xcodeproj/project.pbxproj
Expand Up @@ -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 */; };
Expand All @@ -36,8 +36,8 @@
5878DA5C151B9A03003B758C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = "<group>"; };
5878DA5D151B9A03003B758C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = "<group>"; };
5878DA60151B9A03003B758C /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = "<group>"; };
9598E396151B9C5E000F1A36 /* Triangle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Triangle.h; sourceTree = "<group>"; };
9598E397151B9C5E000F1A36 /* Triangle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Triangle.m; sourceTree = "<group>"; };
9598E396151B9C5E000F1A36 /* Shape.h */ = {isa = PBXFileReference; fileEncoding = 4; path = Shape.h; sourceTree = "<group>"; };
9598E397151B9C5E000F1A36 /* Shape.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Shape.m; sourceTree = "<group>"; };
9598E39B151B9D35000F1A36 /* ShapeView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShapeView.h; sourceTree = "<group>"; };
9598E39C151B9D35000F1A36 /* ShapeView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShapeView.m; sourceTree = "<group>"; };
9598E39F151B9F77000F1A36 /* HKPoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HKPoint.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -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 = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 2 additions & 2 deletions MovingShapes/Triangle.h → MovingShapes/Shape.h
@@ -1,5 +1,5 @@
//
// Triangle.h
// Shape.h
// MovingShapes
//
// Created by Karol Mazur on 3/22/12.
Expand All @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>
#import "HKPoint.h"

@interface Triangle : NSObject
@interface Shape : NSObject

- (id)initWithPoints:(NSArray *)points;
- (void) updatePoints: (NSArray *) points;
Expand Down
6 changes: 3 additions & 3 deletions MovingShapes/Triangle.m → 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;

Expand Down
4 changes: 2 additions & 2 deletions MovingShapes/ShapeView.h
Expand Up @@ -8,7 +8,7 @@

#import <UIKit/UIKit.h>
#import "HKPoint.h"
#import "Triangle.h"
#import "Shape.h"

@protocol ShapeViewDelegate <NSObject>

Expand All @@ -26,6 +26,6 @@
}

@property (assign, nonatomic) id <ShapeViewDelegate> delegate;
@property (assign, nonatomic) Triangle *triangle;
@property (assign, nonatomic) Shape *shape;

@end
24 changes: 12 additions & 12 deletions MovingShapes/ShapeView.m
Expand Up @@ -13,7 +13,7 @@

@implementation ShapeView

@synthesize delegate, triangle;
@synthesize delegate, shape;

- (void) awakeFromNib {
vertex = -1;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions MovingShapes/ViewController.h
Expand Up @@ -8,13 +8,13 @@

#import <UIKit/UIKit.h>
#import "ShapeView.h"
#import "Triangle.h"
#import "Shape.h"
#import "Gyroscopic.h"

@class Gyroscopic;

@interface ViewController : UIViewController <ShapeViewDelegate, GyroscopicDelegate> {
Triangle *triangle;
Shape *shape;
}

@property (strong, nonatomic) Gyroscopic *gyroscopic;
Expand Down
20 changes: 10 additions & 10 deletions MovingShapes/ViewController.m
Expand Up @@ -7,7 +7,7 @@
//

#import "ViewController.h"
#import "Triangle.h"
#import "Shape.h"
#import "ShapeView.h"
#import "Gyroscopic.h"

Expand All @@ -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];
}

Expand All @@ -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];
Expand Down

0 comments on commit 2d3de20

Please sign in to comment.