Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged all forks, works well #5

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,485 changes: 605 additions & 880 deletions English.lproj/VertexDocument.xib
100644 → 100755

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion ImageViewGridLayer.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Johannes Fahrenkrug on 20.02.10.
// Copyright 2010 Springenwerk. All rights reserved.
//
// Concave Polygons Bug Fixed by Ivan Bastidas on 09/05/2010.

#import <Quartz/Quartz.h>
#import <Cocoa/Cocoa.h>
Expand All @@ -23,5 +24,5 @@
@property (assign) VertexDocument *document;
@property (assign) int rows;
@property (assign) int cols;

-(BOOL) calcWithPoint:(CGPoint)point1 secondPoint: (CGPoint)point2 thirdPoint:(CGPoint)point3 fourthPoint: (CGPoint)point4;
@end
66 changes: 64 additions & 2 deletions ImageViewGridLayer.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
// Created by Johannes Fahrenkrug on 20.02.10.
// Copyright 2010 Springenwerk. All rights reserved.
//
// Concave Polygons Bug Fixed by Ivan Bastidas on 09/05/2010.

#import "ImageViewGridLayer.h"
#import "VertexDocument.h"

#define RAD_TO_DEG(rad) ( (180.0 * (rad)) / M_PI )
// Thanks to Bill Dudney (http://bill.dudney.net/roller/objc/entry/nscolor_cgcolorref)
@interface NSColor(CGColor)
- (CGColorRef)CGColor;
Expand All @@ -31,6 +32,7 @@ @implementation ImageViewGridLayer

@synthesize owner, document, rows, cols;


// -------------------------------------------------------------------------
// init
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -152,7 +154,25 @@ -(CALayer *)hitTest:(CGPoint)aPoint {
relativePoint.x = (p.x - ((currentCol - 1) * colWidth)) - (colWidth / 2);
relativePoint.y = (p.y - ((currentRow - 1) * rowHeight)) - (rowHeight / 2);

[document addPoint:relativePoint forRow:currentRow col:currentCol];
NSMutableArray *points = [[document.pointMatrix objectAtIndex:(currentRow - 1)] objectAtIndex:(currentCol - 1)];
if ([points count]>1 ) {

NSPoint point3 = [[points objectAtIndex:[points count]-2] pointValue];
NSPoint point2 = [[points objectAtIndex:[points count]-1] pointValue];
NSPoint point1 = [[points objectAtIndex:0] pointValue];

if ([self calcWithPoint:point1 secondPoint:point2 thirdPoint:relativePoint fourthPoint:point3]) {
[document addPoint:relativePoint forRow:currentRow col:currentCol];
}else {
return nil;
}


}else {
[document addPoint:relativePoint forRow:currentRow col:currentCol];
}


}

}
Expand All @@ -163,6 +183,48 @@ -(CALayer *)hitTest:(CGPoint)aPoint {
return nil;
}
}
-(BOOL) calcWithPoint:(CGPoint)point1 secondPoint: (CGPoint)point2 thirdPoint:(CGPoint)point3 fourthPoint: (CGPoint)point4{
double ang1 = RAD_TO_DEG(atan2(point2.y-point1.y,point2.x - point1.x));
//NSLog(@"Angulo 1 = %1.2f",ang1);
if (ang1<0) {
ang1 = 180+ang1;
}
//NSLog(@"Transformado = %1.2f",ang1);
double ang2 = RAD_TO_DEG(atan2(point3.y-point2.y,point3.x - point2.x));

//NSLog(@"Angulo 2 = %1.2f",ang2);
if (ang2>=0) {
ang2 = 180-ang2;
}else {
ang2 = (ang2+180) * -1;
}
//NSLog(@"Transformado = %1.2f",ang2);

double total = ang1+ang2;


double ang3 = RAD_TO_DEG(atan2(point2.y-point4.y,point2.x - point4.x));
//NSLog(@"Angulo 3 = %1.2f",ang3);
if (ang3<0) {
ang3 = 180+ang3;
ang2 = RAD_TO_DEG(atan2(point3.y-point2.y,point3.x - point2.x))*-1;
}

//NSLog(@"Transformado = %1.2f",ang3);

double total2 = ang2+ang3;
//NSLog(@"Angulo Interno Suma = %1.2f",total);
//NSLog(@"Angulo Interno = %1.2f",total2);
if ((total <= 180 && total>=0) && (total2 <= 180 && total2>=0)) {

return YES;

}else {
return NO;
}


}

