This is MiscParallelLinesShape.m in view mode; [Download] [Up]
/* MiscParallelLinesShape.m Copyright 1996 Uwe Hoffmann. This notice may not be removed from this source code. The use and distribution of this software is governed by the terms of the MiscKit license agreement. Refer to the license document included with the MiscKit distribution for the terms. Version 2 (August 1996) */ #import <Foundation/Foundation.h> #import "MiscParallelLinesShape.h" #import "MiscUserPath.h" #import "MiscHitPath.h" #import "MiscTDUtils.h" @implementation MiscParallelLinesShape - (NSRect)innerBounds { return [path1 bounds]; } - (MiscShapeType)shapeType { return MiscParallelLinesShapeType; } - (void)calcIntersection:(NSPoint *)ip angle:(float *)alpha toPoint:(NSPoint)aPoint { NSPoint middle,l1,l2,pos; float s,width,height,*bbox; bbox = [path1 bbox]; pos.x = bbox[0]; pos.y = bbox[1]; width = bbox[2] - bbox[0]; height = bbox[3] - bbox[1]; middle.x = pos.x + width / 2; middle.y = pos.y + height / 2; if(aPoint.y == middle.y){ ip->y = middle.y; if(aPoint.x > middle.x){ *alpha = 0; ip->x = pos.x + width; } else { *alpha = 180; ip->x = pos.x; } return; } if(aPoint.x == middle.x){ ip->x = middle.x; if(aPoint.y > middle.y){ ip->y = pos.y + height; *alpha = 90; } else { ip->y = pos.y; *alpha = -90; } return; } s = (aPoint.y - middle.y) / (aPoint.x - middle.x); *alpha = 57.29577951 * atan(s); if(aPoint.y > middle.y){ if(aPoint.x > middle.x){ // I. quadrant l1.x = middle.x; l1.y = l2.y = pos.y + height; l2.x = pos.x + width; if(miscTD_straddles(l1, l2, middle, aPoint)){ ip->y = l1.y; ip->x = middle.x + (ip->y - middle.y) / s; } else { ip->x = l2.x; ip->y = middle.y + s * (ip->x - middle.x); } } else { // II. quadrant l1.x = middle.x; l1.y = l2.y = pos.y + height; l2.x = pos.x; if(miscTD_straddles(l1, l2, middle, aPoint)){ ip->y = l1.y; ip->x = middle.x + (ip->y - middle.y) / s; } else { ip->x = l2.x; ip->y = middle.y + s * (ip->x - middle.x); } *alpha += 180; } } else { if(aPoint.x > middle.x){ // IV. quadrant l1.x = middle.x; l1.y = l2.y = pos.y; l2.x = pos.x + width; if(miscTD_straddles(l1, l2, middle, aPoint)){ ip->y = l1.y; ip->x = middle.x + (ip->y - middle.y) / s; } else { ip->x = l2.x; ip->y = middle.y + s * (ip->x - middle.x); } } else { // III. quadrant l1.x = middle.x; l1.y = l2.y = pos.y; l2.x = pos.x; if(miscTD_straddles(l1, l2, middle, aPoint)){ ip->y = l1.y; ip->x = middle.x + (ip->y - middle.y) / s; } else { ip->x = l2.x; ip->y = middle.y + s * (ip->x - middle.x); } *alpha += 180; } } } - (void)makePathWithBounds:(NSRect)aRect { [path1 moveto:aRect.origin.x :aRect.origin.y]; [path1 rlineto:aRect.size.width :0.0]; [path1 rlineto:0.0 :aRect.size.height]; [path1 rlineto:-aRect.size.width :0.0]; [path1 closepath]; [path2 moveto:aRect.origin.x :aRect.origin.y]; [path2 rlineto:aRect.size.width :0.0]; [path2 moveto:aRect.origin.x :aRect.origin.y + aRect.size.height]; [path2 rlineto:aRect.size.width :0.0]; } - (void)fillParamsWithBounds:(NSRect)aRect { float *params, *bbox; params = [path1 params]; bbox = [path1 bbox]; bbox[0] = aRect.origin.x; bbox[1] = aRect.origin.y; bbox[2] = aRect.origin.x + aRect.size.width; bbox[3] = aRect.origin.y + aRect.size.height; params[0] = aRect.origin.x; params[1] = aRect.origin.y; params[2] = aRect.size.width; params[3] = 0.0; params[4] = 0.0; params[5] = aRect.size.height; params[6] = -aRect.size.width; params[7] = 0.0; params = [path2 params]; bbox = [path2 bbox]; bbox[0] = aRect.origin.x; bbox[1] = aRect.origin.y; bbox[2] = aRect.origin.x + aRect.size.width; bbox[3] = aRect.origin.y + aRect.size.height; params[0] = aRect.origin.x; params[1] = aRect.origin.y; params[2] = aRect.size.width; params[3] = 0.0; params[4] = aRect.origin.x; params[5] = aRect.origin.y + aRect.size.height; params[6] = aRect.size.width; params[7] = 0.0; } + (NSSize)calcSizeForInnerSize:(NSSize)aSize { return aSize; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.