mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 13:11:33 +00:00
rotating flip flags
This commit is contained in:
@ -1,6 +1,15 @@
|
||||
import Foundation
|
||||
|
||||
public struct Extent<T: AdditiveArithmetic & Hashable>: Hashable {
|
||||
public var left: T, top: T, right: T, bottom: T
|
||||
|
||||
public init(left: T, top: T, right: T, bottom: T) {
|
||||
self.left = left
|
||||
self.top = top
|
||||
self.right = right
|
||||
self.bottom = bottom
|
||||
}
|
||||
|
||||
@inline(__always) public var topLeft: Point<T> { .init(left, top) }
|
||||
@inline(__always) public var topRight: Point<T> { .init(right, top) }
|
||||
@inline(__always) public var bottomLeft: Point<T> { .init(left, bottom) }
|
||||
@ -24,6 +33,14 @@ public extension Extent where T: SIMDScalar {
|
||||
self.right = to.x
|
||||
self.bottom = to.y
|
||||
}
|
||||
|
||||
@inline(__always) static func + (lhs: Self, rhs: SIMD2<T>) -> Self {
|
||||
.init(
|
||||
left: lhs.left + rhs.x,
|
||||
top: lhs.top + rhs.y,
|
||||
right: lhs.right + rhs.x,
|
||||
bottom: lhs.bottom + rhs.y)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Extent where T: AdditiveArithmetic {
|
||||
@ -44,3 +61,52 @@ public extension Extent where T: Numeric {
|
||||
bottom: lhs.bottom * rhs.h)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Extent where T: BinaryInteger {
|
||||
init<O: BinaryInteger>(_ other: Extent<O>) {
|
||||
self.left = T(other.left)
|
||||
self.top = T(other.top)
|
||||
self.right = T(other.right)
|
||||
self.bottom = T(other.bottom)
|
||||
}
|
||||
init<O: BinaryFloatingPoint>(_ other: Extent<O>) {
|
||||
self.left = T(other.left)
|
||||
self.top = T(other.top)
|
||||
self.right = T(other.right)
|
||||
self.bottom = T(other.bottom)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Extent where T: FloatingPoint {
|
||||
init<O: BinaryInteger>(_ other: Extent<O>) {
|
||||
self.left = T(other.left)
|
||||
self.top = T(other.top)
|
||||
self.right = T(other.right)
|
||||
self.bottom = T(other.bottom)
|
||||
}
|
||||
|
||||
@inline(__always) static func / (lhs: Self, rhs: T) -> Self {
|
||||
.init(
|
||||
left: lhs.left / rhs,
|
||||
top: lhs.top / rhs,
|
||||
right: lhs.right / rhs,
|
||||
bottom: lhs.bottom / rhs)
|
||||
}
|
||||
}
|
||||
|
||||
public extension Extent where T: BinaryFloatingPoint {
|
||||
init<O: BinaryFloatingPoint>(_ other: Extent<O>) {
|
||||
self.left = T(other.left)
|
||||
self.top = T(other.top)
|
||||
self.right = T(other.right)
|
||||
self.bottom = T(other.bottom)
|
||||
}
|
||||
}
|
||||
|
||||
@inlinable public func floor<T: FloatingPoint>(_ extent: Extent<T>) -> Extent<T> {
|
||||
.init(
|
||||
left: floor(extent.left),
|
||||
top: floor(extent.top),
|
||||
right: floor(extent.right),
|
||||
bottom: floor(extent.bottom))
|
||||
}
|
||||
|
Reference in New Issue
Block a user