Revision: 73876
          http://sourceforge.net/p/brlcad/code/73876
Author:   starseeker
Date:     2019-09-10 15:12:14 +0000 (Tue, 10 Sep 2019)
Log Message:
-----------
Expose the ability to create a libbg style polygon - it's looking like we'll 
need to use it.

Modified Paths:
--------------
    brlcad/trunk/src/libbrep/cdt_mesh.cpp
    brlcad/trunk/src/libbrep/cdt_mesh.h

Modified: brlcad/trunk/src/libbrep/cdt_mesh.cpp
===================================================================
--- brlcad/trunk/src/libbrep/cdt_mesh.cpp       2019-09-10 14:58:23 UTC (rev 
73875)
+++ brlcad/trunk/src/libbrep/cdt_mesh.cpp       2019-09-10 15:12:14 UTC (rev 
73876)
@@ -758,25 +758,19 @@
     return true;
 }
 
-bool
-cpolygon_t::point_in_polygon(long v, bool flip)
+long
+cpolygon_t::bg_polygon(point2d_t **ppnts)
 {
-    if (v == -1) return false;
-    if (!closed()) return false;
+    if (!closed()) return -1;
 
     point2d_t *polypnts = (point2d_t *)bu_calloc(poly.size()+1, 
sizeof(point2d_t), "polyline");
 
-    size_t pind = 0;
+    long pind = 0;
 
     cpolyedge_t *pe = (*poly.begin());
     cpolyedge_t *first = pe;
     cpolyedge_t *next = pe->next;
 
-    if (v == pe->v[0] || v == pe->v[1]) {
-       bu_free(polypnts, "polyline");
-       return false;
-    }
-
     V2SET(polypnts[pind], pnts_2d[pe->v[0]].first, pnts_2d[pe->v[0]].second);
     pind++;
     V2SET(polypnts[pind], pnts_2d[pe->v[1]].first, pnts_2d[pe->v[1]].second);
@@ -784,14 +778,35 @@
     // Walk the loop
     while (first != next) {
        pind++;
-       if (v == next->v[0] || v == next->v[1]) {
-           bu_free(polypnts, "polyline");
-           return false;
-       }
        V2SET(polypnts[pind], pnts_2d[next->v[1]].first, 
pnts_2d[next->v[1]].second);
        next = next->next;
+       if ((size_t)pind > poly.size()+1) {
+           std::cout << "\nERROR infinite loop\n";
+           bu_free(polypnts, "free polypnts");
+           return -1;
+       }
     }
 
+    (*ppnts) = polypnts;
+
+    return pind;
+}
+
+bool
+cpolygon_t::point_in_polygon(long v, bool flip)
+{
+    if (v == -1) return false;
+    if (!closed()) return false;
+
+    cpolyedge_t *pe = (*poly.begin());
+    if (v == pe->v[0] || v == pe->v[1]) {
+       return -1;
+    }
+
+    point2d_t *polypnts = NULL;
+    long pind = bg_polygon(&polypnts);
+    if (pind < 0) return false;
+
 #if 0
     if (bg_polygon_direction(pind+1, pnts_2d, NULL) == BG_CCW) {
        point2d_t *rpolypnts = (point2d_t *)bu_calloc(poly.size()+1, 
sizeof(point2d_t), "polyline");

Modified: brlcad/trunk/src/libbrep/cdt_mesh.h
===================================================================
--- brlcad/trunk/src/libbrep/cdt_mesh.h 2019-09-10 14:58:23 UTC (rev 73875)
+++ brlcad/trunk/src/libbrep/cdt_mesh.h 2019-09-10 15:12:14 UTC (rev 73876)
@@ -351,6 +351,9 @@
        bool closed();
        bool self_intersecting();
 
+       /* Return a libbg style polygon container */
+       long bg_polygon(point2d_t **ppnts);
+
        /* Test if a point is inside the polygon.  Supplying flip=true will 
instead
         * report if the point is outside the polygon.
         * TODO - document what it does if it's ON the polygon...*/

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to