Skip to content

Commit 5e4c73d

Browse files
committed
Add Geometry.worldTransform
1 parent 640d456 commit 5e4c73d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

ShapeScript/Geometry.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public final class Geometry: Hashable {
1717
public let children: [Geometry]
1818
public let isOpaque: Bool // Computed
1919
public let sourceLocation: SourceLocation?
20+
public private(set) weak var parent: Geometry?
2021

2122
public func hash(into hasher: inout Hasher) {
2223
hasher.combine(type)
@@ -232,6 +233,9 @@ public final class Geometry: Hashable {
232233

233234
// Must be set after cache key is generated
234235
self.isOpaque = isOpaque
236+
237+
// Must be set after all other properties
238+
children.forEach { $0.parent = self }
235239
}
236240
}
237241

@@ -265,6 +269,10 @@ public extension Geometry {
265269
}
266270
}
267271

272+
var worldTransform: Transform {
273+
(parent?.worldTransform ?? .identity) * transform
274+
}
275+
268276
internal func gatherNamedObjects(_ dictionary: inout [String: Geometry]) {
269277
if let name = self.name {
270278
dictionary[name] = self

0 commit comments

Comments
 (0)