Rev 2199 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1528 | jag | 1 | /* |
2 | * point.h |
||
2097 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2024 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1528 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
6 | */ |
||
7 | |||
8 | #ifndef __point |
||
9 | #define __point |
||
10 | |||
2178 | jag | 11 | #include <math.h> |
12 | |||
1528 | jag | 13 | template <class T> struct point { |
14 | T x, y; |
||
15 | point (T a, T b) : x(a), y(b) {} |
||
16 | point () : x(0), y(0) {} |
||
17 | void operator() (T a, T b) { |
||
18 | x = a; |
||
19 | y = b; |
||
20 | } |
||
2178 | jag | 21 | int operator== (const point<T>& p) { |
1528 | jag | 22 | return ( (x == p.x) && (y == p.y)); |
23 | } |
||
24 | |||
25 | point& operator+= (const T& d) { |
||
26 | x += d; |
||
27 | y += d; |
||
28 | return *this; |
||
29 | } |
||
30 | |||
31 | point& operator= (const T& d) { |
||
32 | x = d; |
||
33 | y = d; |
||
34 | return *this; |
||
35 | } |
||
36 | |||
37 | point& operator*= (const point<T>& m) { |
||
38 | x *= m.x; |
||
39 | y *= m.y; |
||
40 | return *this; |
||
41 | } |
||
42 | |||
43 | point& operator= (const point<T>& q) { |
||
44 | x = q.x; |
||
45 | y = q.y; |
||
46 | return *this; |
||
47 | } |
||
48 | |||
2178 | jag | 49 | void rotate (point<T>& c, T angle) { |
50 | T px = x - c.x, py = y - c.y; |
||
51 | x = px * cos (angle) - py * sin (angle) + c.x; |
||
52 | y = px * sin (angle) + py * cos (angle) + c.y; |
||
53 | } |
||
54 | |||
55 | void scale (point<T>& c, T sx, T sy) { |
||
56 | float px = sx * (x - c.x), py = sy * (y - c.y); |
||
57 | x = c.x + px; |
||
58 | y = c.y + py; |
||
59 | } |
||
60 | |||
1528 | jag | 61 | }; |
62 | |||
63 | template <typename T> point<T> operator+ (const point<T>& p1, const point<T>& p2) { |
||
64 | return point<T> (p1.x + p2.x, p1.y + p2.y); |
||
65 | } |
||
2178 | jag | 66 | |
2184 | jag | 67 | template <typename T> struct pointinfo : point<T> { |
2179 | jag | 68 | int pin; |
2208 | jag | 69 | void init () { pin = 0;} |
2184 | jag | 70 | pointinfo () { init(); } |
71 | pointinfo (const point<T>& p) : point<T> (p.x, p.y) { init(); } |
||
2208 | jag | 72 | pointinfo (T tx, T ty, int p = 0) :point<T> (tx, ty) { pin = p; } |
2179 | jag | 73 | }; |
74 | |||
1528 | jag | 75 | #endif |