-
Notifications
You must be signed in to change notification settings - Fork 1
/
PointNormalPlane.swift
54 lines (42 loc) · 1.58 KB
/
PointNormalPlane.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/// Represents an infinite plane with a point and a normal.
///
/// In 2D, a plane equates to a line, while in 3D and higher dimensions it
/// equates to a flat 2D plane.
public struct PointNormalPlane<Vector: VectorFloatingPoint>: GeometricType, CustomStringConvertible {
/// Convenience for `Vector.Scalar`
public typealias Scalar = Vector.Scalar
public var description: String {
"PointNormalPlane(point: \(point), normal: \(normal))"
}
/// A point on this plane.
public var point: Vector
/// The normal of the plane's surface.
@UnitVector public var normal: Vector
@_transparent
public init(point: Vector, normal: Vector) {
self.point = point
self.normal = normal
}
/// Creates a ``PointNormalPlane`` that wraps the given plane object.
@_transparent
public init<Plane: PlaneType>(_ plane: Plane) where Plane.Vector == Vector {
self.init(point: plane.pointOnPlane, normal: plane.normal)
}
}
extension PointNormalPlane: Equatable where Vector: Equatable { }
extension PointNormalPlane: Hashable where Vector: Hashable { }
public extension PointNormalPlane {
/// Returns a ``PointNormal`` value initialized with this plane's parameters.
@_transparent
var asPointNormal: PointNormal<Vector> {
PointNormal(point: point, normal: normal)
}
}
extension PointNormalPlane: PlaneType {
@_transparent
public var pointOnPlane: Vector { point }
}
extension PointNormalPlane: PointProjectablePlaneType {
}
extension PointNormalPlane: LineIntersectablePlaneType {
}