Skip to content

Commit

Permalink
feat(geobase): simply bounds property for Point geometry #141
Browse files Browse the repository at this point in the history
  • Loading branch information
navispatial committed Aug 11, 2022
1 parent 4aeb993 commit 1357b96
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
3 changes: 1 addition & 2 deletions dart/geobase/lib/src/vector_data/model/bounded/bounded.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ abstract class Bounded {

/// The bounding box for this object, if available.
///
/// Accessing this should never trigger extensive calculations. That is, if
/// bounds is not known, then this returns the null value.
/// Accessing this should never trigger extensive calculations.
BoxCoords? get bounds => _bounds;

/*
Expand Down
38 changes: 33 additions & 5 deletions dart/geobase/lib/src/vector_data/model/geometry/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
import '/src/codes/coords.dart';
import '/src/codes/geom.dart';
import '/src/vector/content.dart';
import '/src/vector/encoding.dart';
import '/src/vector/formats.dart';
import '/src/vector_data/array.dart';

import 'geometry.dart';

/// A point geometry with a position.
class Point extends SimpleGeometry {
class Point implements SimpleGeometry {
final PositionCoords _position;

/// A point geometry with [position] and optional [bounds].
const Point(PositionCoords position, {super.bounds}) : _position = position;
/// A point geometry with [position].
const Point(PositionCoords position) : _position = position;

/// A point geometry from a [position].
///
Expand Down Expand Up @@ -77,16 +79,42 @@ class Point extends SimpleGeometry {
/// The position in this point geometry.
PositionCoords get position => _position;

/// The bounding box for this point, mix and max with the same point position.
@override
BoxCoords get bounds => BoxCoords.create(
minX: position.x,
minY: position.y,
minZ: position.optZ,
minM: position.optM,
maxX: position.x,
maxY: position.y,
maxZ: position.optZ,
maxM: position.optM,
);

@override
void writeTo(SimpleGeometryContent writer, {String? name}) =>
writer.point(_position, type: coordType, name: name);

// todo: coordinates as raw data

@override
String toStringAs({
TextWriterFormat<SimpleGeometryContent> format = GeoJSON.geometry,
int? decimals,
}) {
final encoder = format.encoder(decimals: decimals);
writeTo(encoder.writer);
return encoder.toText();
}

@override
String toString() => toStringAs();

@override
bool operator ==(Object other) =>
other is Point && bounds == other.bounds && position == other.position;
other is Point && position == other.position;

@override
int get hashCode => Object.hash(bounds, position);
int get hashCode => position.hashCode;
}

0 comments on commit 1357b96

Please sign in to comment.