From 882a303cc2464f298fc04bd52c59a41c31af87ba Mon Sep 17 00:00:00 2001 From: Lukas Himsel Date: Mon, 20 Jun 2022 09:28:33 +0200 Subject: [PATCH 1/2] start new signing mechanism from #46 --- lib/src/geojson.dart | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/geojson.dart b/lib/src/geojson.dart index 75f2e3b6..93669d4b 100644 --- a/lib/src/geojson.dart +++ b/lib/src/geojson.dart @@ -68,9 +68,13 @@ abstract class GeoJSONObject { /// Coordinate types, following https://tools.ietf.org/html/rfc7946#section-4 abstract class CoordinateType implements Iterable { + final bool isSigned; final List _items; - CoordinateType(List list) : _items = List.of(list, growable: false); + CoordinateType( + List list, + this.isSigned, + ) : _items = List.of(list, growable: false); @override num get first => _items.first; @@ -180,7 +184,7 @@ abstract class CoordinateType implements Iterable { CoordinateType toSigned(); - bool get isSigned; + CoordinateType toUnsigned(); _untilSigned(val, limit) { if (val > limit) { From 01187dc68b1fa93e1dec0fb065978aa288f99d68 Mon Sep 17 00:00:00 2001 From: Lukas Himsel Date: Sun, 11 Sep 2022 19:06:40 +0200 Subject: [PATCH 2/2] finish basic implementation --- lib/src/geojson.dart | 112 ++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 39 deletions(-) diff --git a/lib/src/geojson.dart b/lib/src/geojson.dart index b02bc81a..cb439a97 100644 --- a/lib/src/geojson.dart +++ b/lib/src/geojson.dart @@ -68,12 +68,12 @@ abstract class GeoJSONObject { /// Coordinate types, following https://tools.ietf.org/html/rfc7946#section-4 abstract class CoordinateType implements Iterable { - final bool isSigned; + final bool _signed; final List _items; CoordinateType( List list, - this.isSigned, + this._signed, ) : _items = List.of(list, growable: false); @override @@ -186,6 +186,8 @@ abstract class CoordinateType implements Iterable { CoordinateType toUnsigned(); + bool get isSigned => _signed; + num _untilSigned(num val, limit) { if (val > limit) { return _untilSigned(val - 360, limit); @@ -199,24 +201,36 @@ abstract class CoordinateType implements Iterable { /// Please make sure, you arrange your parameters like this: /// 1. Longitude, 2. Latitude, 3. Altitude (optional) class Position extends CoordinateType { - Position(num lng, num lat, [num? alt]) - : super([ - lng, - lat, - if (alt != null) alt, - ]); - - Position.named({required num lat, required num lng, num? alt}) - : super([ - lng, - lat, - if (alt != null) alt, - ]); + Position(num lng, num lat, [num? alt, bool signed = false]) + : super( + [ + lng, + lat, + if (alt != null) alt, + ], + signed, + ); + + Position.named( + {required num lat, required num lng, num? alt, bool signed = false}) + : super( + [ + lng, + lat, + if (alt != null) alt, + ], + signed, + ); /// Position.of([, , ]) - Position.of(List list) - : assert(list.length >= 2 && list.length <= 3), - super(list); + Position.of( + List list, { + bool signed = false, + }) : assert(list.length >= 2 && list.length <= 3), + super( + list, + signed, + ); factory Position.fromJson(List list) => Position.of(list); @@ -257,17 +271,21 @@ class Position extends CoordinateType { num? get alt => length == 3 ? _items[2] : null; @override - bool get isSigned => lng <= 180 && lat <= 90; + bool get isSigned => _signed && lng <= 180 && lat <= 90; @override Position toSigned() => Position.named( lng: _untilSigned(lng, 180), lat: _untilSigned(lat, 90), alt: alt, + signed: true, ); @override - Position clone() => Position.of(_items); + Position toUnsigned() => Position.of(_items, signed: false); + + @override + Position clone() => Position.of(_items, signed: _signed); @override int get hashCode => Object.hashAll(_items); @@ -303,14 +321,18 @@ class BBox extends CoordinateType { /// altitude 2 for 3 dim. positions num? alt2, - ]) : super([ - lng1, - lat1, - alt1, - lng2, - if (lat2 != null) lat2, - if (alt2 != null) alt2, - ]); + bool signed = false, + ]) : super( + [ + lng1, + lat1, + alt1, + lng2, + if (lat2 != null) lat2, + if (alt2 != null) alt2, + ], + signed, + ); BBox.named({ required num lng1, @@ -319,19 +341,28 @@ class BBox extends CoordinateType { required num lng2, required num lat2, num? alt2, - }) : super([ - lng1, - lat1, - if (alt1 != null) alt1, - lng2, - lat2, - if (alt2 != null) alt2, - ]); + bool signed = false, + }) : super( + [ + lng1, + lat1, + if (alt1 != null) alt1, + lng2, + lat2, + if (alt2 != null) alt2, + ], + signed, + ); /// Position.of([, , ]) - BBox.of(List list) - : assert(list.length == 4 || list.length == 6), - super(list); + BBox.of( + List list, { + bool signed = false, + }) : assert(list.length == 4 || list.length == 6), + super( + list, + signed, + ); factory BBox.fromJson(List list) => BBox.of(list); @@ -382,6 +413,9 @@ class BBox extends CoordinateType { lng2: _untilSigned(lng2, 180), ); + @override + BBox toUnsigned() => BBox.of(_items, signed: false); + @override int get hashCode => Object.hashAll(_items);