11#ifndef JAU_GAMP_GRAPH_VERTEXMATH_HPP_
12#define JAU_GAMP_GRAPH_VERTEXMATH_HPP_
31 using namespace jau::math;
33 using jau::math::geom::AABBox3f;
34 using jau::math::geom::plane::AffineTransform;
53 size_t n = vertices.size();
55 for (
size_t p = n - 1, q = 0; q < n; p = q++) {
56 const Vec3f& pCoord = vertices[p].coord();
57 const Vec3f& qCoord = vertices[q].coord();
58 area += (double)pCoord.
x * (
double)qCoord.
y - (double)qCoord.
x * (
double)pCoord.
y;
76 return area2D(vertices) >= 0 ? Winding::CCW : Winding::CW ;
80 static ssize_t
cmod(ssize_t i, ssize_t count)
noexcept {
101 const ssize_t polysz =
static_cast<ssize_t
>(polyline.size());
103 return shortIsConvex;
105 constexpr float eps = std::numeric_limits<float>::epsilon();
123 }
while( !v0.
onCurve() && offset < polysz );
124 if( offset >= polysz ) {
125 return shortIsConvex;
130 }
while( !v1.
onCurve() && offset < polysz );
131 if( offset >= polysz ) {
132 return shortIsConvex;
136 while( offset < polysz ) {
142 }
while( !v1.
onCurve() && offset < polysz );
143 if( offset >= polysz ) {
160 }
else if( xSign < 0 ) {
164 }
else if( ax < -eps ) {
167 }
else if ( xSign > 0 ) {
179 }
else if( ySign < 0 ) {
183 }
else if( ay < -eps ) {
186 }
else if( ySign > 0 ) {
197 const float w = bx*ay - ax*by;
200 }
else if( wSign > eps && w < -eps ) {
202 }
else if( wSign < -eps && w > eps ) {
208 if( xSign != 0 && xFirstSign != 0 && xSign != xFirstSign ) {
211 if( ySign != 0 && yFirstSign != 0 && ySign != yFirstSign ) {
216 if( xFlips != 2 || yFlips != 2 ) {
constexpr const Vec3f & coord() const noexcept
constexpr bool onCurve() const noexcept
std::enable_if_t< std::is_floating_point_v< T >, bool > constexpr 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.
jau::darray< Vertex, uint32_t > VertexList
static 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 Winding getWinding(const VertexList &vertices) noexcept
Compute the winding using the area2D() function over all vertices for complex shapes.
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
constexpr double area2D(const Vec3fList &vertices) noexcept
Computes the area of a list of vertices via shoelace formula.
constexpr bool testTri2SegIntersection2D(const Vec3f &a, const Vec3f &b, const Vec3f &c, const Vec3f &d, const Vec3f &e)
Check if a segment intersects with a triangle using FloatUtil#EPSILON w/o considering collinear-case.
static ssize_t cmod(ssize_t i, ssize_t count) noexcept