11#ifndef JAU_GAMP_GRAPH_IMPL_VERTEXMATH_HPP_
12#define JAU_GAMP_GRAPH_IMPL_VERTEXMATH_HPP_
29namespace gamp::graph::impl {
31 using namespace jau::math;
50 constexpr double area2D(
const VertexList& vertices)
noexcept {
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;
88 constexpr static bool isConvex1(
const VertexList& polyline,
bool shortIsConvex)
noexcept {
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 ) {
143 const float bx = v0.coord().x - vp.coord().x;
144 const float by = v0.coord().y - vp.coord().y;
147 const float ax = v1.coord().x - v0.coord().x;
148 const float ay = v1.coord().y - v0.coord().y;
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 ) {
232 constexpr bool testTri2SegIntersection2D(
const Vertex& a,
const Vertex& b,
const Vertex& c,
233 const Vertex& d,
const Vertex& e) {
234 using namespace jau::math::geom;
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.
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