-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from li3zhen1/dev
Add conditional import for simd
- Loading branch information
Showing
7 changed files
with
106 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import simd | ||
|
||
protocol ViewportPoint<Scalar> { | ||
associatedtype Scalar where Scalar: FloatingPoint | ||
var x: Scalar { get } | ||
var y: Scalar { get } | ||
} | ||
|
||
extension SIMD2: ViewportPoint where Scalar == Double {} | ||
|
||
public struct ViewportTransform { | ||
public typealias Scalar = Double | ||
@usableFromInline | ||
internal var data: SIMD3<Scalar> | ||
|
||
@inlinable | ||
public init(data: SIMD3<Scalar>) { | ||
self.data = data | ||
} | ||
} | ||
|
||
extension ViewportTransform: ExpressibleByArrayLiteral { | ||
@inlinable | ||
public init(arrayLiteral elements: Scalar...) { | ||
self.init(data: SIMD3<Scalar>(elements)) | ||
} | ||
} | ||
|
||
extension ViewportTransform { | ||
@inlinable | ||
public var k: Scalar { | ||
return self.data.x | ||
} | ||
|
||
@inlinable | ||
public var x: Scalar { | ||
return self.data.y | ||
} | ||
|
||
@inlinable | ||
public var y: Scalar { | ||
return self.data.z | ||
} | ||
} | ||
|
||
extension ViewportTransform { | ||
@inlinable | ||
public func scale(by factor: Scalar) -> ViewportTransform { | ||
return ViewportTransform(data: self.data * [1, factor, factor]) | ||
} | ||
|
||
@inlinable | ||
public func translate(by vector: SIMD2<Scalar>) -> ViewportTransform { | ||
return ViewportTransform(data: self.data + [0, vector.x, vector.y]) | ||
} | ||
} |