aboutsummaryrefslogtreecommitdiff
path: root/Map/Data
diff options
context:
space:
mode:
Diffstat (limited to 'Map/Data')
-rw-r--r--Map/Data/MapDocument.swift26
1 files changed, 25 insertions, 1 deletions
diff --git a/Map/Data/MapDocument.swift b/Map/Data/MapDocument.swift
index df77abf..4d3350c 100644
--- a/Map/Data/MapDocument.swift
+++ b/Map/Data/MapDocument.swift
@@ -60,9 +60,33 @@ struct MapDocument: FileDocument {
@MainActor
func exportAsImage(withEvolution selectedEvolution: StageType) -> NSImage? {
+ let renderableMap = RenderableMap.from(self.parsed)
+ let mapSize = Dimensions.Map.size
+ let vertexSize = CGSize(width: 25.0, height: 25.0)
+ let useSmartLabels = UserDefaults.standard.bool(forKey: "useSmartLabelPositioning")
+
+ var labelPositions: [Int: CGPoint] = [:]
+ if useSmartLabels {
+ let axisLines = [
+ Line(start: CGPoint(x: 0, y: 0), end: CGPoint(x: 0, y: mapSize.height)),
+ Line(
+ start: CGPoint(x: 0, y: mapSize.height),
+ end: CGPoint(x: mapSize.width, y: mapSize.height)),
+ ]
+ for vertex in renderableMap.vertices {
+ labelPositions[vertex.id] = SmartLabelPositioning.calculateOptimalLabelPosition(
+ for: vertex, mapSize: mapSize, vertexSize: vertexSize,
+ edges: renderableMap.edges, opportunities: renderableMap.opportunities,
+ inertias: renderableMap.inertias, axisLines: axisLines,
+ allVertices: renderableMap.vertices, notes: renderableMap.notes)
+ }
+ }
+
let renderView = MapRenderView(
parsedMap: self.parsed,
- evolution: .constant(selectedEvolution))
+ evolution: .constant(selectedEvolution),
+ precomputedMap: renderableMap,
+ precomputedLabelPositions: labelPositions)
let renderer = ImageRenderer(content: renderView)
return renderer.nsImage