Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOPointMaths.h
Go to the documentation of this file.
2#include <tgmath.h>
3
4
5// Utilities for working with NSPoints as 2D vectors.
6OOINLINE NSPoint PtAdd(NSPoint a, NSPoint b)
7{
8 return NSMakePoint(a.x + b.x, a.y + b.y);
9}
10
11OOINLINE NSPoint PtSub(NSPoint a, NSPoint b)
12{
13 return NSMakePoint(a.x - b.x, a.y - b.y);
14}
15
16OOINLINE NSPoint PtScale(NSPoint p, CGFloat scale)
17{
18 return NSMakePoint(p.x * scale, p.y * scale);
19}
20
21OOINLINE CGFloat PtDot(NSPoint a, NSPoint b)
22{
23 return a.x * b.x + a.y * b.y;
24}
25
26OOINLINE CGFloat PtCross(NSPoint a, NSPoint b)
27{
28 return a.x * b.y - b.x * a.y;
29}
30
31OOINLINE NSPoint PtRotCW(NSPoint p)
32{
33 // Rotate 90 degrees clockwise.
34 return NSMakePoint(p.y, -p.x);
35}
36
37OOINLINE NSPoint PtRotACW(NSPoint p)
38{
39 // Rotate 90 degrees anticlockwise.
40 return NSMakePoint(-p.y, p.x);
41}
42
43OOINLINE NSPoint PtNormal(NSPoint p)
44{
45 return PtScale(p, 1.0 / sqrt(PtDot(p, p)));
46}
#define OOINLINE
OOINLINE CGFloat PtDot(NSPoint a, NSPoint b)
OOINLINE NSPoint PtScale(NSPoint p, CGFloat scale)
OOINLINE NSPoint PtSub(NSPoint a, NSPoint b)
OOINLINE NSPoint PtRotACW(NSPoint p)
OOINLINE NSPoint PtNormal(NSPoint p)
OOINLINE CGFloat PtCross(NSPoint a, NSPoint b)
OOINLINE NSPoint PtRotCW(NSPoint p)
OOINLINE NSPoint PtAdd(NSPoint a, NSPoint b)
Definition OOPointMaths.h:6