22 return !(*
this == other);
34 return Point(
x * scalar,
y * scalar);
39 throw std::invalid_argument(
"Division by zero in Point::operator/");
41 return Point(
x / scalar,
y / scalar);
57 double dx =
x - other.
x;
58 double dy =
y - other.
y;
59 return std::sqrt(dx * dx + dy * dy);
63 double dx =
x - other.
x;
64 double dy =
y - other.
y;
65 return dx * dx + dy * dy;
70 Point line_vec = line_end - line_start;
79 Point point_vec = *
this - line_start;
82 double t = point_vec.
dot(line_vec) / line_length_sq;
85 t = std::max(0.0, std::min(1.0, t));
88 Point closest = line_start + line_vec * t;
94 return x * other.
x +
y * other.
y;
98 return x * other.
y -
y * other.
x;
102 return std::sqrt(
x *
x +
y *
y);
106 return x *
x +
y *
y;
112 return Point(0.0, 0.0);
114 return Point(
x / mag,
y / mag);
118 double cos_a = std::cos(angle);
119 double sin_a = std::sin(angle);
120 return Point(
x * cos_a -
y * sin_a,
x * sin_a +
y * cos_a);
124 Point translated = *
this - center;
126 return rotated + center;
130 Point vec = other - *
this;
131 return std::atan2(vec.
y, vec.
x);
139 std::ostringstream oss;
140 oss << std::fixed << std::setprecision(6) <<
"Point(" <<
x <<
", " <<
y <<
")";
153 std::hash<double> hasher;
156 return h1 ^ (h2 << 1);
166 return Point((p1.
x + p2.
x) * 0.5, (p1.
y + p2.
y) * 0.5);
175 double dot_product = v1.
dot(v2);
183 double cos_angle = dot_product / (mag1 * mag2);
185 cos_angle = std::max(-1.0, std::min(1.0, cos_angle));
187 return std::acos(cos_angle);
194 double cross_product = v1.
cross(v2);
202 double cross_product = v1.
cross(v2);
207 return (cross_product > 0) ? 1 : 2;
2D point with high-precision coordinates and utility methods
bool operator==(const Point &other) const
Equality operator with tolerance.
double cross(const Point &other) const
Calculate cross product magnitude (2D cross product)
Point normalize() const
Normalize vector to unit length.
std::string to_string() const
Get string representation.
double magnitude() const
Calculate vector magnitude (length)
Point & operator+=(const Point &other)
Addition assignment.
Point operator/(double scalar) const
Scalar division.
double distance_squared_to(const Point &other) const
Calculate squared distance (faster, avoids sqrt)
Point operator-(const Point &other) const
Subtraction operator.
double distance_to_line(const Point &line_start, const Point &line_end) const
Calculate distance from this point to a line segment.
Point rotate_around(const Point ¢er, double angle) const
Rotate point around another point by angle (radians)
Point & operator-=(const Point &other)
Subtraction assignment.
Point rotate(double angle) const
Rotate point around origin by angle (radians)
static constexpr double TOLERANCE
Default precision tolerance for floating point comparisons.
bool operator!=(const Point &other) const
Inequality operator.
double magnitude_squared() const
Calculate squared magnitude (faster, avoids sqrt)
double dot(const Point &other) const
Calculate dot product with another point (as vector)
double angle_to(const Point &other) const
Calculate angle from this point to another (radians)
Point operator+(const Point &other) const
Addition operator.
double distance_to(const Point &other) const
Calculate Euclidean distance to another point.
Point()
Default constructor - creates point at origin.
Point operator*(double scalar) const
Scalar multiplication.
bool is_zero() const
Check if point is approximately zero.
std::ostream & operator<<(std::ostream &os, const Point &point)
Point midpoint(const Point &p1, const Point &p2)
Calculate midpoint between two points.
int orientation(const Point &p1, const Point &p2, const Point &p3)
Calculate orientation of three points.
double distance(const Point &p1, const Point &p2)
Calculate distance between two points.
bool are_collinear(const Point &p1, const Point &p2, const Point &p3)
Check if three points are collinear.
double angle_between_points(const Point &p1, const Point &p2, const Point &p3)
Calculate angle between three points (p1-p2-p3)
Main namespace for ZLayout library.
2D Point class for geometric calculations
std::size_t operator()(const Point &point) const