Skip to content

Commit

Permalink
Fixing integration of master branch changes in last merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonystone committed Mar 23, 2018
1 parent fb4806a commit 5c69f5f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 93 deletions.
44 changes: 21 additions & 23 deletions Sources/GeoFeatures/LineString+Geometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,32 @@ extension LineString: Geometry {
///
public
func isSimple() -> Bool {
return buffer.withUnsafeMutablePointers { (header, elements) -> Bool in

/// If there are no more than two coordinates, there can be at most one line segment,
/// so this line segment cannot self-intersect.
guard header.pointee.count > 2 else {
return true
}
/// If there are no more than two coordinates, there can be at most one line segment,
/// so this line segment cannot self-intersect.
guard coordinates.count > 2 else {
return true
}

/// There must be at least two line segments to get to this point.
for i in 0..<header.pointee.count - 2 {
let c1 = elements[i]
let c2 = elements[i+1]
for j in (i+1)..<header.pointee.count - 1 {
let c3 = elements[j]
let c4 = elements[j+1]
var intersect: Bool = false
if j == i+1 {
intersect = segmentsIntersect(c1, c2, c3, c4, true)
} else if i == 0 && j == header.pointee.count - 2 {
intersect = segmentsIntersect(c1, c2, c3, c4, false, true)
} else {
intersect = segmentsIntersect(c1, c2, c3, c4)
}
if intersect { return false }
/// There must be at least two line segments to get to this point.
for i in 0..<coordinates.count - 2 {
let c1 = coordinates[i]
let c2 = coordinates[i+1]
for j in (i+1)..<coordinates.count - 1 {
let c3 = coordinates[j]
let c4 = coordinates[j+1]
var intersect: Bool = false
if j == i+1 {
intersect = segmentsIntersect(c1, c2, c3, c4, true)
} else if i == 0 && j == coordinates.count - 2 {
intersect = segmentsIntersect(c1, c2, c3, c4, false, true)
} else {
intersect = segmentsIntersect(c1, c2, c3, c4)
}
if intersect { return false }
}
return true
}
return true
}

///
Expand Down
14 changes: 6 additions & 8 deletions Sources/GeoFeatures/MultiPoint+Geometry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ extension MultiPoint: Geometry {
///
public func isSimple() -> Bool {

return buffer.withUnsafeMutablePointers { (header, elements) -> Bool in
var points = [Element]()
var points = [Element]()

for i in 0..<header.pointee.count {
if points.contains(elements[i]) {
return false
}
points.append(elements[i])
for i in 0..<elements.count {
if points.contains(elements[i]) {
return false
}
return true
points.append(elements[i])
}
return true
}

///
Expand Down
44 changes: 0 additions & 44 deletions Sources/GeoFeatures/Segment.swift

This file was deleted.

96 changes: 78 additions & 18 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1263,7 +1263,10 @@ extension MultiPointGeometryCoordinate2DFloatingPrecisionCartesianTests {
return [
("testDimension", testDimension),
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty)
("testBoundaryEmpty", testBoundaryEmpty),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1273,7 +1276,10 @@ extension MultiPointGeometryCoordinate2DMFloatingPrecisionCartesianTests {
return [
("testDimension", testDimension),
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty)
("testBoundaryEmpty", testBoundaryEmpty),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1283,7 +1289,10 @@ extension MultiPointGeometryCoordinate3DFloatingPrecisionCartesianTests {
return [
("testDimension", testDimension),
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty)
("testBoundaryEmpty", testBoundaryEmpty),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1293,7 +1302,10 @@ extension MultiPointGeometryCoordinate3DMFloatingPrecisionCartesianTests {
return [
("testDimension", testDimension),
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty)
("testBoundaryEmpty", testBoundaryEmpty),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1303,7 +1315,10 @@ extension MultiPointGeometryCoordinate2DFixedPrecisionCartesianTests {
return [
("testDimension", testDimension),
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty)
("testBoundaryEmpty", testBoundaryEmpty),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1313,7 +1328,10 @@ extension MultiPointGeometryCoordinate2DMFixedPrecisionCartesianTests {
return [
("testDimension", testDimension),
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty)
("testBoundaryEmpty", testBoundaryEmpty),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1325,7 +1343,10 @@ extension MultiPointGeometryCoordinate3DFixedPrecisionCartesianTests {
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty),
("testEqualTrue", testEqualTrue),
("testEqualFalse", testEqualFalse)
("testEqualFalse", testEqualFalse),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand All @@ -1337,7 +1358,10 @@ extension MultiPointGeometryCoordinate3DMFixedPrecisionCartesianTests {
("testBoundary", testBoundary),
("testBoundaryEmpty", testBoundaryEmpty),
("testEqualTrue", testEqualTrue),
("testEqualFalse", testEqualFalse)
("testEqualFalse", testEqualFalse),
("testIsSimpleWithNoEqualPoints", testIsSimpleWithNoEqualPoints),
("testIsSimpleWithNoEqualPointsAfterPrecision", testIsSimpleWithNoEqualPointsAfterPrecision),
("testIsSimpleWithEqualPointsAfterPrecision", testIsSimpleWithEqualPointsAfterPrecision)
]
}
}
Expand Down Expand Up @@ -1437,7 +1461,8 @@ extension PointGeometryCoordinate2DFloatingPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1450,7 +1475,8 @@ extension PointGeometryCoordinate2DMFloatingPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1463,7 +1489,8 @@ extension PointGeometryCoordinate3DFloatingPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1476,7 +1503,8 @@ extension PointGeometryCoordinate3DMFloatingPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1489,7 +1517,8 @@ extension PointGeometryCoordinate2DFixedPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1502,7 +1531,8 @@ extension PointGeometryCoordinate2DMFixedPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1515,7 +1545,8 @@ extension PointGeometryCoordinate3DFixedPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand All @@ -1528,7 +1559,8 @@ extension PointGeometryCoordinate3DMFixedPrecisionCartesianTests {
("testEqualsWithIntOneTrue", testEqualsWithIntOneTrue),
("testEqualsWithIntOneFalse", testEqualsWithIntOneFalse),
("testEqualsWithPointNonPointFalse", testEqualsWithPointNonPointFalse),
("testBoundary", testBoundary)
("testBoundary", testBoundary),
("testIsSimple_True", testIsSimple_True)
]
}
}
Expand Down Expand Up @@ -2118,7 +2150,21 @@ extension LineStringGeometryCoordinate2DFloatingPrecisionCartesianTests {
("testBoundaryWith4ElementClosed", testBoundaryWith4ElementClosed),
("testBoundaryEmpty", testBoundaryEmpty),
("testEqualTrue", testEqualTrue),
("testEqualFalse", testEqualFalse)
("testEqualFalse", testEqualFalse),
("testIsSimple_WithNoPoints", testIsSimple_WithNoPoints),
("testIsSimple_WithOnePoint", testIsSimple_WithOnePoint),
("testIsSimple_WithTwoPoints", testIsSimple_WithTwoPoints),
("testIsSimple_WithThreeIdenticalPoints", testIsSimple_WithThreeIdenticalPoints),
("testIsSimple_WithThreePoints_FirstSecondSame", testIsSimple_WithThreePoints_FirstSecondSame),
("testIsSimple_WithThreePoints_FirstThirdSame", testIsSimple_WithThreePoints_FirstThirdSame),
("testIsSimple_WithThreePoints_SecondThirdSame", testIsSimple_WithThreePoints_SecondThirdSame),
("testIsSimple_WithThreePoints_AllDifferent", testIsSimple_WithThreePoints_AllDifferent),
("testIsSimple_WithFourPoints_FirstLastSame", testIsSimple_WithFourPoints_FirstLastSame),
("testIsSimple_WithFourPoints_LastSegmentTouchesButGoesBeyondFirstPoint", testIsSimple_WithFourPoints_LastSegmentTouchesButGoesBeyondFirstPoint),
("testIsSimple_WithFourPoints_LastSegmentCrossedFirstSegment", testIsSimple_WithFourPoints_LastSegmentCrossedFirstSegment),
("testIsSimple_WithFivePoints_SecondLastSame", testIsSimple_WithFivePoints_SecondLastSame),
("testIsSimple_WithFivePoints_FirstFourthSame", testIsSimple_WithFivePoints_FirstFourthSame),
("testIsSimple_WithFivePoints_ThirdSegmentTouchesFirstSegment", testIsSimple_WithFivePoints_ThirdSegmentTouchesFirstSegment)
]
}
}
Expand Down Expand Up @@ -2150,7 +2196,21 @@ extension LineStringGeometryCoordinate3DMFloatingPrecisionCartesianTests {
extension LineStringGeometryCoordinate2DFixedPrecisionCartesianTests {
static var allTests: [(String, (LineStringGeometryCoordinate2DFixedPrecisionCartesianTests) -> () throws -> Void)] {
return [
("testDimension", testDimension)
("testDimension", testDimension),
("testIsSimple_WithNoPoints", testIsSimple_WithNoPoints),
("testIsSimple_WithOnePoint", testIsSimple_WithOnePoint),
("testIsSimple_WithTwoPoints", testIsSimple_WithTwoPoints),
("testIsSimple_WithThreeIdenticalPoints", testIsSimple_WithThreeIdenticalPoints),
("testIsSimple_WithThreePoints_FirstSecondSame", testIsSimple_WithThreePoints_FirstSecondSame),
("testIsSimple_WithThreePoints_FirstThirdSame", testIsSimple_WithThreePoints_FirstThirdSame),
("testIsSimple_WithThreePoints_SecondThirdSame", testIsSimple_WithThreePoints_SecondThirdSame),
("testIsSimple_WithThreePoints_AllDifferent", testIsSimple_WithThreePoints_AllDifferent),
("testIsSimple_WithFourPoints_FirstLastSame", testIsSimple_WithFourPoints_FirstLastSame),
("testIsSimple_WithFourPoints_LastSegmentTouchesButGoesBeyondFirstPoint", testIsSimple_WithFourPoints_LastSegmentTouchesButGoesBeyondFirstPoint),
("testIsSimple_WithFourPoints_LastSegmentCrossedFirstSegment", testIsSimple_WithFourPoints_LastSegmentCrossedFirstSegment),
("testIsSimple_WithFivePoints_SecondLastSame", testIsSimple_WithFivePoints_SecondLastSame),
("testIsSimple_WithFivePoints_FirstFourthSame", testIsSimple_WithFivePoints_FirstFourthSame),
("testIsSimple_WithFivePoints_ThirdSegmentTouchesFirstSegment", testIsSimple_WithFivePoints_ThirdSegmentTouchesFirstSegment)
]
}
}
Expand Down

0 comments on commit 5c69f5f

Please sign in to comment.