Skip to content

Commit fdc9456

Browse files
committed
Separate tolerance and segmentLength in overlapping segments
1 parent 6201957 commit fdc9456

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

Sources/GISTools/Algorithms/FrechetDistance.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension LineString {
3737
/// - Parameters:
3838
/// - from: The other geometry of equal type.
3939
/// - distanceFunction: The algorithm to use for distance calculations.
40-
/// - segmentLength: Adds coordinates to the lines for improved matching (in meters).
40+
/// - segmentLength: This value adds intermediate points to the geometry for improved matching, in meters.
4141
///
4242
/// - Returns: The frechet distance between the two geometries.
4343
public func frechetDistance(

Sources/GISTools/Algorithms/LineOverlap.swift

+12-10
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,25 @@ extension GeoJson {
103103

104104
/// Returns the overlapping segments with the receiver itself.
105105
///
106-
/// This implementation is streamlined for finding self-overlaps.
106+
/// This implementation has been optimized for finding self-overlaps.
107107
///
108108
/// - Note: Altitude values will be ignored.
109109
///
110110
/// - Parameters:
111-
/// - tolerance: The tolerance, in meters. Choosing this too small might lead to memory explosion.
112-
/// Using `0.0` will only return segments that *exactly* overlap.
111+
/// - tolerance: The tolerance, in meters. Using `0.0` will only return segments that *exactly* overlap.
112+
/// - segmentLength: This value adds intermediate points to the geometry for improved matching, in meters. Choosing this too small might lead to memory explosion.
113113
///
114114
/// - Returns: All segments that at least overlap with one other segment. Each segment will
115115
/// appear in the result only once.
116116
public func overlappingSegments(
117-
tolerance: CLLocationDistance
117+
tolerance: CLLocationDistance,
118+
segmentLength: Double? = nil
118119
) -> MultiLineString? {
119120
let tolerance = abs(tolerance)
120121
let distanceFunction = FrechetDistanceFunction.haversine
121122

122-
guard let line = if tolerance > 0.0 {
123-
LineString(lineSegments)?.evenlyDivided(segmentLength: tolerance)
123+
guard let line = if let segmentLength, segmentLength > 0.0 {
124+
LineString(lineSegments)?.evenlyDivided(segmentLength: segmentLength)
124125
}
125126
else {
126127
LineString(lineSegments)
@@ -216,14 +217,15 @@ extension GeoJson {
216217
/// An estimate of how much the receiver overlaps with itself.
217218
///
218219
/// - Parameters:
219-
/// - tolerance: The tolerance, in meters. Choosing this too small might lead to memory explosion.
220-
/// Using `0.0` will only use segments that *exactly* overlap.
220+
/// - tolerance: The tolerance, in meters. Using `0.0` will only count segments that *exactly* overlap.
221+
/// - segmentLength: This value adds intermediate points to the geometry for improved matching, in meters. Choosing this too small might lead to memory explosion.
221222
///
222223
/// - Returns: The length of all segments that overlap within `tolerance`.
223224
public func estimatedOverlap(
224-
tolerance: CLLocationDistance
225+
tolerance: CLLocationDistance,
226+
segmentLength: Double? = nil
225227
) -> Double {
226-
guard let result = overlappingSegments(tolerance: tolerance) else { return 0.0 }
228+
guard let result = overlappingSegments(tolerance: tolerance, segmentLength: segmentLength) else { return 0.0 }
227229

228230
return result.length
229231
}

0 commit comments

Comments
 (0)