ZLayout EDA Library v1.0.0
Advanced Electronic Design Automation Layout Library with Bilingual Documentation
Loading...
Searching...
No Matches
point.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8#include <cmath>
9#include <iostream>
10#include <functional>
11
12namespace zlayout {
13namespace geometry {
14
23class Point {
24public:
25 double x;
26 double y;
27
29 static constexpr double TOLERANCE = 1e-10;
30
34 Point() : x(0.0), y(0.0) {}
35
41 Point(double x, double y) : x(x), y(y) {}
42
46 Point(const Point& other) = default;
47
51 Point& operator=(const Point& other) = default;
52
58 bool operator==(const Point& other) const;
59
63 bool operator!=(const Point& other) const;
64
68 Point operator+(const Point& other) const;
69
73 Point operator-(const Point& other) const;
74
78 Point operator*(double scalar) const;
79
83 Point operator/(double scalar) const;
84
88 Point& operator+=(const Point& other);
89
93 Point& operator-=(const Point& other);
94
100 double distance_to(const Point& other) const;
101
107 double distance_squared_to(const Point& other) const;
108
115 double distance_to_line(const Point& line_start, const Point& line_end) const;
116
122 double dot(const Point& other) const;
123
129 double cross(const Point& other) const;
130
135 double magnitude() const;
136
141 double magnitude_squared() const;
142
147 Point normalize() const;
148
154 Point rotate(double angle) const;
155
162 Point rotate_around(const Point& center, double angle) const;
163
169 double angle_to(const Point& other) const;
170
175 bool is_zero() const;
176
181 std::string to_string() const;
182
186 friend std::ostream& operator<<(std::ostream& os, const Point& point);
187};
188
192struct PointHash {
193 std::size_t operator()(const Point& point) const;
194};
195
202double distance(const Point& p1, const Point& p2);
203
210Point midpoint(const Point& p1, const Point& p2);
211
219double angle_between_points(const Point& p1, const Point& p2, const Point& p3);
220
228bool are_collinear(const Point& p1, const Point& p2, const Point& p3);
229
237int orientation(const Point& p1, const Point& p2, const Point& p3);
238
239} // namespace geometry
240} // namespace zlayout
2D point with high-precision coordinates and utility methods
Definition point.hpp:23
bool operator==(const Point &other) const
Equality operator with tolerance.
Definition point.cpp:16
double cross(const Point &other) const
Calculate cross product magnitude (2D cross product)
Definition point.cpp:97
Point & operator=(const Point &other)=default
Assignment operator.
Point normalize() const
Normalize vector to unit length.
Definition point.cpp:109
double x
X coordinate.
Definition point.hpp:25
std::string to_string() const
Get string representation.
Definition point.cpp:138
double magnitude() const
Calculate vector magnitude (length)
Definition point.cpp:101
Point & operator+=(const Point &other)
Addition assignment.
Definition point.cpp:44
Point operator/(double scalar) const
Scalar division.
Definition point.cpp:37
double distance_squared_to(const Point &other) const
Calculate squared distance (faster, avoids sqrt)
Definition point.cpp:62
Point operator-(const Point &other) const
Subtraction operator.
Definition point.cpp:29
double distance_to_line(const Point &line_start, const Point &line_end) const
Calculate distance from this point to a line segment.
Definition point.cpp:68
Point rotate_around(const Point &center, double angle) const
Rotate point around another point by angle (radians)
Definition point.cpp:123
friend std::ostream & operator<<(std::ostream &os, const Point &point)
Stream output operator.
Definition point.cpp:144
Point & operator-=(const Point &other)
Subtraction assignment.
Definition point.cpp:50
Point rotate(double angle) const
Rotate point around origin by angle (radians)
Definition point.cpp:117
static constexpr double TOLERANCE
Default precision tolerance for floating point comparisons.
Definition point.hpp:29
Point(double x, double y)
Constructor with coordinates.
Definition point.hpp:41
bool operator!=(const Point &other) const
Inequality operator.
Definition point.cpp:21
double magnitude_squared() const
Calculate squared magnitude (faster, avoids sqrt)
Definition point.cpp:105
double dot(const Point &other) const
Calculate dot product with another point (as vector)
Definition point.cpp:93
double angle_to(const Point &other) const
Calculate angle from this point to another (radians)
Definition point.cpp:129
double y
Y coordinate.
Definition point.hpp:26
Point(const Point &other)=default
Copy constructor.
Point operator+(const Point &other) const
Addition operator.
Definition point.cpp:25
double distance_to(const Point &other) const
Calculate Euclidean distance to another point.
Definition point.cpp:56
Point()
Default constructor - creates point at origin.
Definition point.hpp:34
Point operator*(double scalar) const
Scalar multiplication.
Definition point.cpp:33
bool is_zero() const
Check if point is approximately zero.
Definition point.cpp:134
Point midpoint(const Point &p1, const Point &p2)
Calculate midpoint between two points.
Definition point.cpp:165
int orientation(const Point &p1, const Point &p2, const Point &p3)
Calculate orientation of three points.
Definition point.cpp:198
double distance(const Point &p1, const Point &p2)
Calculate distance between two points.
Definition point.cpp:161
bool are_collinear(const Point &p1, const Point &p2, const Point &p3)
Check if three points are collinear.
Definition point.cpp:190
double angle_between_points(const Point &p1, const Point &p2, const Point &p3)
Calculate angle between three points (p1-p2-p3)
Definition point.cpp:169
Main namespace for ZLayout library.
Definition component.hpp:20
Hash function for Point (for use in std::unordered_map, etc.)
Definition point.hpp:192
std::size_t operator()(const Point &point) const
Definition point.cpp:151