Skip to content

Commit

Permalink
refactor(geobase): definitions of equalsCooords, equals2D and equals3…
Browse files Browse the repository at this point in the history
…D to Positionable #213
  • Loading branch information
navispatial committed Oct 9, 2023
1 parent ab6a864 commit cafe9e7
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 47 deletions.
47 changes: 0 additions & 47 deletions dart/geobase/lib/src/coordinates/base/bounded.dart
Expand Up @@ -4,7 +4,6 @@
//
// Docs: https://github.com/navibyte/geospatial

import '/src/constants/epsilon.dart';
import '/src/coordinates/base/box.dart';
import '/src/coordinates/projection/projection.dart';

Expand Down Expand Up @@ -91,50 +90,4 @@ abstract class Bounded extends Positionable {
/// projecting position data. If [bounds] is null, then it's null after
/// projecting too.
Bounded project(Projection projection);

/// True if this and [other] contain exactly same coordinate values (or both
/// are empty) in the same order and with the same coordinate type.
bool equalsCoords(covariant Bounded other);

/// True if this and [other] equals by testing 2D coordinate values of all
/// position data (that must be in same order in both objects) contained
/// directly or by child objects.
///
/// Returns false if this and [other] are not of the same subtype.
///
/// Returns false if this or [other] contain "empty geometry"
/// ([isEmptyByGeometry] true).
///
/// Differences on 2D coordinate values (ie. x and y, or lon and lat) between
/// this and [other] must be within [toleranceHoriz].
///
/// Tolerance values must be positive (>= 0.0).
bool equals2D(
covariant Bounded other, {
double toleranceHoriz = defaultEpsilon,
});

/// True if this and [other] equals by testing 3D coordinate values of all
/// position data (that must be in same order in both objects) contained
/// directly or by child objects.
///
/// Returns false if this and [other] are not of the same subtype.
///
/// Returns false if this or [other] contain "empty geometry"
/// ([isEmptyByGeometry] true).
///
/// Returns false if this or [other] do not contain 3D coordinates.
///
/// Differences on 2D coordinate values (ie. x and y, or lon and lat) between
/// this and [other] must be within [toleranceHoriz].
///
/// Differences on vertical coordinate values (ie. z or elev) between
/// this and [other] must be within [toleranceVert].
///
/// Tolerance values must be positive (>= 0.0).
bool equals3D(
covariant Bounded other, {
double toleranceHoriz = defaultEpsilon,
double toleranceVert = defaultEpsilon,
});
}
6 changes: 6 additions & 0 deletions dart/geobase/lib/src/coordinates/base/box.dart
Expand Up @@ -452,12 +452,17 @@ abstract class Box extends ValuePositionable {
/// box when forward-projecting, and other way when inverse-projecting).
Box project(Projection projection);

/// True if this and the [other] box equals.
@override
bool equalsCoords(Box other) => this == other;

/// True if this box equals with [other] by testing 2D coordinates only.
///
/// Differences on 2D coordinate values (ie. x and y, or lon and lat) between
/// this and [other] must be within [toleranceHoriz].
///
/// Tolerance values must be positive (>= 0.0).
@override
bool equals2D(Box other, {double toleranceHoriz = defaultEpsilon}) =>
Box.testEquals2D(this, other, toleranceHoriz: toleranceHoriz);

Expand All @@ -472,6 +477,7 @@ abstract class Box extends ValuePositionable {
/// this and [other] must be within [toleranceVert].
///
/// Tolerance values must be positive (>= 0.0).
@override
bool equals3D(
Box other, {
double toleranceHoriz = defaultEpsilon,
Expand Down
6 changes: 6 additions & 0 deletions dart/geobase/lib/src/coordinates/base/position.dart
Expand Up @@ -423,12 +423,17 @@ abstract class Position extends ValuePositionable {
/// The returned object should be of the same type as this object has.
Position transform(TransformPosition transform);

/// True if this and the [other] position equals.
@override
bool equalsCoords(Position other) => this == other;

/// True if this position equals with [other] by testing 2D coordinates only.
///
/// Differences on 2D coordinate values (ie. x and y, or lon and lat) between
/// this and [other] must be within [toleranceHoriz].
///
/// Tolerance values must be positive (>= 0.0).
@override
bool equals2D(
Position other, {
double toleranceHoriz = defaultEpsilon,
Expand All @@ -446,6 +451,7 @@ abstract class Position extends ValuePositionable {
/// this and [other] must be within [toleranceVert].
///
/// Tolerance values must be positive (>= 0.0).
@override
bool equals3D(
Position other, {
double toleranceHoriz = defaultEpsilon,
Expand Down
3 changes: 3 additions & 0 deletions dart/geobase/lib/src/coordinates/base/position_series.dart
Expand Up @@ -493,6 +493,7 @@ abstract class PositionSeries implements ValuePositionable {

/// Returns true if this and [other] contain exactly same coordinate values
/// (or both are empty) in the same order and with the same coordinate type.
@override
bool equalsCoords(PositionSeries other) {
if (identical(this, other)) return true;
if (positionCount != other.positionCount) return false;
Expand Down Expand Up @@ -522,6 +523,7 @@ abstract class PositionSeries implements ValuePositionable {
/// this and [other] must be within [toleranceHoriz].
///
/// Tolerance values must be positive (>= 0.0).
@override
bool equals2D(
PositionSeries other, {
double toleranceHoriz = defaultEpsilon,
Expand Down Expand Up @@ -563,6 +565,7 @@ abstract class PositionSeries implements ValuePositionable {
/// this and [other] must be within [toleranceVert].
///
/// Tolerance values must be positive (>= 0.0).
@override
bool equals3D(
PositionSeries other, {
double toleranceHoriz = defaultEpsilon,
Expand Down
45 changes: 45 additions & 0 deletions dart/geobase/lib/src/coordinates/base/positionable.dart
Expand Up @@ -5,6 +5,7 @@
// Docs: https://github.com/navibyte/geospatial

import '/src/codes/coords.dart';
import '/src/constants/epsilon.dart';

/// A positionable object contains data structures for (geospatial) position
/// data, directly or within child objects.
Expand All @@ -30,4 +31,48 @@ abstract class Positionable {
/// `Coords.xym`, then `Coords.xy` is returned. When all items are
/// `Coords.xyz`, then `Coords.xyz` is returned.
Coords get coordType;

/// True if this and [other] contain exactly same coordinate values (or both
/// are empty) in the same order and with the same coordinate type.
bool equalsCoords(covariant Positionable other);

/// True if this and [other] equals by testing 2D coordinate values of all
/// position data (that must be in same order in both objects) contained
/// directly or by child objects.
///
/// Returns false if this and [other] are not of the same subtype.
///
/// Returns false if this or [other] contain "empty geometry".
///
/// Differences on 2D coordinate values (ie. x and y, or lon and lat) between
/// this and [other] must be within [toleranceHoriz].
///
/// Tolerance values must be positive (>= 0.0).
bool equals2D(
covariant Positionable other, {
double toleranceHoriz = defaultEpsilon,
});

/// True if this and [other] equals by testing 3D coordinate values of all
/// position data (that must be in same order in both objects) contained
/// directly or by child objects.
///
/// Returns false if this and [other] are not of the same subtype.
///
/// Returns false if this or [other] contain "empty geometry".
///
/// Returns false if this or [other] do not contain 3D coordinates.
///
/// Differences on 2D coordinate values (ie. x and y, or lon and lat) between
/// this and [other] must be within [toleranceHoriz].
///
/// Differences on vertical coordinate values (ie. z or elev) between
/// this and [other] must be within [toleranceVert].
///
/// Tolerance values must be positive (>= 0.0).
bool equals3D(
covariant Positionable other, {
double toleranceHoriz = defaultEpsilon,
double toleranceVert = defaultEpsilon,
});
}
3 changes: 3 additions & 0 deletions dart/geobase/test/coordinates/position_test.dart
Expand Up @@ -677,6 +677,9 @@ class _TestXYZM implements Projected {
@override
String toString() => '$x,$y,$z,$m';

@override
bool equalsCoords(Position other) => this == other;

@override
bool equals2D(
Position other, {
Expand Down

0 comments on commit cafe9e7

Please sign in to comment.