Skip to content

Commit

Permalink
fix(geobase): small adjustements to utils testing coords #188
Browse files Browse the repository at this point in the history
  • Loading branch information
navispatial committed Sep 2, 2023
1 parent 0802c9c commit 84c06ed
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dart/geobase/lib/src/utils/bounded_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ bool testEqualsCoords<T extends Bounded>(
Bounded b2,
bool Function(T, T) test,
) {
// require both bounded objects are of same type
if (b1 is! T || b2 is! T) return false;

// check if refering to the same instance
if (identical(b1, b2)) return true;

// test bounding boxes if both bounded objects have it
Expand All @@ -34,6 +37,7 @@ bool testEqualsCoords<T extends Bounded>(
return false;
}

// use given test function to test actual geometries / coordinates
return test.call(b1, b2);
}

Expand All @@ -50,9 +54,14 @@ bool testEquals2D<T extends Bounded>(
double toleranceHoriz = defaultEpsilon,
}) {
assertTolerance(toleranceHoriz);

// require both bounded objects are of same type, and not empty
if (b1 is! T || b2 is! T) return false;
if (b1.isEmptyByGeometry || b2.isEmptyByGeometry) return false;

// check if refering to the same instance
if (identical(b1, b2)) return true;

// test bounding boxes if both bounded objects have it
final bb1 = b1.bounds;
final bb2 = b2.bounds;
Expand All @@ -65,6 +74,8 @@ bool testEquals2D<T extends Bounded>(
// both bounded objects has bounding boxes and boxes do not equal in 2D
return false;
}

// use given test function to test actual geometries / coordinates
return test.call(b1, b2);
}

Expand All @@ -83,10 +94,16 @@ bool testEquals3D<T extends Bounded>(
}) {
assertTolerance(toleranceHoriz);
assertTolerance(toleranceVert);

// require both bounded objects are of same type, 3D coords, and not empty
if (b1 is! T || b2 is! T) return false;
if (b1.isEmptyByGeometry || b2.isEmptyByGeometry) return false;
if (!b1.coordType.is3D || !b2.coordType.is3D) return false;

// check if refering to the same instance
// NOTE: commented out, does not work as expected, need to refine coord types
// if (identical(b1, b2)) return true;

// test bounding boxes if both bounded objects have it
final bb1 = b1.bounds;
final bb2 = b2.bounds;
Expand All @@ -100,5 +117,7 @@ bool testEquals3D<T extends Bounded>(
// both bounded objects has bounding boxes and boxes do not equal in 3D
return false;
}

// use given test function to test actual geometries / coordinates
return test.call(b1, b2);
}

0 comments on commit 84c06ed

Please sign in to comment.