CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
MathClasses.h
Go to the documentation of this file.
1
9#if !defined(_MATHCLASSES_H)
10#define _MATHCLASSES_H
11
12#define _USE_MATH_DEFINES
13// #define __USE_GNU
14#include <math.h>
15#include <map>
16#include <array>
17
18#include "Utils.h"
19
20namespace cmlabs {
21
22class Size;
23class PointFloat;
24class Vector2D;
25class Vector3D;
26
27
29const std::map<std::string, std::array<uint8, 3> > ColorMap = {
30 { "maroon",{ { 128,0,0 } } },
31 { "dark red",{ { 139,0,0 } } },
32 { "darkred",{ { 139,0,0 } } },
33 { "brown",{ { 165,42,42 } } },
34 { "firebrick",{ { 178,34,34 } } },
35 { "crimson",{ { 220,20,60 } } },
36 { "red",{ { 255,0,0 } } },
37 { "tomato",{ { 255,99,71 } } },
38 { "coral",{ { 255,127,80 } } },
39 { "indian red",{ { 205,92,92 } } },
40 { "indianred",{ { 205,92,92 } } },
41 { "light coral",{ { 240,128,128 } } },
42 { "lightcoral",{ { 240,128,128 } } },
43 { "dark salmon",{ { 233,150,122 } } },
44 { "darksalmon",{ { 233,150,122 } } },
45 { "salmon",{ { 250,128,114 } } },
46 { "light salmon",{ { 255,160,122 } } },
47 { "lightsalmon",{ { 255,160,122 } } },
48 { "orange red",{ { 255,69,0 } } },
49 { "orangered",{ { 255,69,0 } } },
50 { "dark orange",{ { 255,140,0 } } },
51 { "darkorange",{ { 255,140,0 } } },
52 { "orange",{ { 255,165,0 } } },
53 { "gold",{ { 255,215,0 } } },
54 { "dark golden rod",{ { 184,134,11 } } },
55 { "darkgoldenrod",{ { 184,134,11 } } },
56 { "golden rod",{ { 218,165,32 } } },
57 { "goldenrod",{ { 218,165,32 } } },
58 { "pale golden rod",{ { 238,232,170 } } },
59 { "palegoldenrod",{ { 238,232,170 } } },
60 { "dark khaki",{ { 189,183,107 } } },
61 { "darkkhaki",{ { 189,183,107 } } },
62 { "khaki",{ { 240,230,140 } } },
63 { "olive",{ { 128,128,0 } } },
64 { "yellow",{ { 255,255,0 } } },
65 { "yellow green",{ { 154,205,50 } } },
66 { "yellowgreen",{ { 154,205,50 } } },
67 { "dark olive green",{ { 85,107,47 } } },
68 { "darkolivegreen",{ { 85,107,47 } } },
69 { "olive drab",{ { 107,142,35 } } },
70 { "olivedrab",{ { 107,142,35 } } },
71 { "lawn green",{ { 124,252,0 } } },
72 { "lawngreen",{ { 124,252,0 } } },
73 { "chart reuse",{ { 127,255,0 } } },
74 { "chartreuse",{ { 127,255,0 } } },
75 { "green yellow",{ { 173,255,47 } } },
76 { "greenyellow",{ { 173,255,47 } } },
77 { "dark green",{ { 0,100,0 } } },
78 { "darkgreen",{ { 0,100,0 } } },
79 { "green",{ { 0,128,0 } } },
80 { "forest green",{ { 34,139,34 } } },
81 { "forestgreen",{ { 34,139,34 } } },
82 { "lime",{ { 0,255,0 } } },
83 { "lime green",{ { 50,205,50 } } },
84 { "limegreen",{ { 50,205,50 } } },
85 { "light green",{ { 144,238,144 } } },
86 { "lightgreen",{ { 144,238,144 } } },
87 { "pale green",{ { 152,251,152 } } },
88 { "palegreen",{ { 152,251,152 } } },
89 { "dark sea green",{ { 143,188,143 } } },
90 { "darkseagreen",{ { 143,188,143 } } },
91 { "medium spring green",{ { 0,250,154 } } },
92 { "mediumspringgreen",{ { 0,250,154 } } },
93 { "spring green",{ { 0,255,127 } } },
94 { "springgreen",{ { 0,255,127 } } },
95 { "sea green",{ { 46,139,87 } } },
96 { "seagreen",{ { 46,139,87 } } },
97 { "medium aqua marine",{ { 102,205,170 } } },
98 { "mediumaquamarine",{ { 102,205,170 } } },
99 { "medium sea green",{ { 60,179,113 } } },
100 { "mediumseagreen",{ { 60,179,113 } } },
101 { "light sea green",{ { 32,178,170 } } },
102 { "lightseagreen",{ { 32,178,170 } } },
103 { "dark slate gray",{ { 47,79,79 } } },
104 { "darkslategray",{ { 47,79,79 } } },
105 { "teal",{ { 0,128,128 } } },
106 { "dark cyan",{ { 0,139,139 } } },
107 { "darkcyan",{ { 0,139,139 } } },
108 { "aqua",{ { 0,255,255 } } },
109 { "cyan",{ { 0,255,255 } } },
110 { "light cyan",{ { 224,255,255 } } },
111 { "lightcyan",{ { 224,255,255 } } },
112 { "dark turquoise",{ { 0,206,209 } } },
113 { "darkturquoise",{ { 0,206,209 } } },
114 { "turquoise",{ { 64,224,208 } } },
115 { "medium turquoise",{ { 72,209,204 } } },
116 { "mediumturquoise",{ { 72,209,204 } } },
117 { "pale turquoise",{ { 175,238,238 } } },
118 { "paleturquoise",{ { 175,238,238 } } },
119 { "aqua marine",{ { 127,255,212 } } },
120 { "aquamarine",{ { 127,255,212 } } },
121 { "powder blue",{ { 176,224,230 } } },
122 { "powderblue",{ { 176,224,230 } } },
123 { "cadet blue",{ { 95,158,160 } } },
124 { "cadetblue",{ { 95,158,160 } } },
125 { "steel blue",{ { 70,130,180 } } },
126 { "steelblue",{ { 70,130,180 } } },
127 { "corn flower blue",{ { 100,149,237 } } },
128 { "cornflowerblue",{ { 100,149,237 } } },
129 { "deep sky blue",{ { 0,191,255 } } },
130 { "deepskyblue",{ { 0,191,255 } } },
131 { "dodger blue",{ { 30,144,255 } } },
132 { "dodgerblue",{ { 30,144,255 } } },
133 { "light blue",{ { 173,216,230 } } },
134 { "lightblue",{ { 173,216,230 } } },
135 { "sky blue",{ { 135,206,235 } } },
136 { "skyblue",{ { 135,206,235 } } },
137 { "light sky blue",{ { 135,206,250 } } },
138 { "lightskyblue",{ { 135,206,250 } } },
139 { "midnight blue",{ { 25,25,112 } } },
140 { "midnightblue",{ { 25,25,112 } } },
141 { "navy",{ { 0,0,128 } } },
142 { "dark blue",{ { 0,0,139 } } },
143 { "darkblue",{ { 0,0,139 } } },
144 { "medium blue",{ { 0,0,205 } } },
145 { "mediumblue",{ { 0,0,205 } } },
146 { "blue",{ { 0,0,255 } } },
147 { "royal blue",{ { 65,105,225 } } },
148 { "royalblue",{ { 65,105,225 } } },
149 { "blue violet",{ { 138,43,226 } } },
150 { "blueviolet",{ { 138,43,226 } } },
151 { "indigo",{ { 75,0,130 } } },
152 { "dark slate blue",{ { 72,61,139 } } },
153 { "darkslateblue",{ { 72,61,139 } } },
154 { "slate blue",{ { 106,90,205 } } },
155 { "slateblue",{ { 106,90,205 } } },
156 { "medium slate blue",{ { 123,104,238 } } },
157 { "mediumslateblue",{ { 123,104,238 } } },
158 { "medium purple",{ { 147,112,219 } } },
159 { "mediumpurple",{ { 147,112,219 } } },
160 { "dark magenta",{ { 139,0,139 } } },
161 { "darkmagenta",{ { 139,0,139 } } },
162 { "dark violet",{ { 148,0,211 } } },
163 { "darkviolet",{ { 148,0,211 } } },
164 { "dark orchid",{ { 153,50,204 } } },
165 { "darkorchid",{ { 153,50,204 } } },
166 { "medium orchid",{ { 186,85,211 } } },
167 { "mediumorchid",{ { 186,85,211 } } },
168 { "purple",{ { 128,0,128 } } },
169 { "thistle",{ { 216,191,216 } } },
170 { "plum",{ { 221,160,221 } } },
171 { "violet",{ { 238,130,238 } } },
172 { "magenta",{ { 255,0,255 } } },
173 { "fuchsia",{ { 255,0,255 } } },
174 { "orchid",{ { 218,112,214 } } },
175 { "medium violet red",{ { 199,21,133 } } },
176 { "mediumvioletred",{ { 199,21,133 } } },
177 { "pale violet red",{ { 219,112,147 } } },
178 { "palevioletred",{ { 219,112,147 } } },
179 { "deep pink",{ { 255,20,147 } } },
180 { "deeppink",{ { 255,20,147 } } },
181 { "hot pink",{ { 255,105,180 } } },
182 { "hotpink",{ { 255,105,180 } } },
183 { "light pink",{ { 255,182,193 } } },
184 { "lightpink",{ { 255,182,193 } } },
185 { "pink",{ { 255,192,203 } } },
186 { "antique white",{ { 250,235,215 } } },
187 { "antiquewhite",{ { 250,235,215 } } },
188 { "beige",{ { 245,245,220 } } },
189 { "bisque",{ { 255,228,196 } } },
190 { "blanched almond",{ { 255,235,205 } } },
191 { "blanchedalmond",{ { 255,235,205 } } },
192 { "wheat",{ { 245,222,179 } } },
193 { "corn silk",{ { 255,248,220 } } },
194 { "cornsilk",{ { 255,248,220 } } },
195 { "lemon chiffon",{ { 255,250,205 } } },
196 { "lemonchiffon",{ { 255,250,205 } } },
197 { "light golden rod yellow",{ { 250,250,210 } } },
198 { "lightgoldenrodyellow",{ { 250,250,210 } } },
199 { "light yellow",{ { 255,255,224 } } },
200 { "lightyellow",{ { 255,255,224 } } },
201 { "saddle brown",{ { 139,69,19 } } },
202 { "saddlebrown",{ { 139,69,19 } } },
203 { "sienna",{ { 160,82,45 } } },
204 { "chocolate",{ { 210,105,30 } } },
205 { "peru",{ { 205,133,63 } } },
206 { "sandy brown",{ { 244,164,96 } } },
207 { "sandybrown",{ { 244,164,96 } } },
208 { "burly wood",{ { 222,184,135 } } },
209 { "burlywood",{ { 222,184,135 } } },
210 { "tan",{ { 210,180,140 } } },
211 { "rosy brown",{ { 188,143,143 } } },
212 { "rosybrown",{ { 188,143,143 } } },
213 { "moccasin",{ { 255,228,181 } } },
214 { "navajo white",{ { 255,222,173 } } },
215 { "navajowhite",{ { 255,222,173 } } },
216 { "peach puff",{ { 255,218,185 } } },
217 { "peachpuff",{ { 255,218,185 } } },
218 { "misty rose",{ { 255,228,225 } } },
219 { "mistyrose",{ { 255,228,225 } } },
220 { "lavender blush",{ { 255,240,245 } } },
221 { "lavenderblush",{ { 255,240,245 } } },
222 { "linen",{ { 250,240,230 } } },
223 { "old lace",{ { 253,245,230 } } },
224 { "oldlace",{ { 253,245,230 } } },
225 { "papaya whip",{ { 255,239,213 } } },
226 { "papayawhip",{ { 255,239,213 } } },
227 { "sea shell",{ { 255,245,238 } } },
228 { "seashell",{ { 255,245,238 } } },
229 { "mint cream",{ { 245,255,250 } } },
230 { "mintcream",{ { 245,255,250 } } },
231 { "slate gray",{ { 112,128,144 } } },
232 { "slategray",{ { 112,128,144 } } },
233 { "light slate gray",{ { 119,136,153 } } },
234 { "lightslategray",{ { 119,136,153 } } },
235 { "light steel blue",{ { 176,196,222 } } },
236 { "lightsteelblue",{ { 176,196,222 } } },
237 { "lavender",{ { 230,230,250 } } },
238 { "floral white",{ { 255,250,240 } } },
239 { "floralwhite",{ { 255,250,240 } } },
240 { "alice blue",{ { 240,248,255 } } },
241 { "aliceblue",{ { 240,248,255 } } },
242 { "ghost white",{ { 248,248,255 } } },
243 { "ghostwhite",{ { 248,248,255 } } },
244 { "honeydew",{ { 240,255,240 } } },
245 { "ivory",{ { 255,255,240 } } },
246 { "azure",{ { 240,255,255 } } },
247 { "snow",{ { 255,250,250 } } },
248 { "black",{ { 0,0,0 } } },
249 { "dim gray",{ { 105,105,105 } } },
250 { "dimgray",{ { 105,105,105 } } },
251 { "dim grey",{ { 105,105,105 } } },
252 { "dimgrey",{ { 105,105,105 } } },
253 { "gray",{ { 128,128,128 } } },
254 { "grey",{ { 128,128,128 } } },
255 { "dark grey",{ { 169,169,169 } } },
256 { "darkgrey",{ { 169,169,169 } } },
257 { "dark gray",{ { 169,169,169 } } },
258 { "darkgray",{ { 169,169,169 } } },
259 { "silver",{ { 192,192,192 } } },
260 { "light gray",{ { 211,211,211 } } },
261 { "lightgray",{ { 211,211,211 } } },
262 { "light grey",{ { 211,211,211 } } },
263 { "lightgrey",{ { 211,211,211 } } },
264 { "gainsboro",{ { 220,220,220 } } },
265 { "white smoke",{ { 245,245,245 } } },
266 { "whitesmoke",{ { 245,245,245 } } },
267 { "white",{ { 255,255,255 } } }
268};
269
287class Color
288{
289public:
290 Color();
291 Color(uint8 red, uint8 green, uint8 blue);
292 Color(const char* name);
293 Color(const Color &color);
294 virtual ~Color();
295
302 Color mixOn(Color& color, double weight);
304 uint8 getGreyValue();
305
306 uint8 r, g, b;
307 uint32 size;
308
310 double distance(Color &otherColor);
311 //bool setNoColor();
312 //bool isValid();
313 //bool isNoColor();
314
317 static std::vector<Color> createColorsMaxDifference(uint32 count, bool mix = false);
319 std::string toRGBString() {
320 return utils::StringFormat("%u,%u,%u", r, g, b);
321 }
322
323private:
324 bool init(uint8 red, uint8 green, uint8 blue);
325 bool init(const char* colorName);
326};
327
328
330// Size Class
332
334class Size
335{
336public:
337 Size();
338 Size(double width, double height, double depth = 0);
339 virtual ~Size();
340
341 double w;
342 double h;
343 double d;
344
345 bool equals(const Size& size) const;
346 bool operator==(const Size &p) const;
347 Size operator*(const Vector2D &v) const;
348
349 double getHeight() const;
350 double getWidth() const;
351 double getDepth() const;
352
353 bool setHeight(double height);
354 bool setWidth(double width);
355 bool setDepth(double depth);
356
357 bool isNonZero() const;
358 double getArea() const;
359 double getDiagonalLenth() const;
360
361 std::string print() ;
362};
363
364
366// Point Class
368
385class Point
386{
387public:
388 Point();
389 Point(int px, int py, int pz=0, Size psize=Size());
390 virtual ~Point();
391
392 operator PointFloat() const;
393
394 int x;
395 int y;
396 int z;
398
399 int operator[](int n) const;
400 bool operator==(const Point &p) const;
401 bool operator==(const PointFloat &p) const;
402 Point operator-(const Point &p) const;
403 PointFloat operator-(const PointFloat &p) const;
404 Point operator+(const Point &p) const;
405 PointFloat operator+(const PointFloat &p) const;
406 PointFloat operator+(const Vector2D &v) const;
407 PointFloat operator+(const Vector3D &v) const;
408 Point operator*(const Point &p) const;
409 PointFloat operator*(const PointFloat &p) const;
410 Point operator-(double a) const;
411 Point operator+(double a) const;
412 Point operator*(double a) const;
413
414 int getX() const;
415 int getY() const;
416 int getZ() const;
417 Size getSize() const;
418
419 bool set(int x, int y, int z=0);
420 bool setX(int n);
421 bool setY(int n);
422 bool setZ(int n);
423 bool setSize(Size s);
424
425 double getDistanceTo(Point &p) const;
426 double getDistanceTo(PointFloat &p) const;
427
428 std::string print() ;
429};
430
431
433// PointFloat Class
435
439{
440public:
441 PointFloat();
442 PointFloat(double px, double py, double pz=0, Size psize=Size());
443 virtual ~PointFloat();
444
445 operator Point() const;
446
447 double x;
448 double y;
449 double z;
451
452 double operator[](int n) const;
453 bool operator==(const Point &p) const;
454 bool operator==(const PointFloat &p) const;
455 PointFloat operator-(const Point &p) const;
456 PointFloat operator-(const PointFloat &p) const;
457 PointFloat operator+(const Point &p) const;
458 PointFloat operator+(const PointFloat &p) const;
459 PointFloat operator+(const Vector2D &v) const;
460 PointFloat operator+(const Vector3D &v) const;
461 PointFloat operator*(const Point &p) const;
462 PointFloat operator*(const PointFloat &p) const;
463 PointFloat operator-(double a) const;
464 PointFloat operator+(double a) const;
465 PointFloat operator*(double a) const;
466
467 double getX() const;
468 double getY() const;
469 double getZ() const;
470 Size getSize() const;
471
472 bool set(double x, double y, double z=0);
473 bool setX(double v);
474 bool setY(double v);
475 bool setZ(double v);
476 bool setSize(Size s);
477
478 double getDistanceTo(const Point &p) const;
479 double getDistanceTo(const PointFloat &p) const;
480
481 std::string print();
482};
483
484
486// Line Class
488
490class Line
491{
492public:
493 Line();
494 Line(PointFloat startpoint, PointFloat endpoint, double width = 0);
495 virtual ~Line();
496
499 double lineWidth;
500
501 PointFloat getStartPoint() const;
502 PointFloat getEndPoint() const;
503 double getLineWidth() const;
504
505 bool setStartPoint(PointFloat point);
506 bool setEndPoint(PointFloat point);
507 bool setLineWidth(double width);
508
509 std::string print();
510};
511
512
514// PolyLine Class
516
519{
520public:
521 PolyLine();
522 virtual ~PolyLine();
523
524 std::vector<Line> lines;
525
526 uint32 getLineCount() const;
527 Line getLine(uint32 pos) const;
528 bool addLine(Line line);
529 bool replaceLine(uint32 pos, Line newline);
530 bool removeLine(uint32 pos);
531
532 std::string print();
533};
534
535
537// Box Class
539
557class Box
558{
559public:
560 Box();
561 Box(PointFloat upperleft, Size boxsize, double linewidth = 0);
562 Box(PointFloat upperleft, PointFloat lowerright, double linewidth = 0);
563 Box(double x, double y, double w, double h, double linewidth = 0);
564 virtual ~Box();
565
568 double lineWidth;
569 std::string name;
570 std::string comment;
571 double orientation;
572
573 double getUpperY() const;
574 double getLowerY() const;
575 double getLeftX() const;
576 double getRightX() const;
577 double getArea() const;
578
579 double getCMX() const;
580 double getCMY() const;
581 PointFloat getCM() const;
582
583 PointFloat getUpperLeft() const;
584 PointFloat getUpperRight() const;
585 PointFloat getLowerLeft() const;
586 PointFloat getLowerRight() const;
587 double getLineWidth() const;
588 Size getSize() const;
589 double getWidth() const;
590 double getHeight() const;
591
592 Box operator-(const Point &p) const;
593 Box operator-(const PointFloat &p) const;
594 Box operator+(const Point &p) const;
595 Box operator+(const PointFloat &p) const;
596 bool move(double dx, double dy);
597 bool moveTo(double x, double y);
598 bool set(double x, double y, double w, double h, double linewidth = 0);
599 bool setUpperLeft(const PointFloat& point);
600 bool setSize(const Size& boxsize);
601 bool setLineWidth(double width);
602 bool grow(double dw, double dh);
603
604 bool isPointWithin(const PointFloat& point) const;
605 bool isPointWithin(int x, int y) const;
606 PointFloat getCentreMass() const;
607
608 bool hasZeroSize() const;
609 bool equals(const Box &otherbox) const;
610 bool equals(const Box &otherbox, double maxerror) const;
611 Box getBoundingBox(const Box &otherbox) const;
612 bool growToBoundingBox(const Box &otherbox);
613 bool growToIncludePoint(const Point& point, int padX = 0, int padY = 0);
614 Box getOverlapBox(const Box &otherbox) const;
620 double percentOverlap(const Box &otherbox) const;
621
623 bool constrainTo(const Box& box);
624 bool constrainTo(double x, double y, double w, double h);
625 Box getConstrainedCopy(const Box& box);
626 Box getConstrainedCopy(double x, double y, double w, double h);
627
628 std::string print();
629};
630
631
633// Vector2D Class
635
657{
658public:
659 Vector2D();
660 Vector2D(double x, double y);
661 virtual ~Vector2D();
662
663 double x;
664 double y;
665
666 double operator[](int n) const;
667 bool operator==(const Vector2D &v) const;
668 Vector2D operator-(const Vector2D &v) const;
669 Vector2D operator+(const Vector2D &v) const;
670 double operator*(const Vector2D &v) const;
671 Vector2D operator-(double a) const;
672 Vector2D operator+(double a) const;
673 Vector2D operator*(double a) const;
674 const Vector2D& operator-=(const Vector2D &v);
675 const Vector2D& operator+=(const Vector2D &v);
676 const Vector2D& operator-=(double a);
677 const Vector2D& operator+=(double a);
678 const Vector2D& operator*=(double a);
679
680 double getX() const;
681 double getY() const;
682
683 bool set(const PointFloat& p1, const PointFloat& p2);
684 bool set(double x1, double y1, double x2, double y2);
685 bool set(double x, double y);
686 bool setX(double v);
687 bool setY(double v);
688 bool setLength(double l);
689 bool makeUnitVector();
690
691 double length() const;
692 double det(const Vector2D &v) const;
693 bool isOrthogonalWith(const Vector2D &v) const;
694 bool isParallelWith(const Vector2D &v) const;
695 Vector2D getProjectionOn(const Vector2D &v) const;
696 Vector2D getUnitVector() const;
698 double getAngle(const Vector2D &v) const;
699 double getArea(const Vector2D &v) const;
700
701 Vector2D rotate(double angle);
702 bool rotateIt(double angle);
703
704 std::string print();
705};
706
707
709// Vector3D Class
711
726{
727public:
728 Vector3D();
729 Vector3D(double x, double y, double z);
730 virtual ~Vector3D();
731
732 double x;
733 double y;
734 double z;
735
736 double operator[](int n) const;
737 bool operator==(const Vector3D &v) const;
738 Vector3D operator-(const Vector3D &v) const;
739 Vector3D operator+(const Vector3D &v) const;
740 double operator*(const Vector3D &v) const;
741 Vector3D operator-(double a) const;
742 Vector3D operator+(double a) const;
743 Vector3D operator*(double a) const;
744 const Vector3D& operator-=(const Vector3D &v);
745 const Vector3D& operator+=(const Vector3D &v);
746 const Vector3D& operator-=(double a);
747 const Vector3D& operator+=(double a);
748 const Vector3D& operator*=(double a);
749
750 double getX() const;
751 double getY() const;
752 double getZ() const;
753
754 bool set(const PointFloat& p1, const PointFloat& p2);
755 bool set(double x1, double y1, double z1, double x2, double y2, double z2);
756 bool set(double x, double y, double z);
757 bool setX(double v);
758 bool setY(double v);
759 bool setZ(double v);
760
761 double length() const;
762 Vector3D product(const Vector3D &v) const;
763 bool isOrthogonalWith(const Vector3D &v) const;
764 bool isParallelWith(const Vector3D &v) const;
765 Vector3D getProjectionOn(const Vector3D &v) const;
766 Vector3D getUnitVector() const;
767 double getAngle(const Vector3D &v) const;
768 double getArea(const Vector3D &v) const;
769
770 std::string print();
771};
772
774// RandomPathGenerator Class
776
780public:
783
784 bool setStartPoint(double x, double y);
785 bool setDirection(double dx, double dy);
786 bool setVariation(double var);
787
789
794
795};
796
799
800} // namespace cmlabs
801
802#endif // !defined(_MATHCLASSES_H)
Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory,...
bool setSize(const Size &boxsize)
Set the extent.
bool setUpperLeft(const PointFloat &point)
Set the corner.
Size size
Extent.
bool growToIncludePoint(const Point &point, int padX=0, int padY=0)
Enlarge to include point plus padding.
double getArea() const
double getWidth() const
Box getOverlapBox(const Box &otherbox) const
double getLineWidth() const
PointFloat getLowerLeft() const
virtual ~Box()
Size getSize() const
PointFloat getCM() const
bool move(double dx, double dy)
Translate in place.
bool moveTo(double x, double y)
Move the upper-left corner to (x,y).
double percentOverlap(const Box &otherbox) const
Overlap between the two boxes as a fraction of the larger area.
bool isPointWithin(const PointFloat &point) const
PointFloat getCentreMass() const
Box operator-(const Point &p) const
Box translated by -p.
double lineWidth
Stroke width (drawing hint).
bool setLineWidth(double width)
Set the stroke width.
bool hasZeroSize() const
double getUpperY() const
bool grow(double dw, double dh)
Enlarge by (dw,dh), keeping the upper-left corner.
bool growToBoundingBox(const Box &otherbox)
Enlarge in place to include otherbox.
double getHeight() const
PointFloat getUpperLeft() const
Box getDoubleSizeSameCenter()
double getCMX() const
double orientation
Optional rotation metadata (radians); not applied by the geometric queries.
Box operator+(const Point &p) const
Box translated by +p.
double getLeftX() const
Box getConstrainedCopy(const Box &box)
std::string print()
Human-readable representation for debugging.
PointFloat upperLeft
Upper-left corner.
bool equals(const Box &otherbox) const
Exact geometric equality.
PointFloat getLowerRight() const
bool constrainTo(const Box &box)
Clip this box in place to lie within box.
Box getBoundingBox(const Box &otherbox) const
double getLowerY() const
std::string name
Optional label.
bool set(double x, double y, double w, double h, double linewidth=0)
Reset all geometry.
double getCMY() const
double getRightX() const
PointFloat getUpperRight() const
Box()
Empty box at the origin.
std::string comment
Optional free-form comment.
Color mixOn(Color &color, double weight)
Blend this color onto a background color.
static std::vector< Color > createColorsMaxDifference(uint32 count, bool mix=false)
Generate count colors spread for maximum mutual visual difference (e.g.
Color getReverseColor()
Component-wise inverse (255-r, 255-g, 255-b).
uint8 getGreyValue()
Grey value as the plain average (r+g+b)/3.
Color()
Black (0,0,0).
double distance(Color &otherColor)
Euclidean distance to another color in RGB space.
std::string toRGBString()
Format as "r,g,b" decimal text.
Line segment between two PointFloat endpoints with a drawing width.
double lineWidth
Stroke width (drawing hint).
Line()
Degenerate line at the origin.
PointFloat getStartPoint() const
double getLineWidth() const
std::string print()
Human-readable representation for debugging.
bool setLineWidth(double width)
Set the stroke width.
bool setStartPoint(PointFloat point)
Set the start point.
bool setEndPoint(PointFloat point)
Set the end point.
virtual ~Line()
PointFloat getEndPoint() const
PointFloat startPoint
First endpoint.
PointFloat endPoint
Second endpoint.
Floating-point 3D point with an optional attached Size; float counterpart of Point.
PointFloat()
Origin (0,0,0).
double getY() const
bool setX(double v)
Set x.
std::string print()
Human-readable representation for debugging.
double getDistanceTo(const Point &p) const
Euclidean distance to an integer point.
double getZ() const
double operator[](int n) const
Component access: 0=x, 1=y, 2=z.
Size getSize() const
bool setSize(Size s)
Set the attached size.
PointFloat operator+(const Point &p) const
Element-wise sum.
bool set(double x, double y, double z=0)
Set all coordinates.
bool setY(double v)
Set y.
bool operator==(const Point &p) const
Equality against an integer point.
bool setZ(double v)
Set z.
double getX() const
PointFloat operator*(const Point &p) const
Element-wise product.
PointFloat operator-(const Point &p) const
Element-wise difference.
Integer 3D point with an optional attached Size; interoperates with PointFloat and vectors.
Point operator*(const Point &p) const
Element-wise product.
bool setX(int n)
Set x.
int operator[](int n) const
Component access: 0=x, 1=y, 2=z.
bool setY(int n)
Set y.
bool setZ(int n)
Set z.
bool setSize(Size s)
Set the attached size.
Point operator-(const Point &p) const
Element-wise difference.
double getDistanceTo(Point &p) const
Euclidean distance to another point.
Point()
Origin (0,0,0).
Size getSize() const
std::string print()
Human-readable representation for debugging.
int getZ() const
bool operator==(const Point &p) const
Exact coordinate equality.
int getX() const
bool set(int x, int y, int z=0)
Set all coordinates.
Point operator+(const Point &p) const
Element-wise sum.
int getY() const
virtual ~Point()
uint32 getLineCount() const
std::string print()
Human-readable representation for debugging.
bool replaceLine(uint32 pos, Line newline)
Replace the segment at pos.
bool addLine(Line line)
Append a segment.
bool removeLine(uint32 pos)
Remove the segment at pos.
std::vector< Line > lines
The segments, in order.
Line getLine(uint32 pos) const
uint64 lastPointTime
Timestamp of the last generated point (ms).
bool setDirection(double dx, double dy)
Set the base movement direction per step.
Vector2D direction
Current movement direction.
Vector2D variation
Random variation applied per step.
bool setStartPoint(double x, double y)
Set the initial position.
bool setVariation(double var)
Set the random perturbation magnitude.
PointFloat generateNextPoint()
Advance one step and return the new position.
PointFloat lastPoint
Most recently generated position.
2D/3D extent (width, height, optional depth) stored as doubles.
bool setDepth(double depth)
Set depth.
bool equals(const Size &size) const
Exact component equality.
virtual ~Size()
bool setHeight(double height)
Set height.
double d
Depth (0 for 2D use).
Size()
Zero size.
bool operator==(const Size &p) const
Same as equals().
double getHeight() const
double getDiagonalLenth() const
double h
Height.
double getDepth() const
double getArea() const
bool setWidth(double width)
Set width.
double w
Width.
bool isNonZero() const
Size operator*(const Vector2D &v) const
Scale w by v.x and h by v.y.
double getWidth() const
std::string print()
Human-readable representation for debugging.
2D vector with the usual linear algebra: dot product, determinant, projection, rotation,...
double getX() const
double length() const
Vector2D getProjectionOn(const Vector2D &v) const
bool setLength(double l)
Rescale to length l, keeping direction.
Vector2D rotate(double angle)
Rotated copy; this vector is unchanged.
const Vector2D & operator-=(const Vector2D &v)
In-place subtract.
Vector2D getUnitVector() const
double getY() const
bool isParallelWith(const Vector2D &v) const
double operator*(const Vector2D &v) const
Dot product.
bool setX(double v)
Set x.
const Vector2D & operator*=(double a)
In-place scale.
double operator[](int n) const
Component access: 0=x, 1=y.
Vector2D getOrthogonalVector() const
Vector2D()
Zero vector.
Vector2D operator-(const Vector2D &v) const
Difference.
double getAngle(const Vector2D &v) const
Unsigned angle to v via acos of the normalized dot product.
bool set(const PointFloat &p1, const PointFloat &p2)
Set as p2-p1.
double y
Y component.
std::string print()
Human-readable representation for debugging.
Vector2D operator+(const Vector2D &v) const
Sum.
bool isOrthogonalWith(const Vector2D &v) const
const Vector2D & operator+=(const Vector2D &v)
In-place add.
bool makeUnitVector()
Normalize in place.
double x
X component.
bool operator==(const Vector2D &v) const
Component equality.
bool setY(double v)
Set y.
bool rotateIt(double angle)
Rotate in place by angle radians (same convention as rotate()).
double det(const Vector2D &v) const
2D cross product / determinant (x*v.y - y*v.x); sign gives turn direction.
double getArea(const Vector2D &v) const
3D vector with dot/cross products, projection and angle math.
double getX() const
double getAngle(const Vector3D &v) const
bool operator==(const Vector3D &v) const
Component equality.
double getY() const
bool setZ(double v)
Set z.
Vector3D getProjectionOn(const Vector3D &v) const
bool setY(double v)
Set y.
double z
Z component.
bool isParallelWith(const Vector3D &v) const
double getArea(const Vector3D &v) const
bool setX(double v)
Set x.
std::string print()
Human-readable representation for debugging.
Vector3D()
Zero vector.
double operator[](int n) const
Component access: 0=x, 1=y, 2=z.
bool set(const PointFloat &p1, const PointFloat &p2)
Set as p2-p1.
double length() const
Vector3D getUnitVector() const
bool isOrthogonalWith(const Vector3D &v) const
Vector3D product(const Vector3D &v) const
Cross product with v.
double operator*(const Vector3D &v) const
Dot product.
const Vector3D & operator+=(const Vector3D &v)
In-place add.
double y
Y component.
Vector3D operator+(const Vector3D &v) const
Sum.
const Vector3D & operator*=(double a)
In-place scale.
double getZ() const
const Vector3D & operator-=(const Vector3D &v)
In-place subtract.
Vector3D operator-(const Vector3D &v) const
Difference.
double x
X component.
std::string StringFormat(const char *format,...)
printf into a std::string.
Definition Utils.cpp:6626
const std::map< std::string, std::array< uint8, 3 > > ColorMap
Lookup table mapping ~200 CSS/X11 color names (with and without spaces) to 8-bit RGB triplets; used b...
Definition MathClasses.h:29
bool MathClasses_UnitTest()
Unit test for the MathClasses module (geometry / vectors / boxes).