11#include "ZXAlgorithms.h"
31 using Base = std::array<T, 4>;
53 if (centerLine ==
Point{})
55 auto centerLineF = normalized(centerLine);
56 return std::atan2(centerLineF.y, centerLineF.x);
67 for (
const auto& p : points)
68 res += std::to_string(p.x) +
"x" + std::to_string(p.y) + (&p == &points.back() ?
"" :
" ");
74template <
typename Po
intT = Po
intF>
75Quadrilateral<PointT> Rectangle(
int width,
int height,
typename PointT::value_t margin = 0)
78 PointT{margin, margin}, {width - margin, margin}, {width - margin, height - margin}, {margin, height - margin}};
81template <
typename Po
intT = Po
intF>
84 return {
PointT{x0 + o, y0 + o}, {x1 + o, y0 + o}, {x1 + o, y1 + o}, {x0 + o, y1 + o}};
87template <
typename Po
intT = Po
intF>
90 int right = left + width - 1;
91 int bottom = top + height - 1;
93 return {
PointT{left, top}, {right, top}, {right, bottom}, {left, bottom}};
96template <
typename Po
intT = Po
intF>
102template <
typename Po
intT = Po
intI>
105 return {
PointT{xStart, y}, {xStop, y}, {xStop, y}, {xStart, y}};
108template <
typename Po
intT>
111 const int N = Size(poly);
116 for(
int i = 0; i < N; i++)
118 auto d1 = poly[(i + 2) % N] - poly[(i + 1) % N];
119 auto d2 = poly[i] - poly[(i + 1) % N];
120 auto cp = cross(d1, d2);
124 UpdateMinMax(m, M, std::fabs(cp));
128 else if (sign != (cp > 0))
142template <
typename Po
intT>
145 return {factor * q[0], factor * q[1], factor * q[2], factor * q[3]};
148template <
typename Po
intT>
151 return Reduce(q) / Size(q);
154template <
typename Po
intT>
158 std::rotate_copy(q.begin(), q.begin() + ((n + 4) % 4), q.end(), res.begin());
160 std::swap(res[1], res[3]);
164template <
typename Po
intT>
168 int pos = 0, neg = 0;
169 for (
int i = 0; i < Size(q); ++i)
170 (cross(p - q[i], q[(i + 1) % Size(q)] - q[i]) < 0 ? neg : pos)++;
171 return pos == 0 || neg == 0;
174template <
typename Po
intT>
177 auto [minX, maxX] = std::minmax({q[0].x, q[1].x, q[2].x, q[3].x});
178 auto [minY, maxY] = std::minmax({q[0].y, q[1].y, q[2].y, q[3].y});
179 return {
PointT{minX, minY}, {maxX, minY}, {maxX, maxY}, {minX, maxY}};
182template <
typename Po
intT>
185 auto bba = BoundingBox(a), bbb = BoundingBox(b);
187 bool x = bbb.topRight().x < bba.topLeft().x || bbb.topLeft().x > bba.topRight().x;
188 bool y = bbb.bottomLeft().y < bba.topLeft().y || bbb.topLeft().y > bba.bottomLeft().y;
192template <
typename Po
intT>
195 auto dist2First = [r = a[0]](
auto s,
auto t) {
return distance(s, r) < distance(t, r); };
197 auto offset = std::min_element(b.begin(), b.end(), dist2First) - b.begin();
200 for (
int i = 0; i < 4; ++i)
201 res[i] = (a[i] + b[(i + offset) % 4]) / 2;
A simple class representing a quadrilateral defined by its four corner points.
Definition Quadrilateral.h:30
double orientation() const
Definition Quadrilateral.h:50
constexpr Point topRight() const noexcept
Definition Quadrilateral.h:44
T Point
Definition Quadrilateral.h:34
Quadrilateral(T tl, T tr, T br, T bl)
Definition Quadrilateral.h:37
constexpr Point bottomLeft() const noexcept
Definition Quadrilateral.h:46
constexpr Point bottomRight() const noexcept
Definition Quadrilateral.h:45
constexpr Point topLeft() const noexcept
Definition Quadrilateral.h:43
Quadrilateral(PointT< U > tl, PointT< U > tr, PointT< U > br, PointT< U > bl)
Definition Quadrilateral.h:39
Quadrilateral< PointI > QuadrilateralI
Definition Quadrilateral.h:61
Quadrilateral< PointF > QuadrilateralF
Definition Quadrilateral.h:60
std::string ToString(BarcodeFormat format)
A simple 2D point class template.
Definition Point.h:21
T value_t
Definition Point.h:22