Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/Packages
/*.xcodeproj
xcuserdata/

.vscode/
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/RougeWare/Swift-MultiplicativeArithmetic.git", from: "2.0.1"),
.package(url: "https://github.com/RougeWare/Swift-MultiplicativeArithmetic.git", from: "2.1.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Swift Rectangle Tools #

[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRougeWare%2FSwift-Rectangle-Tools%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/RougeWare/Swift-Rectangle-Tools)
![Linux](https://img.shields.io/badge/Linux-supported-blue?logo=linux&logoColor=white)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FRougeWare%2FSwift-Rectangle-Tools%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/RougeWare/Swift-Rectangle-Tools)
[![Swift Package Manager](https://img.shields.io/badge/SwiftPM-compatible-orange?logo=swift&logoColor=white)](https://swift.org/package-manager/)
[![Fair License](https://img.shields.io/badge/License-Fair-green)](LICENSE.txt)
![](https://img.shields.io/github/release-date/RougeWare/Swift-RectangleTools?display_date=published_at&label=Last%20updated)

A set of Swift utilities for dealing with rectangles, including a way to generically build your own!

This package includes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,48 @@

public typealias NativeEdgeInsets = NSEdgeInsets
public typealias UserInterfaceLayoutDirection = NSUserInterfaceLayoutDirection
#else
import Foundation

public typealias NativeEdgeInsets = EdgeInsets



/// Represents the amount by which something is inset from the edge of something else
///
/// This includes presumptive automatic localization by using leading/trailing sides instead of left/right.
public struct EdgeInsets<Length> {
public var top: Length
public var leading: Length
public var bottom: Length
public var trailing: Length


public init(top: Length, leading: Length, bottom: Length, trailing: Length) {
self.top = top
self.leading = leading
self.bottom = bottom
self.trailing = trailing
}
}



/// The layout direction of the user interface, corresponding to the reading direction of the current language.
public enum UserInterfaceLayoutDirection {
case leftToRight
case rightToLeft
}
#endif



@available(watchOS 2.1, *)
extension NativeEdgeInsets: FourSidedAbsolute {

#if canImport(SwiftUI)
#if canImport(SwiftUI) || !(canImport(WatchKit) || canImport(UIKit) || canImport(AppKit))

public init(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) {
public init(top: Length, right: Length, bottom: Length, left: Length) {
switch UserInterfaceLayoutDirection.current {
case .leftToRight:
self.init(top: top, leading: left, bottom: bottom, trailing: right)
Expand All @@ -52,12 +84,12 @@ extension NativeEdgeInsets: FourSidedAbsolute {
}


public init(top: CGFloat, trailing: CGFloat, bottom: CGFloat, leading: CGFloat) {
public init(top: Length, trailing: Length, bottom: Length, leading: Length) {
self.init(top: top, leading: leading, bottom: bottom, trailing: trailing)
}


public var left: CGFloat {
public var left: Length {
switch UserInterfaceLayoutDirection.current {
case .leftToRight: return leading
case .rightToLeft: return trailing
Expand All @@ -69,7 +101,7 @@ extension NativeEdgeInsets: FourSidedAbsolute {
}


public var right: CGFloat {
public var right: Length {
switch UserInterfaceLayoutDirection.current {
case .leftToRight: return trailing
case .rightToLeft: return leading
Expand All @@ -81,16 +113,16 @@ extension NativeEdgeInsets: FourSidedAbsolute {
}


#else
#elseif canImport(WatchKit) || canImport(UIKit) || canImport(AppKit)


@available(watchOS 2.1, *)
public init(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) {
public init(top: Length, right: Length, bottom: Length, left: Length) {
self.init(top: top, left: left, bottom: bottom, right: right)
}


public init(top: CGFloat, trailing: CGFloat, bottom: CGFloat, leading: CGFloat) {
public init(top: Length, trailing: Length, bottom: Length, leading: Length) {
switch UserInterfaceLayoutDirection.current {
case .leftToRight:
self.init(top: top, right: trailing, bottom: bottom, left: leading)
Expand All @@ -109,11 +141,11 @@ extension NativeEdgeInsets: FourSidedAbsolute {



#if !canImport(SwiftUI)
#if !canImport(SwiftUI) && (canImport(WatchKit) || canImport(UIKit) || canImport(AppKit))
@available(watchOS 2.1, *)
public extension NativeEdgeInsets {
/// The value of whichever edge inset is leading in the current app's UI direction
var leading: CGFloat {
var leading: Length {
switch UserInterfaceLayoutDirection.current {
case .leftToRight: return left
case .rightToLeft: return right
Expand All @@ -125,7 +157,7 @@ public extension NativeEdgeInsets {


/// The value of whichever edge inset is trailing in the current app's UI direction
var trailing: CGFloat {
var trailing: Length {
switch UserInterfaceLayoutDirection.current {
case .leftToRight: return right
case .rightToLeft: return left
Expand Down Expand Up @@ -163,6 +195,9 @@ public extension UserInterfaceLayoutDirection {
let legacyCurrent = UIApplication.shared.userInterfaceLayoutDirection
#elseif canImport(AppKit)
let legacyCurrent = NSApp?.userInterfaceLayoutDirection ?? .leftToRight
#else
// TODO: Figure this out for common other platforms
let legacyCurrent = UserInterfaceLayoutDirection.leftToRight
#endif

#if canImport(SwiftUI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif
import MultiplicativeArithmetic


Expand Down
2 changes: 2 additions & 0 deletions Tests/RectangleToolsTests/Point Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif
#if canImport(CoreImage)
import CoreImage
#endif
Expand Down
2 changes: 2 additions & 0 deletions Tests/RectangleToolsTests/Size initializatoin tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Created by Ky on 2026-02-03.
//

#if canImport(CoreGraphics)
import CoreGraphics
#endif
import Testing

import RectangleTools
Expand Down
2 changes: 2 additions & 0 deletions Tests/RectangleToolsTests/Test Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
//

import Foundation
#if canImport(CoreGraphics)
import CoreGraphics
#endif

import RectangleTools

Expand Down
2 changes: 2 additions & 0 deletions Tests/RectangleToolsTests/TwoDimensional operator tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//

import Testing
#if canImport(CoreGraphics)
import CoreGraphics
#endif

import RectangleTools

Expand Down
Loading