1 #pragma once
2 
3 #include <cmath>
4 
5 struct Point {
PointPoint6 	Point() : x(0.0f), y(0.0f) {}
PointPoint7 	Point(float x_, float y_) : x(x_), y(y_) {}
8 
9 	float x;
10 	float y;
11 
distanceToPoint12 	float distanceTo(const Point &other) const {
13 		float dx = other.x - x, dy = other.y - y;
14 		return sqrtf(dx*dx + dy*dy);
15 	}
16 
17 	bool operator ==(const Point &other) const {
18 		return x == other.x && y == other.y;
19 	}
20 
21 	/*
22 	FocusDirection directionTo(const Point &other) const {
23 		int angle = atan2f(other.y - y, other.x - x) / (2 * M_PI) - 0.125;
24 
25 	}*/
26 };
27 
28 
29 // Resolved bounds on screen after layout.
30 struct Bounds {
BoundsBounds31 	Bounds() : x(0), y(0), w(0), h(0) {}
BoundsBounds32 	Bounds(float x_, float y_, float w_, float h_) : x(x_), y(y_), w(w_), h(h_) {}
33 
ContainsBounds34 	bool Contains(float px, float py) const {
35 		return (px >= x && py >= y && px < x + w && py < y + h);
36 	}
37 
IntersectsBounds38 	bool Intersects(const Bounds &other) const {
39 		return !(x > other.x2() || x2() < other.x || y > other.y2() || y2() < other.y);
40 	}
41 
ClipBounds42 	void Clip(const Bounds &clipTo) {
43 		if (x < clipTo.x) {
44 			w -= clipTo.x - x;
45 			x = clipTo.x;
46 		}
47 		if (y < clipTo.y) {
48 			h -= clipTo.y - y;
49 			y = clipTo.y;
50 		}
51 		if (x2() > clipTo.x2()) {
52 			w = clipTo.x2() - x;
53 		}
54 		if (y2() > clipTo.y2()) {
55 			h = clipTo.y2() - y;
56 		}
57 	}
58 
x2Bounds59 	float x2() const { return x + w; }
y2Bounds60 	float y2() const { return y + h; }
centerXBounds61 	float centerX() const { return x + w * 0.5f; }
centerYBounds62 	float centerY() const { return y + h * 0.5f; }
CenterBounds63 	Point Center() const {
64 		return Point(centerX(), centerY());
65 	}
ExpandBounds66 	Bounds Expand(float amount) const {
67 		return Bounds(x - amount, y - amount, w + amount * 2, h + amount * 2);
68 	}
ExpandBounds69 	Bounds Expand(float xAmount, float yAmount) const {
70 		return Bounds(x - xAmount, y - yAmount, w + xAmount * 2, h + yAmount * 2);
71 	}
OffsetBounds72 	Bounds Offset(float xAmount, float yAmount) const {
73 		return Bounds(x + xAmount, y + yAmount, w, h);
74 	}
75 
76 	float x;
77 	float y;
78 	float w;
79 	float h;
80 };
81 
82 
83