YODAU 1.0
YEAR OF THE DEPEND ADULT UNDERGARMENT
Loading...
Searching...
No Matches
yodau::backend::line Struct Reference

Polyline / polygon described in percentage coordinates. More...

#include <backend/include/geometry.hpp>

Public Member Functions

void dump (std::ostream &out) const
 Print a human-readable representation of the line.
void normalize ()
 Canonicalize point order.
bool operator== (const line &other) const
 Equality check using canonical point comparison.

Public Attributes

std::string name
 Logical name of the line (e.g., "entrance_tripwire").
std::vector< pointpoints
 Vertex list in percentage coordinates.
bool closed { false }
 Whether the chain is closed.
tripwire_dir dir { tripwire_dir::any }
 Optional tripwire direction constraint.

Detailed Description

Polyline / polygon described in percentage coordinates.

A line can represent:

  • an open polyline (when closed == false),
  • or a closed polygon-like chain (when closed == true).

The points may be reordered by normalize() to provide a canonical representation for equality checks and stable processing.

Definition at line 81 of file geometry.hpp.

Member Function Documentation

◆ dump()

void yodau::backend::line::dump ( std::ostream & out) const

Print a human-readable representation of the line.

Parameters
outOutput stream to write to.

Definition at line 17 of file geometry.cpp.

17 {
18 out << "Line(name=" << name << ", closed=" << (closed ? "true" : "false")
19 << ", points=[";
20 for (size_t i = 0; i < points.size(); i++) {
21 out << "(" << points[i].x << ", " << points[i].y << ")";
22 if (i < points.size() - 1) {
23 out << "; ";
24 }
25 }
26 out << "])";
27}
std::string name
Logical name of the line (e.g., "entrance_tripwire").
Definition geometry.hpp:85
bool closed
Whether the chain is closed.
Definition geometry.hpp:97
std::vector< point > points
Vertex list in percentage coordinates.
Definition geometry.hpp:90

◆ normalize()

void yodau::backend::line::normalize ( )

Canonicalize point order.

Behavior (as per implementation):

  • If closed is true, rotates points so the vertex closest to (0,0) becomes the first element.
  • Then ensures a consistent direction by comparing distances of first/last vertices to a reference point and reversing if needed.
Note
This operation may reorder points but does not change their values.

Definition at line 29 of file geometry.cpp.

29 {
30 const size_t n = points.size();
31 if (n < 2) {
32 return;
33 }
34 constexpr point origin { 0.0f, 0.0f };
35 constexpr point east { 100.0f, 0.0f };
36
37 if (closed) {
38 size_t best_idx = 0;
39 float best_distance = points[0].distance_to(origin);
40
41 for (size_t i = 1; i < n; i++) {
42 float distance = points[i].distance_to(origin);
43 if (distance < best_distance) {
44 best_distance = distance;
45 best_idx = i;
46 }
47 }
48
49 if (best_idx != 0) {
50 const auto it
51 = points.begin() + static_cast<std::ptrdiff_t>(best_idx);
52 std::ranges::rotate(points, it);
53 }
54 }
55
56 const size_t front = closed ? 1 : 0;
57
58 if (n >= 2 + front) {
59 const float first = points[front].distance_to(closed ? east : origin);
60 const float last = points.back().distance_to(closed ? east : origin);
61 if (last < first) {
62 std::reverse(
63 points.begin() + static_cast<std::ptrdiff_t>(front),
64 points.end()
65 );
66 }
67 }
68}

References closed.

◆ operator==()

bool yodau::backend::line::operator== ( const line & other) const

Equality check using canonical point comparison.

Two lines are equal if:

  • their closed flags match,
  • they have the same number of points,
  • and all points compare equal via point::compare.
Note
The name and dir fields are intentionally NOT compared.
Parameters
otherLine to compare with.
Returns
true if geometrically equal within tolerance.

Definition at line 70 of file geometry.cpp.

70 {
71 if (closed != other.closed || points.size() != other.points.size()) {
72 return false;
73 }
74 for (size_t i = 0; i < points.size(); i++) {
75 if (!points[i].compare(other.points[i])) {
76 return false;
77 }
78 }
79 return true;
80}

Member Data Documentation

◆ closed

bool yodau::backend::line::closed { false }

Whether the chain is closed.

If true, the first point is considered connected to the last point.

Definition at line 97 of file geometry.hpp.

97{ false };

Referenced by normalize().

◆ dir

tripwire_dir yodau::backend::line::dir { tripwire_dir::any }

Optional tripwire direction constraint.

Used by line-crossing logic. Defaults to tripwire_dir::any.

Definition at line 104 of file geometry.hpp.

◆ name

std::string yodau::backend::line::name

Logical name of the line (e.g., "entrance_tripwire").

Definition at line 85 of file geometry.hpp.

◆ points

std::vector<point> yodau::backend::line::points

Vertex list in percentage coordinates.

Definition at line 90 of file geometry.hpp.


The documentation for this struct was generated from the following files: