This is point.c in view mode; [Download] [Up]
/* RoachesView is Copyright 1994 by Brian Hill <bhill@physics.ucla.edu>. */
#import "point.h"
BOOL insideBounds(const NXPoint *point, const NXRect *bounds, NXCoord buffer)
{
if (point->x - bounds->origin.x <= buffer ||
point->y - bounds->origin.y <= buffer ||
point->x - bounds->origin.x >= bounds->size.width - buffer ||
point->y - bounds->origin.y >= bounds->size.height - buffer) return NO;
return YES;
}
float length(const NXPoint *point)
{
return (float)sqrt((double)(point->x * point->x + point->y * point->y));
}
BOOL normalizeTo(NXPoint *point, NXCoord newLength)
{
NXCoord oldLength;
if (!(oldLength = length(point))) return NO;
newLength /= oldLength;
point->x *= newLength;
point->y *= newLength;
return YES;
}
void zero(NXPoint *point)
{
point->x = point->y = (NXCoord)0.0f;
return;
}
void set(NXPoint *point, const NXPoint *anotherPoint)
{
point->x = anotherPoint->x;
point->y = anotherPoint->y;
return;
}
void translate(NXPoint *point, const NXPoint *anotherPoint)
{
point->x += anotherPoint->x;
point->y += anotherPoint->y;
return;
}
float squareDistance(const NXPoint *point, const NXPoint *anotherPoint)
{
NXPoint difference;
difference.x = (float)fabs((double)(point->x - anotherPoint->x));
difference.y = (float)fabs((double)(point->y - anotherPoint->y));
return difference.x >= difference.y ? (float)difference.x : (float)difference.y;
}
void scale(NXPoint *point, NXCoord scalar)
{
point->x *= scalar;
point->y *= scalar;
return;
}
void rotate(NXPoint *point, float angle) /* Counterclockwise, in radians. */
{
NXCoord sine, cosine, temp;
sine = (NXCoord)sin((double)angle);
cosine = (NXCoord)cos((double)angle);
temp = point->x;
point->x = point->x * cosine - point->y * sine;
point->y = point->y * cosine + temp * sine;
return;
}
void unitVector(NXPoint *point, float angle)
{
point->x = (NXCoord)cos((double)angle);
point->y = (NXCoord)sin((double)angle);
return;
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.