1 #ifndef SLAM_CTOR_CORE_GEOMETRY_DISCRETE_PRIMITIVES_H 2 #define SLAM_CTOR_CORE_GEOMETRY_DISCRETE_PRIMITIVES_H 15 : x{x_coord}, y{y_coord} {}
28 return {x - p.
x, y - p.
y};
32 return x == p.
x && y == p.
y;
44 return std::pow(x - pt.
x, 2) + std::pow(y - pt.
y, 2);
50 return stream <<
"(" << pnt.
x <<
", " << pnt.
y <<
")";
60 _points.reserve(std::fabs(beg.
x - end.
x) + std::fabs(beg.
y - end.
y) + 1);
61 gen_points_with_bresenham(beg, end);
63 operator auto()
const {
return _points; }
70 bool y_is_primary = std::abs(delta.
x) < std::abs(delta.
y);
72 int limit, primary, d_primary, secondary, d_secondary;
73 std::tie(limit, primary, d_primary, secondary, d_secondary) = y_is_primary ?
74 std::make_tuple(end.
y, beg.y, delta.
y, beg.x, delta.
x) :
75 std::make_tuple(end.
x, beg.x, delta.
x, beg.y, delta.
y);
77 int inc_primary = 0 < d_primary ? 1 : -1;
78 int inc_secondary = 0 < d_secondary ? 1 : -1;
79 int *
x =
nullptr, *
y =
nullptr;
80 std::tie(x,
y) = y_is_primary ? std::make_tuple(&secondary, &primary) :
81 std::make_tuple(&primary, &secondary);
86 _points.emplace_back(*x, *
y);
87 if (primary == limit) {
break; }
89 int err_inc_primary = error + inc_primary * d_secondary;
90 int err_inc_both = err_inc_primary - inc_secondary * d_primary;
92 primary += inc_primary;
93 if (std::abs(err_inc_primary) < std::abs(err_inc_both)) {
94 error = err_inc_primary;
96 secondary += inc_secondary;
DiscretePoint2D operator+(const DiscretePoint2D &p) const
double dist_sq(const DiscretePoint2D &pt) const
void gen_points_with_bresenham(const DPoint &beg, const DPoint &end)
DiscretePoint2D operator-() const
DiscretePoint2D operator-(const DiscretePoint2D &p) const
std::ostream & operator<<(std::ostream &stream, const DiscretePoint2D &pnt)
DiscreteSegment2D(const DPoint &beg, const DPoint &end)
constexpr DiscretePoint2D(int x_coord=0, int y_coord=0)
DiscretePoint2D & operator+=(const DiscretePoint2D &p)
std::vector< DPoint > _points
bool operator!=(const DiscretePoint2D &p) const
bool operator==(const DiscretePoint2D &p) const