mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-04 10:59:39 +00:00 
			
		
		
		
	split rectangle
This commit is contained in:
		@ -11,7 +11,10 @@ add_executable(Voxelotl MACOSX_BUNDLE
 | 
			
		||||
  Math/FloatExtensions.swift
 | 
			
		||||
  Math/VectorExtensions.swift
 | 
			
		||||
  Math/Matrix4x4.swift
 | 
			
		||||
  Math/Point.swift
 | 
			
		||||
  Math/Size.swift
 | 
			
		||||
  Math/Rectangle.swift
 | 
			
		||||
  Math/Extent.swift
 | 
			
		||||
  Math/AABB.swift
 | 
			
		||||
 | 
			
		||||
  # Random number generator subsystem
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										13
									
								
								Sources/Voxelotl/Math/Extent.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								Sources/Voxelotl/Math/Extent.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,13 @@
 | 
			
		||||
struct Extent<T: AdditiveArithmetic>: Equatable {
 | 
			
		||||
  var top: T, bottom: T, left: T, right: T
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func == (lhs: Self, rhs: Self) -> Bool {
 | 
			
		||||
    lhs.left == rhs.left && lhs.right == rhs.right && lhs.top == rhs.top && lhs.bottom == rhs.bottom
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension Extent where T: Comparable {
 | 
			
		||||
  var size: Size<T> { .init(
 | 
			
		||||
    right > left ? right - left : left - right,
 | 
			
		||||
    bottom > top ? bottom - top : top - bottom) }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										27
									
								
								Sources/Voxelotl/Math/Point.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Sources/Voxelotl/Math/Point.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,27 @@
 | 
			
		||||
struct Point<T: AdditiveArithmetic>: Equatable {
 | 
			
		||||
  var x: T, y: T
 | 
			
		||||
 | 
			
		||||
  static var zero: Self { .init(.zero, .zero) }
 | 
			
		||||
 | 
			
		||||
  init(_ x: T, _ y: T) {
 | 
			
		||||
    self.x = x
 | 
			
		||||
    self.y = y
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func == (lhs: Self, rhs: Self) -> Bool { lhs.x == rhs.x && lhs.y == rhs.y }
 | 
			
		||||
  @inline(__always) static func != (lhs: Self, rhs: Self) -> Bool { lhs.x != rhs.x || lhs.y != rhs.y }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension Point where T: AdditiveArithmetic {
 | 
			
		||||
  @inline(__always) static func + (lhs: Self, rhs: Self) -> Self { Self(lhs.x + rhs.x, lhs.y + rhs.y) }
 | 
			
		||||
  @inline(__always) static func - (lhs: Self, rhs: Self) -> Self { Self(lhs.x - rhs.x, lhs.y - rhs.y) }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func += (lhs: inout Self, rhs: Self) { lhs.x += rhs.x; lhs.y += rhs.y }
 | 
			
		||||
  @inline(__always) static func -= (lhs: inout Self, rhs: Self) { lhs.x -= rhs.x; lhs.y -= rhs.y }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension SIMD2 where Scalar: AdditiveArithmetic {
 | 
			
		||||
  init(_ point: Point<Scalar>) {
 | 
			
		||||
    self.init(point.x, point.y)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -1,73 +1,3 @@
 | 
			
		||||
struct Point<T: AdditiveArithmetic>: Equatable {
 | 
			
		||||
  var x: T, y: T
 | 
			
		||||
 | 
			
		||||
  static var zero: Self { .init(.zero, .zero) }
 | 
			
		||||
 | 
			
		||||
  init(_ x: T, _ y: T) {
 | 
			
		||||
    self.x = x
 | 
			
		||||
    self.y = y
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func == (lhs: Self, rhs: Self) -> Bool { lhs.x == rhs.x && lhs.y == rhs.y }
 | 
			
		||||
  @inline(__always) static func != (lhs: Self, rhs: Self) -> Bool { lhs.x != rhs.x || lhs.y != rhs.y }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension Point where T: AdditiveArithmetic {
 | 
			
		||||
  @inline(__always) static func + (lhs: Self, rhs: Self) -> Self { Self(lhs.x + rhs.x, lhs.y + rhs.y) }
 | 
			
		||||
  @inline(__always) static func - (lhs: Self, rhs: Self) -> Self { Self(lhs.x - rhs.x, lhs.y - rhs.y) }
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func += (lhs: inout Self, rhs: Self) { lhs.x += rhs.x; lhs.y += rhs.y }
 | 
			
		||||
  @inline(__always) static func -= (lhs: inout Self, rhs: Self) { lhs.x -= rhs.x; lhs.y -= rhs.y }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension SIMD2 where Scalar: AdditiveArithmetic {
 | 
			
		||||
  init(_ point: Point<Scalar>) {
 | 
			
		||||
    self.init(point.x, point.y)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public struct Rect<T: AdditiveArithmetic>: Equatable {
 | 
			
		||||
  var x: T, y: T, w: T, h: T
 | 
			
		||||
 | 
			
		||||
@ -107,17 +37,3 @@ public extension Rect where T: AdditiveArithmetic {
 | 
			
		||||
  var up: T { y }
 | 
			
		||||
  var down: T { y + h }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct Extent<T: AdditiveArithmetic>: Equatable {
 | 
			
		||||
  var top: T, bottom: T, left: T, right: T
 | 
			
		||||
 | 
			
		||||
  @inline(__always) static func == (lhs: Self, rhs: Self) -> Bool {
 | 
			
		||||
    lhs.left == rhs.left && lhs.right == rhs.right && lhs.top == rhs.top && lhs.bottom == rhs.bottom
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension Extent where T: Comparable {
 | 
			
		||||
  var size: Size<T> { .init(
 | 
			
		||||
    right > left ? right - left : left - right,
 | 
			
		||||
    bottom > top ? bottom - top : top - bottom) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										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