66 std::vector<double> &tvalues, std::vector<Pt3d> &a_pts,
double a_tol)
87 for (
size_t i = 1; i <
m_d->
m_ixs.size() - 1; ++i)
96 for (
size_t i =
m_d->
m_ixs.size() - 2; i > 0; --i)
121 oldTValues.reserve(
m_d->
m_ixs.size());
122 for (
size_t i = 0; i <
m_d->
m_ixs.size(); ++i)
124 oldTValues.push_back(
m_d->
m_ixs[i].m_t);
134 for (
size_t i = 0; i < tChange.size() - 1; ++i)
136 if (tChange[i + 1] - tChange[i] > 1)
141 if ((i > 0 && i + 2 < tChange.size()) || inNeither.size() > 1 ||
142 (i == 0 && tChange[1] - tChange[0] > 1))
144 toRemove.insert(toRemove.end(), inNeither.begin(), inNeither.end());
152 for (
size_t i = 0; i <
m_d->
m_ixs.size(); ++i)
158 for (
size_t i = toRemove.size(); i-- > 0;)
176 for (
size_t i = 0; i < tChange.size() - 1; ++i) {
177 if (tChange[i + 1] - tChange[i] > 1) {
183 if (inNext.size() > 1) {
194 for (
size_t j = 0; j < inNext.size() && !found; ++j) {
196 int edgeBeg = inNext[j];
198 for (
size_t k = 0; k < inPrev.size() && edgeEnd ==
XM_NONE; ++k) {
204 int polyIdx =
m_d->
m_ixs[edgeBeg].m_i - 1;
207 for (
size_t k = 0; k <
m_d->
m_polys[polyIdx].size(); ++k) {
212 m_d->
m_ixs[edgeEnd].m_pt, centroid);
214 toRemove.push_back(edgeBeg);
215 toRemove.push_back(edgeEnd);
224 std::sort(toRemove.begin(), toRemove.end());
225 for (
size_t i = toRemove.size(); i-- > 0;) {
256 for (; i < (int)
m_d->
m_ixs.size(); ++i) {
277 int begin = a_tChange[0];
278 int end = a_tChange[1];
279 for (
int i = begin; i < end; ++i)
288 int begin = a_tChange[a_tChange.size() - 2];
289 int end = a_tChange.back();
290 for (
int i = begin; i < end; ++i)
304 VecInt &polyids,
VecDbl &tvalues, std::vector<Pt3d> &a_pts)
const {
335 std::vector<Pt3d> &a_pts)
const {
342 SetInt setIds, setIdsPrev;
344 for (
int i = 0; i < (int)tChange.size() - 1; ++i) {
345 if (tChange[i + 1] - tChange[i] > 1) {
346 VecInt inPrev, inNext, inNeither;
351 if (inPrev.empty() && inNeither.empty())
355 for (
size_t j = 0; j < inNeither.size(); ++j) {
356 setIds.insert(
m_d->
m_ixs[inNeither[j]].m_i);
363 for (
size_t j = 0; j < inPrev.size(); ++j) {
364 if (setIdsPrev.find(
m_d->
m_ixs[inPrev[j]].m_i) == setIdsPrev.end()) {
365 setIds.insert(
m_d->
m_ixs[inPrev[j]].m_i);
371 if (setIds.empty()) {
374 for (
size_t j = 0; j < inNext.size(); ++j) {
375 if (setIdsPrev.find(
m_d->
m_ixs[inNext[j]].m_i) ==
377 setIds.insert(
m_d->
m_ixs[inNext[j]].m_i);
385 for (
size_t j = 0; j < inNeither.size(); ++j) {
386 setIds.insert(
m_d->
m_ixs[inNeither[j]].m_i);
391 if (setIds.empty()) {
393 for (
size_t j = 0; j < inPrev.size(); ++j) {
394 setIds.insert(
m_d->
m_ixs[inPrev[j]].m_i);
401 setIds.insert(
m_d->
m_ixs[tChange[i]].m_i);
417 VecInt &polyids,
VecDbl &tvalues, std::vector<Pt3d> &a_pts)
const {
426 polyids.push_back(
m_d->
m_ixs[0].m_i);
427 tvalues.push_back(
m_d->
m_ixs[0].m_t);
428 a_pts.push_back(
m_d->
m_ixs[0].m_pt);
455 if (polyids.size() == 1) {
457 polyids.push_back(polyids.back());
458 tvalues.push_back(tvalues.back());
459 a_pts.push_back(a_pts.back());
463 if (
m_d->
m_polys2.empty() && polyids.back() != polyids[polyids.size() - 2]) {
464 polyids.push_back(polyids.back());
465 tvalues.push_back(tvalues.back());
466 a_pts.push_back(a_pts.back());
470 if (polyids.size() > 1) {
475 for (
size_t i = 1; i < polyids.size(); ++i) {
476 if (polyids[i] == polyids[i - 1]) {
492 std::vector<Pt3d> &a_pts)
const {
493 polyids.push_back(a_ix.
m_i);
494 tvalues.push_back(a_ix.
m_t);
495 a_pts.push_back(a_ix.
m_pt);
512 VecInt *inNeither)
const {
519 for (
int j = tChange[idx]; j < tChange[idx + 1]; ++j) {
523 bool foundPrev =
false;
525 for (
int k = tChange[idx - 1]; k < tChange[idx] && !foundPrev; ++k) {
535 bool foundNext =
false;
536 if (!foundPrev && idx + 2 < (
int)tChange.size()) {
537 for (
int k = tChange[idx + 1]; k < (int)tChange[idx + 2] && !foundNext;
547 inPrev->push_back(j);
548 }
else if (foundNext) {
550 inNext->push_back(j);
553 inNeither->push_back(j);
573 tChange.assign(1, 0);
574 for (
size_t i = 1; i <
m_d->
m_ixs.size(); ++i) {
576 tChange.push_back((
int)i);
579 tChange.push_back((
int)
m_d->
m_ixs.size());
std::vector< std::vector< int > > m_polys
0-based? indices into m_points to form polygons
void SwapAdjacents()
Swap adjacent identical intersections if necessary.
std::vector< int > VecInt
std::vector< double > VecDbl
GmMultiPolyIntersectorData * m_d
Intersection data from GmMultiPolyIntersector.
bool gmEqualPointsXY(double x1, double y1, double x2, double y2, double tolerance)
Returns true if the points are equal to within gmXyTol().
Turn_enum gmTurn(const Pt3d &a_v1, const Pt3d &a_v2, const Pt3d &a_v3, double a_angtol)
Determine if angle a_v1, a_v2, a_v3 is a left turn, a right turn, colinear 180 degrees, or colinear 0 degrees.
#define XM_ENSURE_TRUE_NO_ASSERT(...)
double m_tol
Tolerance used when comparing t values.
void FindPreviousNextNeither(const std::vector< int > &tChange, const int idx, std::vector< int > *inPrev, std::vector< int > *inNext, std::vector< int > *inNeither) const
Look at each poly in this set of t values and see if it exists in the previous or next set of t value...
An intersection point of a line with a polygon.
std::set< int > m_polys2
polygon IDs (1-based) that 2nd point is inside on on
void RemoveCornerTouches()
Remove polys that only touch the line at a corner. We try to identify these corner polys using the fo...
void FindWhereTValuesChange(std::vector< int > &tChange) const
Mark where we have a change in t values.
Pt3d m_pt
Intersection location.
int m_i
The polygon id (1 based)
void IntersectionsToPolyIdsAndTValuesFor3OrMore(std::vector< int > &polyids, std::vector< double > &tvalues, std::vector< Pt3d > &a_pts) const
Copy intersections to polyids and tvalues when there are 3 or more intersections. ...
void IntersectionsToPolyIdsAndTValuesFor2(std::vector< int > &polyids, std::vector< double > &tvalues, std::vector< Pt3d > &a_pts) const
Copy intersections to polyids and tvalues when there are 2 intersections.
Functions dealing with geometry.
void AddMissingEndpointIds(const std::vector< int > &a_tChange)
Add endpoint polygon IDs that may be removed as duplicates.
std::set< int > m_polys1
polygon IDs (1-based) that 1st point is inside or on
#define XM_ENSURE_TRUE_VOID_NO_ASSERT(...)
Pt3d gmComputeCentroid(const VecPt3d &a_points)
Computes the centroid of points (but not of a polygon). Shouldn't pass an empty vector (no checks are...
void AddToPolyIdsAndTValues(const ix &a_ix, std::vector< int > &polyids, std::vector< double > &tvalues, std::vector< Pt3d > &a_pts) const
Add the intersection info to the arrays.
double gmXyTol(bool a_set, double a_value)
Get or set (set first time) global xy tolerance for float operations.
bool EQ_TOL(const _T &A, const _U &B, const _V &tolerance)
std::vector< ix > m_ixs
Intersections.
void FixArrays(std::vector< int > &polyids, std::vector< double > &tvalues, std::vector< Pt3d > &a_pts) const
Make sure we always have at least two tvalues, an entrance and an exit, and that the last polyid = -1...
void FixTValueAtDuplicateXy()
The t-value at the same point should be the same, but it can be off in the floating point representat...
Struct used by GmMultiPolyIntersector.
virtual void Sort(GmMultiPolyIntersectorData &a_data, std::vector< int > &polyids, std::vector< double > &tvalues, std::vector< Pt3d > &a_pts, double a_tol) override
Sort the intersections, remove redundant info.
void RemoveDuplicateEdges()
If the line goes along an edge we may have polygons on both sides of the edge. Perhaps we want only t...
void Swap(int a, int b)
Swap the order of the intersections a and b.
Turn_enum
direction of turn between 3 points
void IntersectionsToPolyIdsAndTValues(std::vector< int > &polyids, std::vector< double > &tvalues, std::vector< Pt3d > &a_pts) const
Copy intersections to polyids and tvalues, removing duplicates.
std::vector< Pt3d > VecPt3d
bool EQ_EPS(_T A, _U B, _V epsilon)
std::vector< Pt3d > m_points
All points used by all polygons.