- (void)dealloc
{
Expand Down
2 changes: 1 addition & 1 deletion PrioritySplitViewDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Cocoa/Cocoa.h>

@interface PrioritySplitViewDelegate : NSObject
@interface PrioritySplitViewDelegate : NSObject<NSSplitViewDelegate>
{
NSMutableDictionary *lengthsByViewIndex;
NSMutableDictionary *viewIndicesByPriority;
Expand Down
17 changes: 17 additions & 0 deletions SWScrollView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// SWScrollView.h
// VertexHelper
//
// Created by Jon Gilkison on 9/15/11.
// Copyright 2011 Interfacelab LLC. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface SWScrollView : NSScrollView {
@private

}

@end
37 changes: 37 additions & 0 deletions SWScrollView.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// SWScrollView.m
// VertexHelper
//
// Code from Nicholas Riley
//
// Created by Nicholas Riley on 1/25/10.
// Copyright 2010 Nicholas Riley. All rights reserved.
//

#import "SWScrollView.h"
#import <Quartz/Quartz.h>

@interface IKImageClipView : NSClipView
- (NSRect)docRect;
@end

@implementation SWScrollView

- (void)reflectScrolledClipView:(NSClipView *)cView;
{
NSView *_imageView = [self documentView];
[super reflectScrolledClipView:cView];
if ([_imageView isKindOfClass:[IKImageView class]] &&
[[self contentView] isKindOfClass:[IKImageClipView class]] &&
[[self contentView] respondsToSelector:@selector(docRect)]) {
NSSize docSize = [(IKImageClipView *)[self contentView] docRect].size;
NSSize scrollViewSize = [self contentSize];

if (docSize.height > scrollViewSize.height || docSize.width > scrollViewSize.width)
((IKImageView *)_imageView).autohidesScrollers = NO;
else
((IKImageView *)_imageView).autohidesScrollers = YES;
}
}

@end
23 changes: 23 additions & 0 deletions SWUndo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// SWUndo.h
// VertexHelper
//
// Created by Jon Gilkison on 9/16/11.
// Copyright 2011 Interfacelab LLC. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface SWUndo : NSObject {
NSInteger col,row;
NSMutableArray *points;
}

@property (readonly) NSInteger col;
@property (readonly) NSInteger row;
@property (readonly) NSMutableArray *points;

+(SWUndo *)undoForMatrix:(NSMutableArray *)pointMatrix col:(NSInteger)c row:(NSInteger)r;

@end
41 changes: 41 additions & 0 deletions SWUndo.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// SWUndo.m
// VertexHelper
//
// Created by Jon Gilkison on 9/16/11.
// Copyright 2011 Interfacelab LLC. All rights reserved.
//

#import "SWUndo.h"


@implementation SWUndo

@synthesize points, col, row;

- (id)initWithPointMatrix:(NSMutableArray *)pointMatrix col:(NSInteger)c row:(NSInteger)r
{
self = [super init];
if (self) {
col=c;
row=r;
points=[[NSMutableArray alloc] initWithArray:[[pointMatrix objectAtIndex:r] objectAtIndex:c] copyItems:YES];
}

return self;
}

- (void)dealloc
{
[points release];
[super dealloc];
}


+(SWUndo *)undoForMatrix:(NSMutableArray *)pointMatrix col:(NSInteger)c row:(NSInteger)r
{
return [[[SWUndo alloc] initWithPointMatrix:pointMatrix col:c row:r] autorelease];
}


@end
10 changes: 9 additions & 1 deletion VertexDocument.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@class PrioritySplitViewDelegate;

@interface VertexDocument : NSDocument
@interface VertexDocument : NSDocument<NSWindowDelegate>
{
IBOutlet NSTextField *rowsTextField;
IBOutlet NSTextField *colsTextField;
Expand All @@ -32,12 +32,17 @@
IBOutlet NSSplitView *splitView;
PrioritySplitViewDelegate *splitViewDelegate;

IBOutlet NSSlider *angleSlider;
IBOutlet NSTextField *angleField;

ImageViewGridLayer *gridLayer;
// each row has columns, each column has points
NSMutableArray *pointMatrix;
NSString *filePath;
BOOL gridOK;
BOOL imageLoaded;

IBOutlet NSTextField *box2DRatioField;
}

- (IBAction)updateGrid:(id)sender;
Expand All @@ -47,6 +52,9 @@
- (IBAction)scanImage:(id)sender;
- (IBAction)resetVertices:(id)sender;

- (IBAction)angleSliderChanged:(NSSlider*)sender;
- (IBAction)angleFieldChanged:(NSTextField*)sender;

- (void)addPoint:(NSPoint)aPoint forRow:(int)aRow col:(int)aCol;
- (void)updateResultTextField;

Expand Down
Loading