ftp.nice.ch/Attic/openStep/developer/resources/MiscKit.2.0.5.s.gnutar.gz#/MiscKit2/Frameworks/MiscAppKit/MiscTreeDiagram.subproj/MiscCircleShape.m

This is MiscCircleShape.m in view mode; [Download] [Up]

/*	MiscCircleShape.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 "MiscCircleShape.h"
#import "MiscUserPath.h"
#import "MiscHitPath.h"

@implementation MiscCircleShape 

- (NSRect)innerBounds
{
	NSRect br,ir;
	NSPoint m;
	float a,b,cx,cy;
	
	br = [path bounds];
	m.x = br.origin.x + br.size.width / 2;
	m.y = br.origin.y + br.size.height / 2;
	a = br.size.width / 2;
	b = br.size.height / 2;
	cx = a * 0.57735;
	cy = b * 0.81649;
	ir.origin.x = m.x - cx;
	ir.origin.y = m.y - cy;
	ir.size.width = 2 * cx;
	ir.size.height = 2 * cy;
	return ir;
}

- (MiscShapeType)shapeType
{
	return MiscCircleShapeType;
}

- (void)calcIntersection:(NSPoint *)ip angle:(float *)alpha toPoint:(NSPoint)aPoint
{
	NSPoint middle,pos;
	float s,x0,y0,a,b,width,height,*bbox;
	
	bbox = [path 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
			x0 = middle.x;
			y0 = middle.y;
			a = width / 2;
			b = height / 2;
			ip->x = a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + x0;
			ip->y = (2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			if(ip->y < y0){
				ip->x = -(a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2))) + x0;
				ip->y = (-2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			}
		} else { 										// II. quadrant
			x0 = middle.x;
			y0 = middle.y;
			a = width / 2;
			b = height / 2;
			ip->x = a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + x0;
			ip->y = (2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			if(ip->y < y0){
				ip->x = -(a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2))) + x0;
				ip->y = (-2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			}
                        *alpha += 180;
		}
	} else {
		if(aPoint.x > middle.x){ 						// IV. quadrant
			x0 = middle.x;
			y0 = middle.y;
			a = width / 2;
			b = height / 2;
			ip->x = a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + x0;
			ip->y = (2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			if(ip->y > y0){
				ip->x = -(a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2))) + x0;
				ip->y = (-2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			}
		} else { 										// III. quadrant
			x0 = middle.x;
			y0 = middle.y;
			a = width / 2;
			b = height / 2;
			ip->x = a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + x0;
			ip->y = (2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			if(ip->y > y0){
				ip->x = -(a*b/sqrt(pow(b,2) + pow(a,2)*pow(s,2))) + x0;
				ip->y = (-2*a*b*s/sqrt(pow(b,2) + pow(a,2)*pow(s,2)) + 2*y0)/2;
			}
                        *alpha += 180;
		}
	}
}


- (void)makePathWithBounds:(NSRect)aRect
{
	[path moveto:(aRect.origin.x + aRect.size.width) :(aRect.origin.y + aRect.size.height / 2)];
	[path curveto:(aRect.origin.x + aRect.size.width) :(aRect.origin.y + aRect.size.height / 2 * 0.445)
						:(aRect.origin.x + aRect.size.width / 2 * 1.555)  :aRect.origin.y
						:(aRect.origin.x + aRect.size.width / 2) :aRect.origin.y];
	[path curveto:(aRect.origin.x + aRect.size.width / 2 * 0.445) :aRect.origin.y
						:aRect.origin.x :(aRect.origin.y + aRect.size.height / 2 * 0.445)
						:aRect.origin.x :(aRect.origin.y + aRect.size.height / 2)];
	[path curveto:aRect.origin.x :(aRect.origin.y + aRect.size.height /2 * 1.555)
						:(aRect.origin.x + aRect.size.width / 2 * 0.445) :(aRect.origin.y + aRect.size.height)
						:(aRect.origin.x + aRect.size.width / 2) :(aRect.origin.y + aRect.size.height)];
	[path curveto:(aRect.origin.x + aRect.size.width / 2 * 1.555) :(aRect.origin.y + aRect.size.height)
						:(aRect.origin.x + aRect.size.width) :(aRect.origin.y + aRect.size.height / 2 * 1.555)
						:(aRect.origin.x + aRect.size.width) :(aRect.origin.y + aRect.size.height / 2)];
	[path closepath];
}
			
- (void)fillParamsWithBounds:(NSRect)aRect
{
	float *params, *bbox;
	
	params = [path params];
	bbox = [path 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 + aRect.size.width;
	params[1] = aRect.origin.y + aRect.size.height / 2;
	params[2] = aRect.origin.x + aRect.size.width;
	params[3] = aRect.origin.y + aRect.size.height / 2 * 0.445;
	params[4] = aRect.origin.x + aRect.size.width / 2 * 1.555;
	params[5] = aRect.origin.y;
	params[6] = aRect.origin.x + aRect.size.width / 2; 
	params[7] = aRect.origin.y;
	params[8] = aRect.origin.x + aRect.size.width / 2 * 0.445;
	params[9] = aRect.origin.y;
	params[10] = aRect.origin.x;
	params[11] = aRect.origin.y + aRect.size.height / 2 * 0.445;
	params[12] = aRect.origin.x;
	params[13] = aRect.origin.y + aRect.size.height / 2;
	params[14] = aRect.origin.x;
	params[15] = aRect.origin.y + aRect.size.height /2 * 1.555;
	params[16] = aRect.origin.x + aRect.size.width / 2 * 0.445;
	params[17] = aRect.origin.y + aRect.size.height;
	params[18] = aRect.origin.x + aRect.size.width / 2;
	params[19] = aRect.origin.y + aRect.size.height;
	params[20] = aRect.origin.x + aRect.size.width / 2 * 1.555;
	params[21] = aRect.origin.y + aRect.size.height;
	params[22] = aRect.origin.x + aRect.size.width;
	params[23] = aRect.origin.y + aRect.size.height / 2 * 1.555;
	params[24] = aRect.origin.x + aRect.size.width;
	params[25] = aRect.origin.y + aRect.size.height / 2;
}

+ (NSSize)calcSizeForInnerSize:(NSSize)aSize
{
	NSSize os;
	float a,b,cx,cy;
	
	cx = aSize.width / 2;
	cy = aSize.height / 2;
	a = cx / 0.57735;
	b = cy / 0.81649;
	os.width = 2 * a;
	os.height = 2 * b;
	return os;
}
		              
@end


	

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.