@@ -11,113 +11,50 @@ import NonEmpty
11
11
import SwiftGeoToolbox
12
12
import ValueWithUnit
13
13
14
- #warning("TODO: Replace all the `bbox` by one or two using `Boundable`")
14
+ // MARK: - Default `GeometricSystemAlgebra` implementations
15
15
16
- // MARK: - Base protocol
17
-
18
- public protocol GeometricSystemAlgebra : GeodeticGeometry . GeometricSystem {
19
-
20
- // MARK: Bounding box
21
-
22
- static func bbox( forPoint point: Self . Point ) -> Self . BoundingBox
23
-
24
- /// Returns a naive [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box)
25
- /// enclosing a cluster of points.
26
- /// - Warning: This does not take into account the curvature of the Earth.
27
- /// - Warning: This is a naive implementation, not taking into account the angular coordinate system
28
- /// (i.e. a cluster around 0°N 180°E will have a bounding box around 0°N 0°E).
29
- static func bbox< C: Collection > ( forCollection coordinates: C ) -> Self . BoundingBox ?
30
- where C. Element == Self . Coordinates
31
-
32
- /// Returns a naive [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box)
33
- /// enclosing a cluster of points.
34
- /// - Warning: This does not take into account the curvature of the Earth.
35
- /// - Warning: This is a naive implementation, not taking into account the angular coordinate system
36
- /// (i.e. a cluster around 0°N 180°E will have a bounding box around 0°N 0°E).
37
- static func bbox< Points: Collection > ( forCollection points: Points ) -> Self . BoundingBox ?
38
- where Points. Element == Self . Point
39
-
40
- /// Returns a naive [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box)
41
- /// enclosing a cluster of points.
42
- /// - Warning: This does not take into account the curvature of the Earth.
43
- /// - Warning: This is a naive implementation, not taking into account the angular coordinate system
44
- /// (i.e. a cluster around 0°N 180°E will have a bounding box around 0°N 0°E).
45
- static func bbox< MultiPoint> ( forMultiPoint multiPoint: MultiPoint ) -> Self . BoundingBox
46
- where MultiPoint: GeodeticGeometry . MultiPoint ,
47
- MultiPoint. Point == Self . Point
48
-
49
- /// Returns the [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box)
50
- /// enclosing a cluster of points.
51
- /// - Warning: This does not take into account the curvature of the Earth.
52
- /// - Note: This implementation takes into account the angular coordinate system
53
- /// (i.e. a cluster around 0°N 180°E will have a bounding box around 0°N 180°E).
54
- static func geographicBBox< C: Collection > ( forCollection coordinates: C ) -> Self . BoundingBox ?
55
- where C. Element == Self . Coordinates
56
-
57
- /// Returns the [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box)
58
- /// enclosing a cluster of points.
59
- /// - Warning: This does not take into account the curvature of the Earth.
60
- /// - Note: This implementation takes into account the angular coordinate system
61
- /// (i.e. a cluster around 0°N 180°E will have a bounding box around 0°N 180°E).
62
- static func geographicBBox< Points: Collection > ( forCollection points: Points ) -> Self . BoundingBox ?
63
- where Points. Element == Self . Point
64
-
65
- /// Returns the [bounding box](https://en.wikipedia.org/wiki/Minimum_bounding_box)
66
- /// enclosing a cluster of points.
67
- /// - Warning: This does not take into account the curvature of the Earth.
68
- /// - Note: This implementation takes into account the angular coordinate system
69
- /// (i.e. a cluster around 0°N 180°E will have a bounding box around 0°N 180°E).
70
- static func geographicBBox< MultiPoint> ( forMultiPoint multiPoint: MultiPoint ) -> Self . BoundingBox
71
- where MultiPoint: GeodeticGeometry . MultiPoint ,
72
- MultiPoint. Point == Self . Point
73
-
74
- // MARK: Center
75
-
76
- /// Returns the linear center of a cluster of points.
77
- /// - Warning: This does not take into account the curvature of the Earth.
78
- /// - Warning: This is a naive implementation, not taking into account the angular coordinate system
79
- /// (i.e. a cluster around 0°N 180°E will have a center near 0°N 0°E).
80
- static func center< Points: Collection > ( forCollection points: Points ) -> Self . Coordinates ?
81
- where Points. Element == Self . Point
82
-
83
- static func center( forBBox bbox: Self . BoundingBox ) -> Self . Coordinates
84
-
85
- // MARK: Centroid
86
-
87
- /// Calculates the centroid of a polygon using the mean of all vertices.
88
- static func centroid< Points: Collection > ( forCollection points: Points ) -> Self . Coordinates ?
89
- where Points. Element == Self . Point
90
-
91
- // MARK: Bézier
92
-
93
- static func bezier(
94
- forLineString: Self . LineString ,
95
- sharpness: Double ,
96
- resolution: Double
97
- ) -> Self . LineString
16
+ public extension GeometricSystemAlgebra {
98
17
99
- }
18
+ static func bbox( forPoint point: Self . Point ) -> Self . BoundingBox {
19
+ Self . BoundingBox ( origin: point. coordinates, size: . zero)
20
+ }
100
21
101
- // MARK: - Default implementations
22
+ static func bbox< C> ( forNonEmptyCollection elements: C ) -> Self . BoundingBox
23
+ where C: NonEmptyProtocol , C. Element: Boundable < Self . BoundingBox >
24
+ {
25
+ Self . bbox ( forCollection: elements) ?? elements. first. bbox
26
+ }
102
27
103
- public extension GeometricSystemAlgebra {
104
-
105
- static func bbox( forPoint point: Self . Point ) -> Self . BoundingBox {
106
- return Self . BoundingBox ( origin: point. coordinates, size: . zero)
28
+ static func bbox< Iterator> ( forIterator iterator: inout Iterator ) -> Self . BoundingBox ?
29
+ where Iterator: IteratorProtocol , Iterator. Element: Boundable < Self . BoundingBox >
30
+ {
31
+ guard let element = iterator. next ( ) else {
32
+ return nil
33
+ }
34
+ var bbox : Self . BoundingBox = element. bbox
35
+ while let element = iterator. next ( ) {
36
+ bbox = bbox. union ( element. bbox)
37
+ }
38
+ return bbox
107
39
}
108
40
109
- static func bbox< C: Collection > ( forCollection coordinates: C ) -> Self . BoundingBox ?
110
- where C. Element == Self . Coordinates
41
+ static func bbox< S> (
42
+ forNonEmptyIterator iterator: inout NonEmptyIterator < S >
43
+ ) -> Self . BoundingBox ?
44
+ where S: Sequence , S. Element: Boundable < Self . BoundingBox >
111
45
{
112
- return Self . bbox ( forCollection: coordinates. map ( Self . Point. init ( coordinates: ) ) )
46
+ var bbox : Self . BoundingBox = iterator. first ( ) . bbox
47
+ while let element = iterator. next ( ) {
48
+ bbox = bbox. union ( element. bbox)
49
+ }
50
+ return bbox
113
51
}
114
-
52
+
115
53
static func bbox< MultiPoint> ( forMultiPoint multiPoint: MultiPoint ) -> Self . BoundingBox
116
54
where MultiPoint: GeodeticGeometry . MultiPoint ,
117
- MultiPoint. Point == Self . Point
55
+ MultiPoint. Points . Element : Boundable < Self . BoundingBox >
118
56
{
119
- return self . bbox ( forCollection: multiPoint. points)
120
- ?? self . bbox ( forPoint: multiPoint. points. first)
57
+ Self . bbox ( forCollection: multiPoint. points) ?? multiPoint. points. first. bbox
121
58
}
122
59
123
60
static func geographicBBox< C: Collection > ( forCollection coordinates: C ) -> Self . BoundingBox ?
0 commit comments