9#if !defined(_MATHCLASSES_H)
12#define _USE_MATH_DEFINES
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 } } }
291 Color(uint8 red, uint8 green, uint8 blue);
292 Color(
const char* name);
324 bool init(uint8 red, uint8 green, uint8 blue);
325 bool init(
const char* colorName);
338 Size(
double width,
double height,
double depth = 0);
361 std::string
print() ;
419 bool set(
int x,
int y,
int z=0);
428 std::string
print() ;
445 operator Point()
const;
472 bool set(
double x,
double y,
double z=0);
563 Box(
double x,
double y,
double w,
double h,
double linewidth = 0);
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);
602 bool grow(
double dw,
double dh);
610 bool equals(
const Box &otherbox,
double maxerror)
const;
624 bool constrainTo(
double x,
double y,
double w,
double h);
684 bool set(
double x1,
double y1,
double x2,
double y2);
685 bool set(
double x,
double y);
755 bool set(
double x1,
double y1,
double z1,
double x2,
double y2,
double z2);
756 bool set(
double x,
double y,
double z);
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.
bool growToIncludePoint(const Point &point, int padX=0, int padY=0)
Enlarge to include point plus padding.
Box getOverlapBox(const Box &otherbox) const
double getLineWidth() const
PointFloat getLowerLeft() 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 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.
PointFloat getUpperLeft() const
Box getDoubleSizeSameCenter()
double orientation
Optional rotation metadata (radians); not applied by the geometric queries.
Box operator+(const Point &p) const
Box translated by +p.
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
std::string name
Optional label.
bool set(double x, double y, double w, double h, double linewidth=0)
Reset all geometry.
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.
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.
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).
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 operator[](int n) const
Component access: 0=x, 1=y, 2=z.
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.
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.
int operator[](int n) const
Component access: 0=x, 1=y, 2=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.
std::string print()
Human-readable representation for debugging.
bool operator==(const Point &p) const
Exact coordinate equality.
bool set(int x, int y, int z=0)
Set all coordinates.
Point operator+(const Point &p) const
Element-wise sum.
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.
bool setHeight(double height)
Set height.
double d
Depth (0 for 2D use).
bool operator==(const Size &p) const
Same as equals().
double getDiagonalLenth() const
bool setWidth(double width)
Set width.
Size operator*(const Vector2D &v) const
Scale w by v.x and h by v.y.
std::string print()
Human-readable representation for debugging.
2D vector with the usual linear algebra: dot product, determinant, projection, rotation,...
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
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 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.
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.
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 getAngle(const Vector3D &v) const
bool operator==(const Vector3D &v) const
Component equality.
bool setZ(double v)
Set z.
Vector3D getProjectionOn(const Vector3D &v) const
bool setY(double v)
Set y.
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.
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.
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.
Vector3D operator+(const Vector3D &v) const
Sum.
const Vector3D & operator*=(double a)
In-place scale.
const Vector3D & operator-=(const Vector3D &v)
In-place subtract.
Vector3D operator-(const Vector3D &v) const
Difference.
std::string StringFormat(const char *format,...)
printf into a std::string.
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...
bool MathClasses_UnitTest()
Unit test for the MathClasses module (geometry / vectors / boxes).