Img2Num C++ (Internal Developer Docs) dev
API Documentation
Loading...
Searching...
No Matches
Point.h
1#ifndef POINT_H
2#define POINT_H
3
4// will start as integer values but can be adjusted to subpixel positions
5struct Point {
6 float x = 0;
7 float y = 0;
8
9 Point operator+(const Point &other) const {
10 return Point{x + other.x, y + other.y};
11 }
12
13 // Overload the - operator (subtraction)
14 Point operator-(const Point &other) const {
15 return Point{x - other.x, y - other.y};
16 }
17
18 // Overload the * operator (multiplication by a scalar)
19 // The left operand is the class object (this), the right is a double.
20 Point operator*(float scalar) const {
21 return Point{x * scalar, y * scalar};
22 }
23
24 Point operator/(float scalar) const {
25 return Point{x / scalar, y / scalar};
26 }
27
28 // Friend function to allow float * Vector
29 friend Point operator*(float scalar, const Point &v) {
30 return Point{v.x * scalar, v.y * scalar};
31 ; // Calls the member function for the actual logic
32 }
33
34 Point &operator+=(const Point &other) {
35 x += other.x;
36 y += other.y;
37 return *this;
38 }
39
40 static float distSq(Point a, Point b) {
41 return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
42 }
43};
44
45#endif
Definition Point.h:5