11#ifndef JAU_GAMP_GRAPH_IMPL_VERTEXMATH_HPP_
12#define JAU_GAMP_GRAPH_IMPL_VERTEXMATH_HPP_
51 size_t n = vertices.size();
53 for (
size_t p = n - 1, q = 0; q < n; p = q++) {
54 const Vec3f& pCoord = vertices[p].coord();
55 const Vec3f& qCoord = vertices[q].coord();
56 area += (double)pCoord.
x * (
double)qCoord.
y - (double)qCoord.
x * (
double)pCoord.
y;
74 return area2D(vertices) >= 0 ? Winding::CCW : Winding::CW ;
89 auto cmod = [](ssize_t i, ssize_t count)
noexcept -> ssize_t {
96 const ssize_t polysz =
static_cast<ssize_t
>(polyline.size());
100 constexpr float eps = std::numeric_limits<float>::epsilon();
117 v0 = polyline[cmod(offset, polysz)];
118 }
while( !v0.
onCurve() && offset < polysz );
119 if( offset >= polysz ) {
120 return shortIsConvex;
124 v1 = polyline[cmod(offset, polysz)];
125 }
while( !v1.
onCurve() && offset < polysz );
126 if( offset >= polysz ) {
127 return shortIsConvex;
131 while( offset < polysz ) {
136 v1 = polyline[cmod(offset, polysz)];
137 }
while( !v1.
onCurve() && offset < polysz );
138 if( offset >= polysz ) {
155 }
else if( xSign < 0 ) {
159 }
else if( ax < -eps ) {
162 }
else if ( xSign > 0 ) {
174 }
else if( ySign < 0 ) {
178 }
else if( ay < -eps ) {
181 }
else if( ySign > 0 ) {
192 const float w = bx*ay - ax*by;
195 }
else if( wSign > eps && w < -eps ) {
197 }
else if( wSign < -eps && w > eps ) {
203 if( xSign != 0 && xFirstSign != 0 && xSign != xFirstSign ) {
206 if( ySign != 0 && yFirstSign != 0 && ySign != yFirstSign ) {
211 if( xFlips != 2 || yFlips != 2 ) {
constexpr const Vec3f & coord() const noexcept
constexpr bool onCurve() const noexcept
constexpr bool is_zero(const T &a, const T &epsilon=std::numeric_limits< T >::epsilon()) noexcept
Returns true if the given value is less than epsilon, w/ epsilon > 0.
static constexpr bool isConvex1(const VertexList &polyline, bool shortIsConvex) noexcept
Returns whether the given on-curve polyline points denotes a convex shape with O(n) complexity.
constexpr bool testTri2SegIntersection2D(const Vertex &a, const Vertex &b, const Vertex &c, const Vertex &d, const Vertex &e)
Check if a segment intersects with a triangle using FloatUtil#EPSILON w/o considering collinear-case.
constexpr double area2D(const VertexList &vertices) noexcept
Computes the area of a list of vertices via shoelace formula.
constexpr Winding getWinding(const VertexList &vertices) noexcept
Compute the winding using the area2D() function over all vertices for complex shapes.
jau::darray< Vertex, uint32_t > VertexList
constexpr bool testSeg2SegIntersection2D(Vec2f *result, const Vec2f &p, const Vec2f &p2, const Vec2f &q, const Vec2f &q2, const bool do_collinear=false) noexcept
See p + t r = q + u s and its terse C# implementation