mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 13:11:33 +00:00
split rectangle
This commit is contained in:
41
Sources/Voxelotl/Math/Size.swift
Normal file
41
Sources/Voxelotl/Math/Size.swift
Normal file
@ -0,0 +1,41 @@
|
||||
public struct Size<T: AdditiveArithmetic>: Equatable {
|
||||
var w: T, h: T
|
||||
|
||||
static var zero: Self { .init(.zero, .zero) }
|
||||
|
||||
init(_ w: T, _ h: T) {
|
||||
self.w = w
|
||||
self.h = h
|
||||
}
|
||||
|
||||
@inline(__always) public static func == (lhs: Self, rhs: Self) -> Bool { lhs.w == rhs.w && lhs.h == rhs.h }
|
||||
@inline(__always) public static func != (lhs: Self, rhs: Self) -> Bool { lhs.w != rhs.w || lhs.h != rhs.h }
|
||||
}
|
||||
|
||||
extension Size where T: BinaryInteger {
|
||||
static var one: Self { .init(T(1), T(1)) }
|
||||
|
||||
init<O: BinaryInteger>(_ other: Size<O>) {
|
||||
self.init(T(other.w), T(other.h))
|
||||
}
|
||||
init<O: BinaryFloatingPoint>(_ other: Size<O>) {
|
||||
self.init(T(other.w), T(other.h))
|
||||
}
|
||||
}
|
||||
|
||||
extension Size where T: BinaryFloatingPoint {
|
||||
init<O: BinaryInteger>(_ other: Size<O>) {
|
||||
self.init(T(other.w), T(other.h))
|
||||
}
|
||||
init<O: BinaryFloatingPoint>(_ other: Size<O>) {
|
||||
self.init(T(other.w), T(other.h))
|
||||
}
|
||||
|
||||
@inline(__always) public static func / (lhs: Self, rhs: Self) -> Self { .init(lhs.w / rhs.w, lhs.h / rhs.h) }
|
||||
}
|
||||
|
||||
extension SIMD2 where Scalar: AdditiveArithmetic {
|
||||
init(_ size: Size<Scalar>) {
|
||||
self.init(size.w, size.h)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user