From bdb1de96e6578b7f1b25b068bd4d7f64f89bc3b0 Mon Sep 17 00:00:00 2001 From: Stephan Michels Date: Mon, 2 Jan 2012 17:56:57 +0100 Subject: [PATCH] Improved drawing code. --- BlobularView.m | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/BlobularView.m b/BlobularView.m index 64b1702..99d9889 100755 --- a/BlobularView.m +++ b/BlobularView.m @@ -105,35 +105,25 @@ - (void)drawRect:(NSRect)rect { NSColor* fillColor = [NSColor colorWithDeviceRed:152.0/255.0 green:180.0/255.0 blue:227.0/255.0 alpha:1.0]; NSColor* strokeColor = [[NSColor whiteColor] colorWithAlphaComponent:0.6]; - /*for(int i=0; i abs(blob1.radius - blob2.radius)) { + distanceOf(blob1.center, blob2.center) > fabs(blob1.radius - blob2.radius)) { connected = YES; } } - for(NSUInteger j = i+1; j < [self.blobs count]; j++) { - /*[[NSColor blackColor] set]; - [NSBezierPath strokeLineFromPoint:circles[i] toPoint:circles[j]];*/ - Blob *blob2 = [self.blobs objectAtIndex:j]; + for(NSUInteger blobIndex2 = blobIndex1 + 1; blobIndex2 < [self.blobs count]; blobIndex2++) { + Blob *blob2 = [self.blobs objectAtIndex:blobIndex2]; NSPoint c1, c2; - if (distanceOf(blob1.center, blob2.center) > abs(blob1.radius - blob2.radius) && + if (distanceOf(blob1.center, blob2.center) > fabs(blob1.radius - blob2.radius) && circle_circle_intersection(blob1.center, blob1.radius + self.probeRadius, blob2.center, blob2.radius + self.probeRadius, &c1, &c2) /* && projection_on_segment(circles[i], circles[j], c1)*/) { @@ -144,6 +134,7 @@ - (void)drawRect:(NSRect)rect { [NSBezierPath strokeLineFromPoint:blob1.center toPoint:blob2.center]; [NSGraphicsContext restoreGraphicsState]; + // show probe circles for debugging purposes if (self.showProbes) { NSBezierPath* probePath = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(c1.x - self.probeRadius, c1.y - self.probeRadius, @@ -158,13 +149,15 @@ - (void)drawRect:(NSRect)rect { 2.0f * self.probeRadius)]; [[NSColor redColor] set]; [probePath stroke]; + + [NSBezierPath strokeLineFromPoint:blob1.center toPoint:c1]; + [NSBezierPath strokeLineFromPoint:blob2.center toPoint:c1]; + [NSBezierPath strokeLineFromPoint:blob1.center toPoint:c2]; + [NSBezierPath strokeLineFromPoint:blob2.center toPoint:c2]; } - /*[NSBezierPath strokeLineFromPoint:circles[0] toPoint:c1]; - [NSBezierPath strokeLineFromPoint:circles[1] toPoint:c1]; - [NSBezierPath strokeLineFromPoint:circles[0] toPoint:c2]; - [NSBezierPath strokeLineFromPoint:circles[1] toPoint:c2];*/ + // determine various angles for the calculate the arc segments float angle1 = angle(c1, blob1.center); float angle2 = angle(c1, blob2.center); float angle3 = angle(c2, blob1.center); @@ -218,8 +211,8 @@ - (void)drawRect:(NSRect)rect { clockwise:YES]; [path closePath]; } else { - //NSLog(@"angle1=%f angle2=%f angle3=%f angle4=%f", angle1, angle2, angle3, angle4); + // draw one single shape by connecting the various arc segments [path appendBezierPathWithArcWithCenter:blob1.center radius:blob1.radius startAngle:rotate_angle(angle1) @@ -259,7 +252,10 @@ - (void)drawRect:(NSRect)rect { // if the circle is not connected draw a single circle if (!connected) { - NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(blob1.center.x-blob1.radius, blob1.center.y-blob1.radius, 2*blob1.radius, 2*blob1.radius)]; + NSBezierPath *path = [NSBezierPath bezierPathWithOvalInRect:NSMakeRect(blob1.center.x - blob1.radius, + blob1.center.y - blob1.radius, + 2.0f * blob1.radius, + 2.0f * blob1.radius)]; [fillColor set]; [path fill];