13inline constexpr double pi = 3.141592653589793238462643383279502884;
20class Text :
public std::string
23 using std::string::string;
29 Text(
const std::string &v) : std::string(v) {};
41 template <
class T>
Text arg(
const T &value)
const
43 std::ostringstream out;
46 std::size_t at = std::string::npos;
48 for (std::size_t i = 0; i + 1 < size(); ++i)
49 if ((*
this)[i] ==
'%' && (*
this)[i + 1] >=
'1' && (*
this)[i + 1] <=
'9') {
50 int n = (*this)[i + 1] -
'0';
56 if (at != std::string::npos) {
57 const auto key =
"%" + std::to_string(lowest);
59 while ((p = result.find(key, p)) != std::string::npos) {
60 result.replace(p, key.size(), out.str());
61 p += out.str().size();
72 template <
class T,
class U>
Text arg(
const T &a,
const U &b)
const {
return arg(a).
arg(b); }
106 double x0 = front().x(), x1 = x0, y0 = front().y(), y1 = y0;
107 for (
auto p : *
this) {
108 x0 = std::min(x0, p.x());
109 x1 = std::max(x1, p.x());
110 y0 = std::min(y0, p.y());
111 y1 = std::max(y1, p.y());
113 return {{x0, y0}, {x1, y1}};
130 double length()
const {
return std::hypot(
b.x() -
a.x(),
b.y() -
a.y()); }
166 int vertex(
int k)
const {
return k == 0 ?
v0 : k == 1 ?
v1 : k == 2 ?
v2 : k == 3 ?
v3 : -1; }
210 const void *owner_ =
nullptr;
211 T (*read_)(
const void *, std::size_t) =
nullptr;
212 std::ptrdiff_t count_ = 0;
224 void borrow(
const void *owner, std::ptrdiff_t count, T (*read)(
const void *, std::size_t))
326 for (
int i = 0; i < 4; ++i) {
327 auto a = v[c.
vertex(i)].xy, b = v[c.
vertex((i + 1) % 4)].xy,
328 d = v[c.
vertex((i + 2) % 4)].xy;
329 auto ab = b - a, bd = d - b;
330 double turn = ab.x() * bd.y() - ab.y() * bd.x();
331 if (!std::isfinite(turn) || turn == 0 || (before && (turn > 0) != (before > 0)))
Axis-aligned rectangle in the XY plane, stored as an origin corner and a signed size.
Definition geometry.hpp:167
Point or displacement vector in the horizontal (XY) plane.
Definition geometry.hpp:21
std::vector<T> with the QVector-style member names the CDT kernel and plan model use.
Definition storage.hpp:31
Vector()=default
Empty vector.
Polygon(const Vector< Point2 > &v)
Copy a point vector.
Definition planmodel.hpp:91
Polygon(const std::vector< Point2 > &v)
Copy a std::vector of points.
Definition planmodel.hpp:96
Box2 boundingRect() const
Axis-aligned bounding box of all points.
Definition planmodel.hpp:102
Read-only array that either owns its elements or reads them from borrowed storage.
Definition planmodel.hpp:209
T operator[](std::size_t i) const
Element i, from the borrowed storage or the owned elements.
Definition planmodel.hpp:239
void borrow(const void *owner, std::ptrdiff_t count, T(*read)(const void *, std::size_t))
View external storage instead of the owned elements, which are left unchanged.
Definition planmodel.hpp:224
Iterator end() const
Iterator at index size().
Definition planmodel.hpp:271
bool isEmpty() const
Return true when size() is 0.
Definition planmodel.hpp:233
std::ptrdiff_t size() const
Borrowed count while borrowing, otherwise the owned element count.
Definition planmodel.hpp:231
Iterator begin() const
Iterator at index 0.
Definition planmodel.hpp:269
Owned byte string with the QString-style helpers used for tags and diagnostics.
Definition planmodel.hpp:21
Text(const std::string &v)
Copy a std::string; also serves as an implicit conversion.
Definition planmodel.hpp:29
Text arg(const T &a, const U &b) const
Substitute two values in turn; exactly arg(a).arg(b).
Definition planmodel.hpp:72
Text arg(const T &value) const
Replace the lowest-numbered %1..%9 placeholder with a formatted value.
Definition planmodel.hpp:41
bool isEmpty() const
Return true when the string holds no characters.
Definition planmodel.hpp:31
std::ptrdiff_t size() const noexcept
Number of elements as a signed std::ptrdiff_t.
Definition storage.hpp:107
Planning algorithms on standard containers: quad patch planning and placement, size fields,...
constexpr double pi
The constant pi as a double.
Definition planmodel.hpp:13
bool cellIsConvex(const Vector< MeshVertex > &v, const MeshTriangle &c)
Test whether a cell is a strictly convex quadrilateral; triangles always pass.
Definition planmodel.hpp:321
std::string Bytes
Raw byte buffer held in a std::string; the planner uses it for exact binary keys.
Definition planmodel.hpp:75
Constraint polyline with marker, tag and optional strip width.
Definition planmodel.hpp:295
Vector< Point2 > path
Polyline vertices, XY units; each consecutive pair is one segment.
Definition planmodel.hpp:296
double stripWidth
Width (XY units) of a swept quad strip requested along an open path; a value that is not > 0 means a ...
Definition planmodel.hpp:301
int marker
Source marker kept on the generated edges; 0 means none.
Definition planmodel.hpp:297
Text tag
Caller-resolved label for the marker; not interpreted here.
Definition planmodel.hpp:298
double length() const
Euclidean length |b - a| via std::hypot, in XY units; finiteness is not checked.
Definition planmodel.hpp:130
Point2 a
Start point, XY units.
Definition planmodel.hpp:122
Point2 b
End point, XY units.
Definition planmodel.hpp:122
Line2(Point2 x, Point2 y)
Construct the segment from x to y.
Definition planmodel.hpp:128
Mesh edge between two vertex indices, carrying a source marker.
Definition planmodel.hpp:186
int v0
First endpoint index into the owning vertex array.
Definition planmodel.hpp:193
int v1
Second endpoint index into the owning vertex array.
Definition planmodel.hpp:193
int marker
Marker of the source constraint the edge came from; 0 (default) means none.
Definition planmodel.hpp:193
Text tag
Optional label; the native planning and audit code does not read it.
Definition planmodel.hpp:194
Mesh as read by the native audits: vertices, cells, marked edges and a status.
Definition planmodel.hpp:279
bool ok
True for a successful mesh (default false); the constraint audit refuses a mesh with ok false.
Definition planmodel.hpp:286
ReadArray< MeshEdge > boundaryEdges
Constraint and boundary edges with their source markers, indexing vertices.
Definition planmodel.hpp:283
ReadArray< MeshTriangle > triangles
Every cell, triangles and quads, indexing vertices.
Definition planmodel.hpp:281
ReadArray< MeshVertex > vertices
Positions (XY units) and elevations (Z units).
Definition planmodel.hpp:280
Text errorMsg
Failure description that accompanies ok == false.
Definition planmodel.hpp:287
Mesh cell: a triangle, or a quadrilateral when v3 is nonnegative.
Definition planmodel.hpp:144
int vertex(int k) const
Corner index stored in slot k.
Definition planmodel.hpp:166
Text tag
Cell label (for example the patch or region tag); empty when untagged.
Definition planmodel.hpp:155
int v1
Second corner index.
Definition planmodel.hpp:154
bool isQuad() const
Return true when v3 is nonnegative (a quadrilateral); indices are not checked.
Definition planmodel.hpp:157
int v2
Third corner index.
Definition planmodel.hpp:154
int v3
Fourth corner index of a quadrilateral; a negative value (default -1) marks a triangle.
Definition planmodel.hpp:154
int vertexCount() const
Return 4 for a quadrilateral and 3 for a triangle.
Definition planmodel.hpp:159
int v0
First corner index.
Definition planmodel.hpp:154
void setVertex(int k, int v)
Store a corner index in one slot, leaving the other fields unchanged.
Definition planmodel.hpp:173
Mesh vertex: planar position plus elevation.
Definition planmodel.hpp:133
Point2 xy
Planar position, XY units.
Definition planmodel.hpp:134
double z
Elevation, Z units; defaults to 0 (there is no separate "unset" flag).
Definition planmodel.hpp:135
Minimal iterator for range-based for loops: supports only *, prefix ++ and !=, and yields elements by...
Definition planmodel.hpp:247
Iterator & operator++()
Advance to the next index.
Definition planmodel.hpp:256
T operator*() const
Current element, by value.
Definition planmodel.hpp:251
bool operator!=(const Iterator &b) const
Compare positions only.
Definition planmodel.hpp:266
const ReadArray * array
Array being iterated; not owned.
Definition planmodel.hpp:248
std::size_t i
Current element index.
Definition planmodel.hpp:249
Mandatory mesh point with marker, tag and optional pre-sampled elevation.
Definition planmodel.hpp:304
Point2 xy
Position, XY units.
Definition planmodel.hpp:305
bool hasZ
True when z holds a pre-sampled elevation.
Definition planmodel.hpp:311
double z
Elevation in Z units; meaningful only when hasZ is true.
Definition planmodel.hpp:308
int marker
Point marker; 0 means none. The native size field seeds only nonzero ones.
Definition planmodel.hpp:306
Text tag
Caller-resolved label; not interpreted by the native code.
Definition planmodel.hpp:307