宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
//  SCNVector3Extensions.swift
//  SwifterSwift
//
//  Created by Max Härtwig on 04.04.19.
//  Copyright © 2019 SwifterSwift
//
 
#if os(OSX)
/// SwifterSwift: CGFloat.
public typealias SceneKitFloat = CGFloat
#else
/// SwifterSwift: Float.
public typealias SceneKitFloat = Float
#endif
 
#if canImport(SceneKit)
import SceneKit
 
// MARK: - Methods
public extension SCNVector3 {
 
    /// SwifterSwift: Returns the absolute values of the vector's components.
    ///
    ///         SCNVector3(2, -3, -6).abs -> SCNVector3(2, 3, 6)
    ///
    var absolute: SCNVector3 {
        return SCNVector3(abs(x), abs(y), abs(z))
    }
 
    /// SwifterSwift: Returns the length of the vector.
    ///
    ///         SCNVector3(2, 3, 6).length -> 7
    ///
    var length: SceneKitFloat {
        return sqrt(pow(x, 2) + pow(y, 2) + pow(z, 2))
    }
 
}
 
// MARK: - Operators
public extension SCNVector3 {
 
    /// SwifterSwift: Add two SCNVector3s.
    ///
    ///     SCNVector3(10, 10, 10) + SCNVector3(10, 20, -30) -> SCNVector3(20, 30, -20)
    ///
    /// - Parameters:
    ///   - lhs: SCNVector3 to add to.
    ///   - rhs: SCNVector3 to add.
    /// - Returns: result of addition of the two given SCNVector3s.
    static func + (lhs: SCNVector3, rhs: SCNVector3) -> SCNVector3 {
        return SCNVector3(lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z)
    }
 
    /// SwifterSwift: Add a SCNVector3 to self.
    ///
    ///     SCNVector3(10, 10, 10) += SCNVector3(10, 20, -30) -> SCNVector3(20, 30, -20)
    ///
    /// - Parameters:
    ///   - lhs: self
    ///   - rhs: SCNVector3 to add.
    static func += (lhs: inout SCNVector3, rhs: SCNVector3) {
        // swiftlint:disable:next shorthand_operator
        lhs = lhs + rhs
    }
 
    /// SwifterSwift: Subtract two SCNVector3s.
    ///
    ///     SCNVector3(10, 10, 10) - SCNVector3(10, 20, -30) -> SCNVector3(0, -10, 40)
    ///
    /// - Parameters:
    ///   - lhs: SCNVector3 to subtract from.
    ///   - rhs: SCNVector3 to subtract.
    /// - Returns: result of subtract of the two given SCNVector3s.
    static func - (lhs: SCNVector3, rhs: SCNVector3) -> SCNVector3 {
        return SCNVector3(lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z)
    }
 
    /// SwifterSwift: Subtract a SCNVector3 from self.
    ///
    ///     SCNVector3(10, 10, 10) -= SCNVector3(10, 20, -30) -> SCNVector3(0, -10, 40)
    ///
    /// - Parameters:
    ///   - lhs: self
    ///   - rhs: SCNVector3 to subtract.
    static func -= (lhs: inout SCNVector3, rhs: SCNVector3) {
        // swiftlint:disable:next shorthand_operator
        lhs = lhs - rhs
    }
 
    /// SwifterSwift: Multiply a SCNVector3 with a scalar
    ///
    ///     SCNVector3(10, 20, -30) * 3 -> SCNVector3(30, 60, -90)
    ///
    /// - Parameters:
    ///   - vector: SCNVector3 to multiply.
    ///   - scalar: scalar value.
    /// - Returns: result of multiplication of the given SCNVector3 with the scalar.
    static func * (vector: SCNVector3, scalar: SceneKitFloat) -> SCNVector3 {
        return SCNVector3(vector.x * scalar, vector.y * scalar, vector.z * scalar)
    }
 
    /// SwifterSwift: Multiply self with a scalar
    ///
    ///     SCNVector3(10, 20, -30) *= 3 -> SCNVector3(30, 60, -90)
    ///
    /// - Parameters:
    ///   - vector: self.
    ///   - scalar: scalar value.
    /// - Returns: result of multiplication of the given CGPoint with the scalar.
    static func *= (vector: inout SCNVector3, scalar: SceneKitFloat) {
        // swiftlint:disable:next shorthand_operator
        vector = vector * scalar
    }
 
    /// SwifterSwift: Multiply a scalar with a SCNVector3
    ///
    ///     3 * SCNVector3(10, 20, -30) -> SCNVector3(30, 60, -90)
    ///
    /// - Parameters:
    ///   - scalar: scalar value.
    ///   - vector: SCNVector3 to multiply.
    /// - Returns: result of multiplication of the given CGPoint with the scalar.
    static func * (scalar: SceneKitFloat, vector: SCNVector3) -> SCNVector3 {
        return SCNVector3(vector.x * scalar, vector.y * scalar, vector.z * scalar)
    }
 
}
 
#endif