diff --git a/Sources/Geometria/2D/Convex2Convex2Intersection.swift b/Sources/Geometria/2D/Convex2Convex2Intersection.swift index aa98474c..0e9530f8 100644 --- a/Sources/Geometria/2D/Convex2Convex2Intersection.swift +++ b/Sources/Geometria/2D/Convex2Convex2Intersection.swift @@ -14,12 +14,20 @@ public enum Convex2Convex2Intersection { /// shape on a single vertex, or tangentially, in case of spheroids. case singlePoint(PointNormal) - /// Represents cases where the convex crosses the other convex shape twice. - case twoPoints(PointNormal, PointNormal) + /// A set of two or more intersection points between the two convexes. + /// + /// The normals are in relation to one of the convexes. + case points([PointNormal]) /// Represents the case where no intersection occurs at any point. case noIntersection + /// Convenience for `.points([p1, p2])`. + @inlinable + public static func twoPoints(_ p1: PointNormal, _ p2: PointNormal) -> Self { + .points([p1, p2]) + } + /// Returns a new ``Convex2Convex2Intersection`` where any ``PointNormal`` value /// is mapped by a provided closure before being stored back into the same /// enum case and returned. @@ -40,8 +48,8 @@ public enum Convex2Convex2Intersection { case .singlePoint(let pointNormal): return .singlePoint(mapper(pointNormal, .singlePoint)) - case let .twoPoints(p1, p2): - return .twoPoints(mapper(p1, .twoPointsFirst), mapper(p2, .twoPointsSecond)) + case .points(let points): + return .points(points.enumerated().map({ mapper($0.element, .points(index: $0.offset)) })) } } @@ -65,8 +73,8 @@ public enum Convex2Convex2Intersection { case .singlePoint(let pointNormal): return .singlePoint(mapper(pointNormal, .singlePoint)) - case let .twoPoints(p1, p2): - return .twoPoints(mapper(p1, .twoPointsFirst), mapper(p2, .twoPointsSecond)) + case .points(let points): + return .points(points.enumerated().map({ mapper($0.element, .points(index: $0.offset)) })) } } @@ -77,6 +85,7 @@ public enum Convex2Convex2Intersection { case singlePoint case twoPointsFirst case twoPointsSecond + case points(index: Int) } } diff --git a/Sources/TestCommons/Assertions.swift b/Sources/TestCommons/Assertions.swift index b971c0db..2f287c65 100644 --- a/Sources/TestCommons/Assertions.swift +++ b/Sources/TestCommons/Assertions.swift @@ -244,11 +244,18 @@ public func assertEqual( ) """ - case .twoPoints(let pn1, let pn2): + case .points(let points) where points.count == 2: buffer = """ .twoPoints( - \(printPointNormal(pn1)), - \(printPointNormal(pn2)) + \(printPointNormal(points[0])), + \(printPointNormal(points[1])) + ) + """ + + case .points(let points): + buffer = """ + .points( + \(points.map(printPointNormal).joined(separator: ",\n")) ) """ } diff --git a/Sources/TestCommons/P5Printer.swift b/Sources/TestCommons/P5Printer.swift index 11a45a4d..98ea2c79 100644 --- a/Sources/TestCommons/P5Printer.swift +++ b/Sources/TestCommons/P5Printer.swift @@ -122,9 +122,10 @@ public class P5Printer { case .singlePoint(let pn): add(pn, style: style, file: file, line: line) - case let .twoPoints(p1, p2): - add(p1, style: style, file: file, line: line) - add(p2, style: style, file: file, line: line) + case .points(let points): + for point in points { + add(point, style: style, file: file, line: line) + } } }