-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
243 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Geometria | ||
|
||
/// A 2-dimensional simplex composed of a circular arc segment. | ||
public struct CircleArc2Simplex<Vector: Vector2Real>: Periodic2Simplex { | ||
/// The circular arc segment associated with this simplex. | ||
public var circleArc: CircleArc2<Vector> | ||
|
||
/// Initializes a new circular arc segment simplex value with a given circular | ||
/// arc segment. | ||
public init(circleArc: CircleArc2<Vector>) { | ||
self.circleArc = circleArc | ||
} | ||
} | ||
|
||
extension CircleArc2Simplex { | ||
@inlinable | ||
public var start: Vector { circleArc.startPoint } | ||
|
||
@inlinable | ||
public var end: Vector { circleArc.endPoint } | ||
} |
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,20 @@ | ||
import Geometria | ||
|
||
/// A 2-dimensional simplex composed of a line segment. | ||
public struct LineSegment2Simplex<Vector: Vector2Type>: Periodic2Simplex { | ||
/// The line segment associated with this simplex. | ||
public var lineSegment: LineSegment2<Vector> | ||
|
||
/// Initializes a new line segment simplex value with a given line segment. | ||
public init(lineSegment: LineSegment2<Vector>) { | ||
self.lineSegment = lineSegment | ||
} | ||
} | ||
|
||
extension LineSegment2Simplex { | ||
@inlinable | ||
public var start: Vector { lineSegment.start } | ||
|
||
@inlinable | ||
public var end: Vector { lineSegment.end } | ||
} |
17 changes: 17 additions & 0 deletions
17
Sources/GeometriaPeriodics/2D/Protocols/Periodic2Geometry.swift
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,17 @@ | ||
import Geometria | ||
|
||
/// A 2-dimensional periodic geometry that produces lines and circular arcs as | ||
/// periodic simplexes. | ||
public protocol Periodic2Geometry: PeriodicGeometry { | ||
/// The type of period that this periodic geometry uses to refer to its | ||
/// ordered simplexes. | ||
associatedtype Period: PeriodType | ||
|
||
/// The inclusive lower bound period within this geometry. | ||
var startPeriod: Period { get } | ||
|
||
/// The exclusive upper bound period within this geometry. | ||
/// | ||
/// This value is not part of the addressable period range. | ||
var endPeriod: Period { get } | ||
} |
11 changes: 11 additions & 0 deletions
11
Sources/GeometriaPeriodics/2D/Protocols/Periodic2Simplex.swift
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,11 @@ | ||
import Geometria | ||
|
||
/// Protocol for types that describe 2-dimensional simplexes produced by 2-dimensional | ||
/// periodic geometry. | ||
public protocol Periodic2Simplex: PeriodicSimplex where Vector: Vector2Type { | ||
/// Gets the starting point of this simplex. | ||
var start: Vector { get } | ||
|
||
/// Gets the ending point of this simplex. | ||
var end: Vector { get } | ||
} |
4 changes: 4 additions & 0 deletions
4
Sources/GeometriaPeriodics/Generalized/Protocols/PeriodType.swift
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,4 @@ | ||
/// Type for periods that can be used to refer to sections of simplexes of periodic | ||
/// geometry. | ||
public protocol PeriodType: Comparable { | ||
} |
File renamed without changes.
6 changes: 6 additions & 0 deletions
6
Sources/GeometriaPeriodics/Generalized/Protocols/PeriodicSimplex.swift
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,6 @@ | ||
import Geometria | ||
|
||
/// Protocol for types that describe simplexes produced by periodic geometry. | ||
public protocol PeriodicSimplex: GeometricType { | ||
associatedtype Vector: VectorType | ||
} |
Empty file.
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,61 @@ | ||
import XCTest | ||
|
||
@testable import Geometria | ||
|
||
class AngleSweepTests: XCTestCase { | ||
typealias Sut = AngleSweep<Double> | ||
|
||
func testIsEquivalent_equal() { | ||
assertIsEquivalent( | ||
.init(start: .pi, sweep: .pi / 2), | ||
.init(start: .pi, sweep: .pi / 2) | ||
) | ||
assertIsEquivalent( | ||
.init(start: 0.0, sweep: .pi / 2), | ||
.init(start: 0.0, sweep: .pi / 2) | ||
) | ||
assertNotIsEquivalent( | ||
.init(start: .pi, sweep: .pi / 2), | ||
.init(start: .pi / 2, sweep: .pi / 2) | ||
) | ||
} | ||
|
||
func testIsEquivalent_equivalentSweep() { | ||
assertIsEquivalent( | ||
.init(start: .pi / 2, sweep: .pi / 2), | ||
.init(start: .pi, sweep: -.pi / 2) | ||
) | ||
assertIsEquivalent( | ||
.init(start: -.pi / 2, sweep: .pi), | ||
.init(start: .pi / 2, sweep: -.pi) | ||
) | ||
} | ||
} | ||
|
||
// MARK: - Test internals | ||
|
||
private func assertIsEquivalent( | ||
_ lhs: AngleSweep<Double>, | ||
_ rhs: AngleSweep<Double>, | ||
file: StaticString = #file, | ||
line: UInt = #line | ||
) { | ||
guard !lhs.isEquivalent(to: rhs) else { | ||
return | ||
} | ||
|
||
XCTFail("\(lhs) is not equivalent to \(rhs)", file: file, line: line) | ||
} | ||
|
||
private func assertNotIsEquivalent( | ||
_ lhs: AngleSweep<Double>, | ||
_ rhs: AngleSweep<Double>, | ||
file: StaticString = #file, | ||
line: UInt = #line | ||
) { | ||
guard lhs.isEquivalent(to: rhs) else { | ||
return | ||
} | ||
|
||
XCTFail("\(lhs) is equivalent to \(rhs)", file: file, line: line) | ||
} |
Oops, something went wrong.