Skip to content

Commit b320979

Browse files
committed
feat: create the Volumetric protocol
1 parent 36e6d93 commit b320979

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import Foundation
2+
3+
/// A set of methods for working with Spatial primitives with volume.
4+
public protocol Volumetric {
5+
6+
// MARK: - Instance properties
7+
8+
/// The size of the volume.
9+
var size: Size3D { get }
10+
11+
// MARK: - Instance methods
12+
13+
/// Returns a Boolean value that indicates whether the entity contains the specified volumetric entity.
14+
///
15+
/// - Parameter other: The volumetric entity that the function compares against.
16+
/// - Returns: A Boolean value that indicates whether the entity contains the specified volumetric entity
17+
func contains(_ other: Self) -> Bool
18+
19+
/// Returns a Boolean value that indicates whether this volume contains the specified point.
20+
///
21+
/// - Parameter point: The point that the function compares against.
22+
/// - Returns: A Boolean value that indicates whether this volume contains the specified point.
23+
func contains(point: Point3D) -> Bool
24+
25+
/// Returns a Boolean value that indicates whether this volume contains any of the specified points.
26+
///
27+
/// - Parameter points: The array of points that the function compares against.
28+
/// - Returns: A Boolean value that indicates whether this volume contains any of the specified points
29+
func contains(anyOf points: [Point3D]) -> Bool
30+
31+
/// Sets the primitive to the intersection of itself and the specified primitive.
32+
///
33+
/// - Parameter other: The primitive to intersect with.
34+
mutating func formIntersection(_ other: Self)
35+
36+
/// Sets the primitive to the union of itself and the specified primitive.
37+
///
38+
/// - Parameter other: The primitive to union with.
39+
mutating func formUnion(_ other: Self)
40+
41+
/// Returns the intersection of this primitive and the specified primitive.
42+
///
43+
/// - Parameter other: The primitive to intersect with.
44+
/// - Returns: The intersection of this primitive and the specified primitive, or `nil` if they do not intersect.
45+
func intersection(_ other: Self) -> Self?
46+
47+
/// Returns the union of this primitive and the specified primitive.
48+
///
49+
/// - Parameter other: The primitive to union with.
50+
/// - Returns: The union of this primitive and the specified primitive.
51+
func union(_ other: Self) -> Self
52+
}
53+
54+
extension Volumetric {
55+
56+
// MARK: - Instance methods
57+
58+
/// Returns a Boolean value that indicates whether this volume contains any of the specified points.
59+
///
60+
/// - Parameter points: The array of points that the function compares against.
61+
/// - Returns: A Boolean value that indicates whether this volume contains any of the specified points
62+
public func contains(anyOf points: [Point3D]) -> Bool {
63+
for point in points {
64+
if contains(point: point) {
65+
return true
66+
}
67+
}
68+
69+
return false
70+
}
71+
}

0 commit comments

Comments
 (0)