Begin statistics creation

This commit is contained in:
Christoph Hagen
2025-08-31 16:27:32 +02:00
parent f972a2c020
commit 96bd07bdb7
33 changed files with 1406 additions and 187 deletions

View File

@@ -11,6 +11,51 @@ struct MapImageCreator {
scale: CGFloat = 2.0,
lineWidth: CGFloat = 5,
paddingFactor: Double = 1.2,
lineColor: NSColor = .systemBlue
) -> (image: NSImage, imagePoints: [CGPoint])? {
let semaphore = DispatchSemaphore(value: 0)
var result: (image: NSImage, imagePoints: [CGPoint])?
self.createMapSnapshot(
size: layoutSize,
scale: scale,
lineWidth: lineWidth,
paddingFactor: paddingFactor,
lineColor: lineColor
) { res in
result = res
semaphore.signal()
}
semaphore.wait()
return result
}
func createMapSnapshot(
size layoutSize: CGSize,
scale: CGFloat = 2.0,
lineWidth: CGFloat = 5,
paddingFactor: Double = 1.2,
lineColor: NSColor = .systemBlue
) async -> (image: NSImage, imagePoints: [CGPoint])? {
await withCheckedContinuation { c in
self.createMapSnapshot(
size: layoutSize,
scale: scale,
lineWidth: lineWidth,
paddingFactor: paddingFactor,
lineColor: lineColor
) { c.resume(returning: $0) }
}
}
func createMapSnapshot(
size layoutSize: CGSize,
scale: CGFloat = 2.0,
lineWidth: CGFloat = 5,
paddingFactor: Double = 1.2,
lineColor: NSColor = .systemBlue,
completion: @escaping ((image: NSImage, imagePoints: [CGPoint])?) -> Void
) {
guard !locations.isEmpty else {
@@ -61,7 +106,7 @@ struct MapImageCreator {
path.line(to: point)
}
NSColor.systemBlue.setStroke()
lineColor.setStroke()
path.lineWidth = lineWidth * scale
path.stroke()
}