Skip to content

Commit 73423c8

Browse files
authored
Merge pull request #7 from tomasf/dev
Merge for 0.3.1
2 parents c887130 + e39f073 commit 73423c8

File tree

109 files changed

+2300
-540
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+2300
-540
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
xcuserdata/
66
/.swiftpm
77

8+
/.claude/settings.local.json

Sources/Cadova/Abstract Layer/2D/Circle/Arc.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import Foundation
99
/// let arcWithDiameter = Arc(range: 0°..<90°, diameter: 10)
1010
/// ```
1111
public struct Arc: Shape2D {
12+
/// The angular range of the arc.
1213
public let range: Range<Angle>
14+
15+
/// The radius of the arc.
1316
public let radius: Double
1417

1518
/// Creates a new `Arc` instance with the specified range of angles and radius.
@@ -30,7 +33,7 @@ public struct Arc: Shape2D {
3033
}
3134

3235
public var body: any Geometry2D {
33-
@Environment(\.segmentation) var segmentation
36+
@Environment(\.scaledSegmentation) var segmentation
3437
Polygon([.zero] + arcPoints(segmentation: segmentation))
3538
}
3639

@@ -45,6 +48,9 @@ public struct Arc: Shape2D {
4548
}
4649

4750
extension Arc: Area {
51+
/// The angular span of the arc.
4852
public var angularDistance: Angle { range.length }
53+
54+
/// The area of the circular sector.
4955
public var area: Double { radius * radius * .pi * (angularDistance / 360°) }
5056
}

Sources/Cadova/Abstract Layer/2D/Circle/Circle.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public struct Circle {
1212
/// The diameter of the circle.
1313
public let diameter: Double
1414

15+
/// The radius of the circle (half of the diameter).
1516
public var radius: Double { diameter / 2 }
1617

1718
/// Creates a new `Circle` instance with the specified diameter.
@@ -50,7 +51,7 @@ public struct Circle {
5051

5152
extension Circle: Shape2D {
5253
public var body: any Geometry2D {
53-
@Environment(\.segmentation) var segmentation
54+
@Environment(\.scaledSegmentation) var segmentation
5455
NodeBasedGeometry(.shape(.circle(radius: radius, segmentCount: segmentation.segmentCount(circleRadius: radius))))
5556
}
5657
}

Sources/Cadova/Abstract Layer/2D/Circle/Ring.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import Foundation
1010
/// let ring = Ring(outerDiameter: 10, innerDiameter: 4)
1111
/// ```
1212
public struct Ring: Shape2D {
13+
/// The outer diameter of the ring.
1314
public let outerDiameter: Double
15+
16+
/// The inner diameter of the ring (the hole).
1417
public let innerDiameter: Double
1518

1619
/// Creates a new `Ring` instance with the specified outer and inner diameters.
@@ -84,6 +87,7 @@ public struct Ring: Shape2D {
8487
}
8588

8689
extension Ring: Area {
90+
/// The area of the ring (outer circle minus inner circle).
8791
public var area: Double {
8892
Circle(diameter: outerDiameter).area - Circle(diameter: innerDiameter).area
8993
}

Sources/Cadova/Abstract Layer/2D/Metrics2D.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
import Foundation
22

3+
/// A type that has a measurable area.
4+
///
5+
/// Conforming types provide an `area` property representing the enclosed surface area.
6+
/// Many 2D shapes in Cadova conform to this protocol, including ``Circle``, ``Rectangle``,
7+
/// ``RegularPolygon``, and others.
8+
///
39
public protocol Area {
10+
/// The enclosed area of the shape.
411
var area: Double { get }
512
}
613

14+
/// A type that has a measurable perimeter.
15+
///
16+
/// Conforming types provide a `perimeter` property representing the total length of
17+
/// the shape's boundary. Many 2D shapes in Cadova conform to this protocol, including
18+
/// ``Circle`` (where it represents circumference), ``Rectangle``, ``RegularPolygon``, and others.
19+
///
720
public protocol Perimeter {
21+
/// The total length of the shape's boundary.
822
var perimeter: Double { get }
923
}
1024

1125
public extension Area {
26+
/// Calculates the volume of a pyramid with this shape as the base.
27+
///
28+
/// - Parameter height: The height of the pyramid from base to apex.
29+
/// - Returns: The volume of the pyramid.
30+
///
1231
func pyramidVolume(height: Double) -> Double {
1332
return (area * height) / 3.0
1433
}

Sources/Cadova/Abstract Layer/2D/Polygon/PolygonPoints.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ internal indirect enum PolygonPoints: Sendable, Hashable, Codable {
1010
func points(in environment: EnvironmentValues) -> [Vector2D] {
1111
switch self {
1212
case .literal (let array): array
13-
case .curve (let curve): curve.curve.points(segmentation: environment.segmentation)
13+
case .curve (let curve): curve.curve.points(segmentation: environment.scaledSegmentation)
1414
case .transformed (let polygonPoints, let transform):
1515
polygonPoints.points(in: environment)
1616
.map { transform.apply(to: $0) }

Sources/Cadova/Abstract Layer/2D/RegularPolygon.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ public extension RegularPolygon {
6666
}
6767

6868
extension RegularPolygon: Area, Perimeter {
69+
/// The area of the polygon.
6970
public var area: Double {
7071
Double(sideCount) / 2.0 * pow(circumradius, 2) * sin(360° / Double(sideCount))
7172
}
7273

74+
/// The perimeter of the polygon.
7375
public var perimeter: Double {
7476
Double(sideCount) * sideLength
7577
}

Sources/Cadova/Abstract Layer/2D/Stadium.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ public struct Stadium: Shape2D {
5454
}
5555

5656
extension Stadium: Area, Perimeter {
57+
/// The area of the stadium.
5758
public var area: Double {
5859
let diameter = min(size.x, size.y)
5960
return Double.pi * (diameter / 2) * (diameter / 2) + (max(size.x, size.y) - diameter) * diameter
6061
}
6162

63+
/// The perimeter of the stadium.
6264
public var perimeter: Double {
6365
let diameter = min(size.x, size.y)
6466
return Double.pi * diameter + 2.0 * (max(size.x, size.y) - diameter)

Sources/Cadova/Abstract Layer/2D/Text/GlyphRenderer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ internal class GlyphRenderer {
7777
FT_Outline_Decompose(&mutableOutline, &funcs, mutablePointer)
7878
}
7979
guard composeResult == 0 else { return nil }
80-
return SimplePolygonList(paths.map { SimplePolygon($0.points(segmentation: environment.segmentation)) })
80+
return SimplePolygonList(paths.map { SimplePolygon($0.points(segmentation: environment.scaledSegmentation)) })
8181
}
8282
}
8383

Sources/Cadova/Abstract Layer/2D/Text/Text.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public struct Text: Shape2D {
3232
public var body: any Geometry2D {
3333
@Environment var environment
3434
@Environment(\.textAttributes) var textAttributes
35-
@Environment(\.segmentation) var segmentation
35+
@Environment(\.scaledSegmentation) var segmentation
3636
let attributes = textAttributes.applyingDefaults()
3737

3838
CachedNode(name: "text", parameters: content, attributes, segmentation) { environment, context in

0 commit comments

Comments
 (0)