File: Point.h

package info (click to toggle)
storm-lang 0.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,028 kB
  • sloc: ansic: 261,471; cpp: 140,432; sh: 14,891; perl: 9,846; python: 2,525; lisp: 2,504; asm: 860; makefile: 678; pascal: 70; java: 52; xml: 37; awk: 12
file content (86 lines) | stat: -rw-r--r-- 2,432 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#pragma once
#include "Size.h"
#include "Angle.h"

namespace storm {
	namespace geometry {
		STORM_PKG(core.geometry);

		/**
		 * A point in 2D-space.
		 * Screen-space is assumed, where 0,0 is positioned in the upper left corner of the screen.
		 */
		class Point {
			STORM_VALUE;
		public:
			// Zero.
			STORM_CTOR Point();

			// Initialize.
			STORM_CTOR Point(Float x, Float y);

			// Convert.
			STORM_CAST_CTOR Point(Size s);

			// Coordinates.
			Float x;
			Float y;

			// Tangent. Always 90 deg clockwise from the vector in screen-space.
			Point STORM_FN tangent() const;

			// Compute the length squared of the point. Cheaper than the length.
			Float STORM_FN lengthSq() const;

			// Compute the lenght of the point.
			Float STORM_FN length() const;

			// Return a normalized point (i.e. length 1). If the point has length zero, then the
			// original point is returned.
			Point STORM_FN normalized() const;

			// Compute the taxicab/manhattan length (i.e. x + y).
			Float STORM_FN taxiLength() const;

			// Output.
			void STORM_FN toS(StrBuf *to) const;
		};

		wostream &operator <<(wostream &to, const Point &s);

		// Operations.
		Point STORM_FN operator +(Point a, Size b);
		Point STORM_FN operator +(Point a, Point b);
		Point STORM_FN operator -(Point a, Point b);
		Point STORM_FN operator -(Point a, Size b);
		Point STORM_FN operator -(Point a);
		Point &STORM_FN operator +=(Point &a, Point b);
		Point &STORM_FN operator -=(Point &a, Point b);

		Point STORM_FN operator *(Point a, Float b);
		Point STORM_FN operator *(Float a, Point b);
		Point STORM_FN operator /(Point a, Float b);
		Point &STORM_FN operator *=(Point &a, Float b);
		Point &STORM_FN operator /=(Point &a, Float b);

		// Dot product.
		Float STORM_FN operator *(Point a, Point b);

		inline Bool STORM_FN operator ==(Point a, Point b) { return a.x == b.x && a.y == b.y; }
		inline Bool STORM_FN operator !=(Point a, Point b) { return !(a == b); }

		// Create an angle based on the point. 0 deg is (0, -1)
		Point STORM_FN angle(Angle angle);

		// Project the point `pt` onto a line that starts in `origin` and expands in the direction
		// of `dir`. `dir` does not have to be normalized.
		Point STORM_FN project(Point pt, Point origin, Point dir);

		// Center point of a size.
		Point STORM_FN center(Size s);

		// Compute the absolute value of both compontents in the point.
		Point STORM_FN abs(Point a);

	}
}