Files
Gas-Tank-AR-App/GasTankAR/Views/TankAR/PipeRoute.swift
2026-09-02 20:54:36 +02:00

50 lines
1.2 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// PipeRoute.swift
// GasTankAR
//
// Created by Dennis Nemec on 28.08.26.
//
import Foundation
import simd
/// Eine Rohrführung als geordnete Folge von Wegpunkten (Welt-Koordinaten), die zu einem
/// zusammenhängenden Pfad verbunden werden – visualisiert die geplante Rohrverlegung.
struct PipeRoute {
private(set) var waypoints: [SIMD3<Float>] = []
var count: Int { waypoints.count }
/// Gesamtlänge des Pfads über alle Segmente in Metern.
var totalLength: Float {
guard waypoints.count > 1 else { return 0 }
return zip(waypoints, waypoints.dropFirst())
.reduce(0) { $0 + simd_distance($1.0, $1.1) }
}
var formattedLength: String {
String(format: "%.2f m", totalLength)
}
mutating func add(_ waypoint: SIMD3<Float>) {
waypoints.append(waypoint)
}
@discardableResult
mutating func removeLast() -> SIMD3<Float>? {
waypoints.isEmpty ? nil : waypoints.removeLast()
}
mutating func clear() {
waypoints.removeAll()
}
}
/// Ablaufphasen beim Erstellen einer Rohrführung.
enum PipeRoutingPhase: Equatable {
/// Kein Rohr-Routing aktiv.
case idle
/// Wegpunkte werden gesetzt.
case placing
}