ftp.nice.ch/pub/next/graphics/vector/Wood.0.72.s.tar.gz#/Wood/WoodFuture/TreeDiagram/MiscDiamondShape.m

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

/*
		Copyright (c) Uwe Hoffmann, 1995.
                  All Rights Reserved.

Filename: MiscDiamondShape.m
Author:   Uwe Hoffmann
Date:	  Sep 07, 1995

$Id: MiscDiamondShape.m,v 1.0 1995/09/07 11:22:00 Uwe Hoffmann Exp $
 $Log: MiscDiamondShape.m,v $
*/

#import <appkit/appkit.h>
#import "MiscDiamondShape.h"
#import "MiscUserPath.h"
#import "MiscHitPath.h"


@implementation MiscDiamondShape 

- (NSRect)innerBounds
{
	return [path bounds];
}

- (MiscShapeType)shapeType
{
	return MiscDiamondShapeType;
}

- (void)calcIntersection:(NSPoint *)ip angle:(float *)alpha toPoint:(NSPoint)aPoint
{
	NSPoint middle,l1,l2,pos;
	float s,ausdruck,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){
		*alpha = 0;
		ip->y = middle.y;
		if(aPoint.x > middle.x)
			ip->x = pos.x + width;
		else
			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){ 						// 4. quadrant
			l1.x = middle.x;
			l1.y = pos.y + height;
			l2.x = pos.x + width;
			l2.y = middle.y;
			ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
			ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
			ip->y = middle.y + s * (ip->x - middle.x);
		} else { 										// 3. quadrant
			l1.x = middle.x;
			l1.y = pos.y + height;
			l2.x = pos.x;
			l2.y = middle.y;
			ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
			ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
			ip->y = middle.y + s * (ip->x - middle.x);
		}
	} else {
		if(aPoint.x > middle.x){ 						// 1. quadrant
			l1.x = middle.x;
			l1.y = pos.y;
			l2.x = pos.x + width;
			l2.y = middle.y;
			ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
			ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
			ip->y = middle.y + s * (ip->x - middle.x);
		} else { 										// 2. quadrant
			l1.x = middle.x;
			l1.y = pos.y;
			l2.x = pos.x;
			l2.y = middle.y;
			ausdruck = (l2.y - l1.y) / (l2.x - l1.x);
			ip->x = (middle.y + ausdruck * l1.x - s * middle.x - l1.y) / (ausdruck - s);
			ip->y = middle.y + s * (ip->x - middle.x);
		}
	}
}


- (void)makePathWithBounds:(NSRect)aRect
{
	[path moveto:aRect.origin.x + aRect.size.width / 2 :aRect.origin.y];
	[path rlineto:aRect.size.width / 2 :aRect.size.height / 2];
	[path rlineto:-aRect.size.width / 2 :aRect.size.height / 2];
	[path rlineto:-aRect.size.width / 2 :-aRect.size.height / 2];
	[path rlineto:aRect.size.width / 2 :-aRect.size.height / 2];
}
			
- (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 / 2;
	params[1] = aRect.origin.y;
	params[2] = aRect.size.width / 2;
	params[3] = aRect.size.height / 2;
	params[4] = -aRect.size.width / 2;
	params[5] = aRect.size.height / 2;
	params[6] = -aRect.size.width / 2;
	params[7] = -aRect.size.height / 2;
	params[8] =aRect.size.width / 2;
	params[9] = -aRect.size.height / 2;
}

+ (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.