feat: Bogenparameter nachträglich bearbeiten
- Auswahlmodus mit Start-, End- und Bogen-Griff - Bogen-Griff ändert Tiefe und Seite, Endpunkte verschieben die Kurve - Bogen-Metadaten (Template, Tiefe, Seite) am PathSegment gespeichert - ArcGeometry als eigenständige, headless testbare Geometrie - Ghost-Sections bleiben nicht interaktiv - Tests auf 203 Assertions erweitert
This commit is contained in:
parent
36e25aa559
commit
c609f065dd
9 changed files with 803 additions and 130 deletions
|
|
@ -92,15 +92,22 @@ eine Abkürzung. So kann die UI Fehler konkret anzeigen.
|
|||
- **Controller** übersetzt Touch-/Maus-Eingaben in Modelloperationen
|
||||
(Segment anlegen, Kante umschalten, Section wechseln, Playback steuern).
|
||||
- **Zeichenwerkzeuge:** `WhiteboardController` hält eine Draft-Routine mit
|
||||
einer Section. Die Toolbar bietet Navigieren, Linie, Bogen links und Bogen
|
||||
einer Section. Die Toolbar bietet Auswählen, Linie, Bogen links und Bogen
|
||||
rechts; Richtung (vorwärts/rückwärts) und Kante (innen/außen) gelten für das
|
||||
nächste Segment. Die Dauer wird mit 6 m/s aus der Länge abgeleitet, Züge
|
||||
über die Bande werden per `clamp_point()` auf die Eisfläche begrenzt.
|
||||
- **Bogen-Vorlage:** Der Bogen wird als Kreisbogen mit 40 % der Sehnenlänge
|
||||
als Pfeilhöhe erzeugt und als `Curve2D`-Polyline gespeichert. Liegt der
|
||||
Bogen außerhalb des Rinks, wird die Pfeilhöhe schrittweise reduziert; die
|
||||
gerade Sehne ist der letzte Fallback. Die Bogen-Seite ist relativ zur
|
||||
Ziehrichtung (Start → Ende) definiert.
|
||||
- **Bogen-Vorlage:** `ArcGeometry` erzeugt einen Kreisbogen mit 40 % der
|
||||
Sehnenlänge als Pfeilhöhe und liefert eine gesampelte `Curve2D`-Polyline.
|
||||
Liegt der Bogen außerhalb des Rinks, wird die Pfeilhöhe schrittweise
|
||||
reduziert; die gerade Sehne ist der letzte Fallback. Die Bogen-Seite ist
|
||||
relativ zur Ziehrichtung (Start → Ende) definiert.
|
||||
- **Auswahl und Bearbeitung:** Im Modus „Auswählen“ pickt ein Tipp auf das
|
||||
aktive Segment. Start- und Endpunkt haben weiße Griffe, Bögen zusätzlich
|
||||
einen orangen Bogen-Griff. Endpunkt-Griffe verschieben die Kurve, der
|
||||
Bogen-Griff ändert Tiefe und Seite. Ghost-Sections sind nicht interaktiv.
|
||||
Die Bogenparameter werden als `template`, `arc_depth_ratio` und
|
||||
`arc_bulge_left` am `PathSegment` gespeichert, damit die Kurve nach dem
|
||||
Editieren neu aufgebaut werden kann.
|
||||
- **Darstellung:** vorwärts durchgezogen, rückwärts gestrichelt, außen rot,
|
||||
innen blau. Inaktive Sections werden mit 20 % Deckkraft geghostet.
|
||||
- **Ghosting** ist reine View-Logik: pro Section ein eigener Layer,
|
||||
|
|
@ -148,13 +155,13 @@ Headless, ohne Editor und ohne Display:
|
|||
|
||||
Aktueller Stand:
|
||||
|
||||
- **Model:** 42 Assertions für Rink-Geometrie, Clamping, Segment-Timing,
|
||||
Section-Aggregation und Routine-Validierung.
|
||||
- **Canvas:** 67 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan und die
|
||||
Rink-Kontur inklusive Eckradien.
|
||||
- **Whiteboard:** 55 Assertions für Controller-Verdrahtung, Segmenterzeugung,
|
||||
Linien-/Bogenpfade, Klemmen an der Bande, Undo, Navigationsmodus und den
|
||||
Maus-Drag-Pfad.
|
||||
- **Model:** 45 Assertions für Rink-Geometrie, Clamping, Segment-Timing,
|
||||
Template-Metadaten, Section-Aggregation und Routine-Validierung.
|
||||
- **Canvas:** 90 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan,
|
||||
Rink-Kontur und die reine Bogen-Geometrie.
|
||||
- **Whiteboard:** 68 Assertions für Controller-Verdrahtung, Segmenterzeugung,
|
||||
Linien-/Bogenpfade, Klemmen an der Bande, Auswahl, Griff-Bearbeitung, Undo,
|
||||
Navigationsmodus und den Maus-Drag-Pfad.
|
||||
|
||||
Visuelle Smoke-Tests laufen zusätzlich über `xvfb-run` und einen
|
||||
Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
||||
|
|
@ -171,9 +178,9 @@ Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
|||
4. **Section-Übergänge:** Ob Sections eine explizite Startzeit erhalten oder
|
||||
ausschließlich aus Segmentdauern abgeleitet werden, klärt die
|
||||
Playback-Implementierung.
|
||||
5. **Kurven und Templates:** Linie und Kreisbogen sind umgesetzt. Offen sind
|
||||
Freihand, das nachträgliche Bearbeiten von Bogenparametern (Start/Ende,
|
||||
Seite, Tiefe) sowie weitere Templates wie Acht und Dreier.
|
||||
6. **Bogen-Metadaten:** Der Bogen wird aktuell als gesampelte Kurve
|
||||
gespeichert. Für spätere Parameter-Editierung sollte `PathSegment` die
|
||||
Template-Art und ihre Parameter zusätzlich als Metadaten tragen.
|
||||
5. **Kurven und Templates:** Linie, Kreisbogen und die Bearbeitung von
|
||||
Start/Ende, Seite und Tiefe sind umgesetzt. Offen sind Freihand sowie
|
||||
weitere Templates wie Acht und Dreier.
|
||||
6. **Segment-Verknüpfung:** Beim Verschieben eines Endpunkts werden
|
||||
Nachbarsegmente nicht automatisch mitgezogen. Ob Pfade später als
|
||||
zusammenhängende Kette editiert werden, ist offen.
|
||||
|
|
|
|||
128
rinkplanner/src/core/model/arc_geometry.gd
Normal file
128
rinkplanner/src/core/model/arc_geometry.gd
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
class_name ArcGeometry
|
||||
extends RefCounted
|
||||
|
||||
## Pure circular-arc geometry for the lobe template. Given a chord, a side and
|
||||
## a depth ratio, the builder returns a sampled curve that stays on the rink.
|
||||
## No Node dependencies, so it is fully headless-testable.
|
||||
|
||||
const DEFAULT_DEPTH_RATIO := 0.4
|
||||
const MIN_DEPTH_RATIO := 0.02
|
||||
const MAX_DEPTH_RATIO := 0.49
|
||||
const CLAMP_ATTEMPTS := 6
|
||||
const CLAMP_FACTOR := 0.75
|
||||
const MIN_STEPS := 8
|
||||
const STEP_ANGLE := PI / 24.0
|
||||
const EPSILON := 0.0001
|
||||
|
||||
|
||||
## Builds an arc from [param start] to [param end]. The bulge is left or right
|
||||
## of the chord (start -> end). If the arc would leave [param rink], the depth
|
||||
## is reduced stepwise; the straight chord is the final fallback.
|
||||
static func build_points(
|
||||
start: Vector2,
|
||||
end: Vector2,
|
||||
bulge_left: bool,
|
||||
depth_ratio: float,
|
||||
rink: RinkDimensions
|
||||
) -> PackedVector2Array:
|
||||
var clamped_start := start
|
||||
var clamped_end := end
|
||||
if rink != null:
|
||||
clamped_start = rink.clamp_point(start)
|
||||
clamped_end = rink.clamp_point(end)
|
||||
|
||||
var chord := clamped_end - clamped_start
|
||||
var chord_length := chord.length()
|
||||
if chord_length <= EPSILON:
|
||||
return PackedVector2Array([clamped_start, clamped_end])
|
||||
|
||||
var normal := Vector2(-chord.y, chord.x) / chord_length
|
||||
if not bulge_left:
|
||||
normal = -normal
|
||||
|
||||
var sagitta := chord_length * clampf(
|
||||
depth_ratio,
|
||||
MIN_DEPTH_RATIO,
|
||||
MAX_DEPTH_RATIO
|
||||
)
|
||||
for attempt: int in range(CLAMP_ATTEMPTS + 1):
|
||||
var points := points_with_sagitta(
|
||||
clamped_start,
|
||||
clamped_end,
|
||||
normal,
|
||||
sagitta
|
||||
)
|
||||
if rink == null or points_inside_rink(points, rink):
|
||||
return points
|
||||
sagitta *= CLAMP_FACTOR
|
||||
|
||||
return PackedVector2Array([clamped_start, clamped_end])
|
||||
|
||||
|
||||
static func points_with_sagitta(
|
||||
start: Vector2,
|
||||
end: Vector2,
|
||||
normal: Vector2,
|
||||
sagitta: float
|
||||
) -> PackedVector2Array:
|
||||
var chord := end - start
|
||||
var chord_length := chord.length()
|
||||
var midpoint := (start + end) * 0.5
|
||||
var radius := (
|
||||
chord_length * chord_length * 0.25 + sagitta * sagitta
|
||||
) / (2.0 * sagitta)
|
||||
var center := midpoint - normal * (radius - sagitta)
|
||||
|
||||
var start_angle := (start - center).angle()
|
||||
var end_angle := (end - center).angle()
|
||||
var delta := wrapf(end_angle - start_angle, -PI, PI)
|
||||
var steps: int = maxi(MIN_STEPS, ceili(absf(delta) / STEP_ANGLE))
|
||||
|
||||
var points := PackedVector2Array()
|
||||
points.resize(steps + 1)
|
||||
for index: int in range(steps + 1):
|
||||
var angle := start_angle + delta * float(index) / float(steps)
|
||||
points[index] = center + Vector2(cos(angle), sin(angle)) * radius
|
||||
|
||||
points[0] = start
|
||||
points[steps] = end
|
||||
return points
|
||||
|
||||
|
||||
static func points_inside_rink(
|
||||
points: PackedVector2Array,
|
||||
rink: RinkDimensions
|
||||
) -> bool:
|
||||
for point: Vector2 in points:
|
||||
if not rink.contains_point(point):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
## Depth ratio implied by dragging [param point] relative to the chord.
|
||||
static func depth_ratio_for_point(
|
||||
start: Vector2,
|
||||
end: Vector2,
|
||||
point: Vector2
|
||||
) -> float:
|
||||
var chord := end - start
|
||||
var chord_length := chord.length()
|
||||
if chord_length <= EPSILON:
|
||||
return DEFAULT_DEPTH_RATIO
|
||||
|
||||
var normal := Vector2(-chord.y, chord.x) / chord_length
|
||||
var midpoint := (start + end) * 0.5
|
||||
return clampf(
|
||||
absf((point - midpoint).dot(normal)) / chord_length,
|
||||
MIN_DEPTH_RATIO,
|
||||
MAX_DEPTH_RATIO
|
||||
)
|
||||
|
||||
|
||||
static func is_left_of_chord(start: Vector2, end: Vector2, point: Vector2) -> bool:
|
||||
var chord := end - start
|
||||
if chord.length() <= EPSILON:
|
||||
return true
|
||||
var normal := Vector2(-chord.y, chord.x).normalized()
|
||||
var midpoint := (start + end) * 0.5
|
||||
return (point - midpoint).dot(normal) >= 0.0
|
||||
1
rinkplanner/src/core/model/arc_geometry.gd.uid
Normal file
1
rinkplanner/src/core/model/arc_geometry.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dlyqepeh6xm4i
|
||||
|
|
@ -16,6 +16,11 @@ enum Edge {
|
|||
OUTSIDE,
|
||||
}
|
||||
|
||||
enum Template {
|
||||
LINE,
|
||||
ARC,
|
||||
}
|
||||
|
||||
@export var segment_id: String = ""
|
||||
@export var curve: Curve2D
|
||||
@export var direction: Direction = Direction.FORWARD
|
||||
|
|
@ -24,6 +29,13 @@ enum Edge {
|
|||
@export var element_id: String = ""
|
||||
@export var label: String = ""
|
||||
|
||||
## Geometry metadata. Start and end are always the first and last curve points;
|
||||
## the remaining values describe how the curve was generated so it can be
|
||||
## rebuilt after editing.
|
||||
@export var template: Template = Template.LINE
|
||||
@export var arc_depth_ratio: float = 0.4
|
||||
@export var arc_bulge_left: bool = true
|
||||
|
||||
|
||||
func get_length_m() -> float:
|
||||
if curve == null:
|
||||
|
|
@ -43,6 +55,10 @@ func is_marker() -> bool:
|
|||
return get_length_m() <= 0.0
|
||||
|
||||
|
||||
func is_arc() -> bool:
|
||||
return template == Template.ARC
|
||||
|
||||
|
||||
func validate() -> PackedStringArray:
|
||||
var errors := PackedStringArray()
|
||||
|
||||
|
|
@ -56,6 +72,9 @@ func validate() -> PackedStringArray:
|
|||
errors.append("duration_seconds must not be negative")
|
||||
if duration_seconds <= 0.0 and not is_marker():
|
||||
errors.append("a segment with length needs a positive duration_seconds")
|
||||
if template == Template.ARC:
|
||||
if arc_depth_ratio <= 0.0 or arc_depth_ratio >= 0.5:
|
||||
errors.append("arc_depth_ratio must be between 0 and 0.5")
|
||||
|
||||
return errors
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ extends Control
|
|||
## canvas gestures into model mutations and keeps the toolbar/status in sync.
|
||||
|
||||
enum Tool {
|
||||
NAVIGATE,
|
||||
SELECT,
|
||||
LINE,
|
||||
ARC_LEFT,
|
||||
ARC_RIGHT,
|
||||
|
|
@ -13,11 +13,6 @@ enum Tool {
|
|||
|
||||
const DEFAULT_SPEED_MPS := 6.0
|
||||
const MIN_SEGMENT_LENGTH_M := 0.3
|
||||
const ARC_DEPTH_RATIO := 0.4
|
||||
const ARC_MIN_STEPS := 8
|
||||
const ARC_STEP_ANGLE := PI / 24.0
|
||||
const ARC_CLAMP_ATTEMPTS := 6
|
||||
const ARC_CLAMP_FACTOR := 0.75
|
||||
const EPSILON := 0.0001
|
||||
|
||||
@onready var rink_canvas: RinkCanvas = %RinkCanvas
|
||||
|
|
@ -33,6 +28,7 @@ const EPSILON := 0.0001
|
|||
var _routine: Routine
|
||||
var _active_section: RoutineSection
|
||||
var _current_segment: PathSegment
|
||||
var _selected_segment_id: String = ""
|
||||
var _segment_counter: int = 0
|
||||
var _tool: Tool = Tool.LINE
|
||||
var _direction: PathSegment.Direction = PathSegment.Direction.FORWARD
|
||||
|
|
@ -75,6 +71,11 @@ func _ready() -> void:
|
|||
rink_canvas.draw_updated.connect(_on_draw_updated)
|
||||
rink_canvas.draw_finished.connect(_on_draw_finished)
|
||||
rink_canvas.draw_cancelled.connect(_on_draw_cancelled)
|
||||
rink_canvas.segment_selected.connect(_on_segment_selected)
|
||||
rink_canvas.selection_cleared.connect(_on_selection_cleared)
|
||||
rink_canvas.segment_handle_drag_started.connect(_on_handle_drag_started)
|
||||
rink_canvas.segment_handle_dragged.connect(_on_handle_dragged)
|
||||
rink_canvas.segment_handle_drag_finished.connect(_on_handle_drag_finished)
|
||||
|
||||
_update_status()
|
||||
|
||||
|
|
@ -91,6 +92,21 @@ func get_tool() -> Tool:
|
|||
return _tool
|
||||
|
||||
|
||||
func get_selected_segment() -> PathSegment:
|
||||
return _find_segment(_selected_segment_id)
|
||||
|
||||
|
||||
## Selects a segment programmatically and switches to the select tool.
|
||||
func select_segment(segment_id: String) -> void:
|
||||
if _find_segment(segment_id) == null:
|
||||
return
|
||||
if _tool != Tool.SELECT:
|
||||
set_tool(Tool.SELECT)
|
||||
_selected_segment_id = segment_id
|
||||
rink_canvas.set_selected_segment(segment_id)
|
||||
_update_status()
|
||||
|
||||
|
||||
## Selects a tool programmatically and keeps the toolbar in sync.
|
||||
func set_tool(tool: Tool) -> void:
|
||||
_apply_tool(tool)
|
||||
|
|
@ -123,14 +139,18 @@ func undo_last_segment() -> void:
|
|||
if _active_section == null or _active_section.segments.is_empty():
|
||||
return
|
||||
|
||||
_active_section.segments.pop_back()
|
||||
var removed: PathSegment = _active_section.segments.pop_back()
|
||||
if removed != null and removed.segment_id == _selected_segment_id:
|
||||
_selected_segment_id = ""
|
||||
rink_canvas.set_selected_segment("")
|
||||
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _setup_tool_options() -> void:
|
||||
tool_option.clear()
|
||||
tool_option.add_item("Navigieren", Tool.NAVIGATE)
|
||||
tool_option.add_item("Auswählen", Tool.SELECT)
|
||||
tool_option.add_item("Linie", Tool.LINE)
|
||||
tool_option.add_item("Bogen links", Tool.ARC_LEFT)
|
||||
tool_option.add_item("Bogen rechts", Tool.ARC_RIGHT)
|
||||
|
|
@ -144,13 +164,16 @@ func _on_tool_selected(index: int) -> void:
|
|||
|
||||
func _apply_tool(tool: Tool) -> void:
|
||||
_tool = tool
|
||||
rink_canvas.set_drawing_enabled(tool != Tool.NAVIGATE)
|
||||
var selecting := tool == Tool.SELECT
|
||||
rink_canvas.set_drawing_enabled(not selecting)
|
||||
rink_canvas.set_selection_enabled(selecting)
|
||||
_update_status()
|
||||
|
||||
|
||||
func _tool_from_id(tool_id: int) -> Tool:
|
||||
match tool_id:
|
||||
Tool.NAVIGATE:
|
||||
return Tool.NAVIGATE
|
||||
Tool.SELECT:
|
||||
return Tool.SELECT
|
||||
Tool.LINE:
|
||||
return Tool.LINE
|
||||
Tool.ARC_LEFT:
|
||||
|
|
@ -206,6 +229,91 @@ func _on_draw_cancelled() -> void:
|
|||
_update_status()
|
||||
|
||||
|
||||
func _on_segment_selected(segment_id: String) -> void:
|
||||
_selected_segment_id = segment_id
|
||||
rink_canvas.set_selected_segment(segment_id)
|
||||
_update_status()
|
||||
|
||||
|
||||
func _on_selection_cleared() -> void:
|
||||
_selected_segment_id = ""
|
||||
_update_status()
|
||||
|
||||
|
||||
func _on_handle_drag_started(segment_id: String, _handle: int) -> void:
|
||||
_selected_segment_id = segment_id
|
||||
_update_status()
|
||||
|
||||
|
||||
func _on_handle_dragged(
|
||||
segment_id: String,
|
||||
handle: int,
|
||||
model_point: Vector2
|
||||
) -> void:
|
||||
var segment := _find_segment(segment_id)
|
||||
if segment == null:
|
||||
return
|
||||
|
||||
_apply_handle_drag(segment, handle, model_point)
|
||||
rink_canvas.refresh()
|
||||
_update_status()
|
||||
|
||||
|
||||
func _on_handle_drag_finished(
|
||||
segment_id: String,
|
||||
handle: int,
|
||||
model_point: Vector2
|
||||
) -> void:
|
||||
_on_handle_dragged(segment_id, handle, model_point)
|
||||
|
||||
|
||||
func _apply_handle_drag(
|
||||
segment: PathSegment,
|
||||
handle: int,
|
||||
model_point: Vector2
|
||||
) -> void:
|
||||
if segment.curve == null or segment.curve.point_count < 2:
|
||||
return
|
||||
|
||||
var start := segment.curve.get_point_position(0)
|
||||
var end := segment.curve.get_point_position(segment.curve.point_count - 1)
|
||||
|
||||
match handle:
|
||||
RinkCanvas.Handle.START:
|
||||
start = _routine.rink.clamp_point(model_point)
|
||||
_rebuild_segment(segment, start, end)
|
||||
RinkCanvas.Handle.END:
|
||||
end = _routine.rink.clamp_point(model_point)
|
||||
_rebuild_segment(segment, start, end)
|
||||
RinkCanvas.Handle.BULGE:
|
||||
if not segment.is_arc():
|
||||
return
|
||||
if start.distance_to(end) <= EPSILON:
|
||||
return
|
||||
var depth := ArcGeometry.depth_ratio_for_point(start, end, model_point)
|
||||
var bulge_left := ArcGeometry.is_left_of_chord(start, end, model_point)
|
||||
_set_arc_geometry(segment, start, end, bulge_left, depth)
|
||||
|
||||
|
||||
func _rebuild_segment(segment: PathSegment, start: Vector2, end: Vector2) -> void:
|
||||
if segment.is_arc():
|
||||
_set_arc_geometry(
|
||||
segment,
|
||||
start,
|
||||
end,
|
||||
segment.arc_bulge_left,
|
||||
segment.arc_depth_ratio
|
||||
)
|
||||
else:
|
||||
_set_line_geometry(segment, start, end)
|
||||
|
||||
|
||||
func _find_segment(segment_id: String) -> PathSegment:
|
||||
if _active_section == null or segment_id.is_empty():
|
||||
return null
|
||||
return _active_section.get_segment_by_id(segment_id)
|
||||
|
||||
|
||||
func _create_segment(
|
||||
start: Vector2,
|
||||
direction: PathSegment.Direction,
|
||||
|
|
@ -237,105 +345,77 @@ func _update_segment_geometry(
|
|||
|
||||
var start := segment.curve.get_point_position(0)
|
||||
var clamped_end := _routine.rink.clamp_point(end)
|
||||
var is_arc_tool := tool == Tool.ARC_LEFT or tool == Tool.ARC_RIGHT
|
||||
|
||||
if tool == Tool.LINE or start.distance_to(clamped_end) <= EPSILON:
|
||||
_set_straight_curve(segment.curve, start, clamped_end)
|
||||
if not is_arc_tool or start.distance_to(clamped_end) <= EPSILON:
|
||||
_set_line_geometry(segment, start, clamped_end)
|
||||
else:
|
||||
var arc_points := _build_arc_points(
|
||||
_set_arc_geometry(
|
||||
segment,
|
||||
start,
|
||||
clamped_end,
|
||||
tool == Tool.ARC_LEFT
|
||||
tool == Tool.ARC_LEFT,
|
||||
ArcGeometry.DEFAULT_DEPTH_RATIO
|
||||
)
|
||||
_set_curve_points(segment.curve, arc_points)
|
||||
|
||||
|
||||
func _set_line_geometry(
|
||||
segment: PathSegment,
|
||||
start: Vector2,
|
||||
end: Vector2
|
||||
) -> void:
|
||||
segment.template = PathSegment.Template.LINE
|
||||
var curve := segment.curve
|
||||
curve.clear_points()
|
||||
curve.add_point(start)
|
||||
curve.add_point(end)
|
||||
_update_duration(segment)
|
||||
|
||||
|
||||
func _set_arc_geometry(
|
||||
segment: PathSegment,
|
||||
start: Vector2,
|
||||
end: Vector2,
|
||||
bulge_left: bool,
|
||||
depth_ratio: float
|
||||
) -> void:
|
||||
segment.template = PathSegment.Template.ARC
|
||||
segment.arc_bulge_left = bulge_left
|
||||
segment.arc_depth_ratio = clampf(
|
||||
depth_ratio,
|
||||
ArcGeometry.MIN_DEPTH_RATIO,
|
||||
ArcGeometry.MAX_DEPTH_RATIO
|
||||
)
|
||||
|
||||
var points := ArcGeometry.build_points(
|
||||
start,
|
||||
end,
|
||||
bulge_left,
|
||||
segment.arc_depth_ratio,
|
||||
_routine.rink
|
||||
)
|
||||
var curve := segment.curve
|
||||
curve.clear_points()
|
||||
for point: Vector2 in points:
|
||||
curve.add_point(point)
|
||||
_update_duration(segment)
|
||||
|
||||
|
||||
func _update_duration(segment: PathSegment) -> void:
|
||||
segment.duration_seconds = maxf(
|
||||
segment.get_length_m() / DEFAULT_SPEED_MPS,
|
||||
0.001
|
||||
)
|
||||
|
||||
|
||||
func _set_straight_curve(curve: Curve2D, start: Vector2, end: Vector2) -> void:
|
||||
curve.clear_points()
|
||||
curve.add_point(start)
|
||||
curve.add_point(end)
|
||||
|
||||
|
||||
func _set_curve_points(curve: Curve2D, points: PackedVector2Array) -> void:
|
||||
if points.size() < 2:
|
||||
return
|
||||
curve.clear_points()
|
||||
for point: Vector2 in points:
|
||||
curve.add_point(point)
|
||||
|
||||
|
||||
## Builds a circular arc between two points. If the bulge would leave the rink,
|
||||
## the sagitta is reduced step by step; the straight chord is the final fallback.
|
||||
func _build_arc_points(
|
||||
start: Vector2,
|
||||
end: Vector2,
|
||||
bulge_left: bool
|
||||
) -> PackedVector2Array:
|
||||
var chord := end - start
|
||||
var chord_length := chord.length()
|
||||
if chord_length <= EPSILON:
|
||||
return PackedVector2Array([start, end])
|
||||
|
||||
var normal := Vector2(-chord.y, chord.x) / chord_length
|
||||
if not bulge_left:
|
||||
normal = -normal
|
||||
|
||||
var sagitta := chord_length * ARC_DEPTH_RATIO
|
||||
for attempt: int in range(ARC_CLAMP_ATTEMPTS + 1):
|
||||
var points := _arc_points_with_sagitta(start, end, normal, sagitta)
|
||||
if _points_inside_rink(points):
|
||||
return points
|
||||
sagitta *= ARC_CLAMP_FACTOR
|
||||
|
||||
return PackedVector2Array([start, end])
|
||||
|
||||
|
||||
func _arc_points_with_sagitta(
|
||||
start: Vector2,
|
||||
end: Vector2,
|
||||
normal: Vector2,
|
||||
sagitta: float
|
||||
) -> PackedVector2Array:
|
||||
var chord := end - start
|
||||
var chord_length := chord.length()
|
||||
var midpoint := (start + end) * 0.5
|
||||
var radius := (
|
||||
chord_length * chord_length * 0.25 + sagitta * sagitta
|
||||
) / (2.0 * sagitta)
|
||||
var center := midpoint - normal * (radius - sagitta)
|
||||
|
||||
var start_angle := (start - center).angle()
|
||||
var end_angle := (end - center).angle()
|
||||
var delta := wrapf(end_angle - start_angle, -PI, PI)
|
||||
var steps: int = maxi(ARC_MIN_STEPS, ceili(absf(delta) / ARC_STEP_ANGLE))
|
||||
|
||||
var points := PackedVector2Array()
|
||||
points.resize(steps + 1)
|
||||
for index: int in range(steps + 1):
|
||||
var angle := start_angle + delta * float(index) / float(steps)
|
||||
points[index] = center + Vector2(cos(angle), sin(angle)) * radius
|
||||
|
||||
points[0] = start
|
||||
points[steps] = end
|
||||
return points
|
||||
|
||||
|
||||
func _points_inside_rink(points: PackedVector2Array) -> bool:
|
||||
for point: Vector2 in points:
|
||||
if not _routine.rink.contains_point(point):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
func _update_status() -> void:
|
||||
if _routine == null or _active_section == null:
|
||||
return
|
||||
|
||||
var segment_count := _active_section.segments.size()
|
||||
var segment_word := "Segment" if segment_count == 1 else "Segmente"
|
||||
status_label.text = (
|
||||
"%s · %d %s · %.1f s | Links ziehen: zeichnen · Mitte/2 Finger: pan · Rad/Pinch: zoom"
|
||||
var text := (
|
||||
"%s · %d %s · %.1f s"
|
||||
% [
|
||||
_active_section.title,
|
||||
segment_count,
|
||||
|
|
@ -343,3 +423,21 @@ func _update_status() -> void:
|
|||
_routine.get_duration_seconds(),
|
||||
]
|
||||
)
|
||||
|
||||
var selected := get_selected_segment()
|
||||
if selected != null:
|
||||
if selected.is_arc():
|
||||
var side := "links" if selected.arc_bulge_left else "rechts"
|
||||
text += " | Auswahl: Bogen %s · Tiefe %d %%" % [
|
||||
side,
|
||||
roundi(selected.arc_depth_ratio * 100.0),
|
||||
]
|
||||
else:
|
||||
text += " | Auswahl: Linie"
|
||||
|
||||
var hint := (
|
||||
"Tippen: auswählen · Griffe ziehen: bearbeiten · leere Fläche: pan"
|
||||
if _tool == Tool.SELECT
|
||||
else "Links ziehen: zeichnen · Mitte/2 Finger: pan · Rad/Pinch: zoom"
|
||||
)
|
||||
status_label.text = "%s | %s" % [text, hint]
|
||||
|
|
|
|||
|
|
@ -4,13 +4,25 @@ extends Control
|
|||
## Phase 1 whiteboard canvas: draws the rink and authored paths in meters.
|
||||
##
|
||||
## The view owns no routine data. It renders what the controller assigns and
|
||||
## translates raw pointer gestures into high-level draw signals.
|
||||
## translates raw pointer gestures into high-level draw/selection signals.
|
||||
|
||||
signal view_changed
|
||||
signal draw_started(model_point: Vector2)
|
||||
signal draw_updated(model_point: Vector2)
|
||||
signal draw_finished(model_point: Vector2)
|
||||
signal draw_cancelled
|
||||
signal segment_selected(segment_id: String)
|
||||
signal selection_cleared
|
||||
signal segment_handle_drag_started(segment_id: String, handle: int)
|
||||
signal segment_handle_dragged(segment_id: String, handle: int, model_point: Vector2)
|
||||
signal segment_handle_drag_finished(segment_id: String, handle: int, model_point: Vector2)
|
||||
|
||||
enum Handle {
|
||||
NONE,
|
||||
START,
|
||||
END,
|
||||
BULGE,
|
||||
}
|
||||
|
||||
const BACKGROUND_COLOR := Color("#0b1220")
|
||||
const ICE_COLOR := Color("#eef6fb")
|
||||
|
|
@ -19,12 +31,19 @@ const CENTER_LINE_COLOR := Color("#dc2626")
|
|||
const CIRCLE_COLOR := Color("#94a3b8")
|
||||
const OUTSIDE_EDGE_COLOR := Color("#DC2626")
|
||||
const INSIDE_EDGE_COLOR := Color("#2563EB")
|
||||
const SELECTION_HALO_COLOR := Color(1.0, 1.0, 1.0, 0.5)
|
||||
const HANDLE_FILL_COLOR := Color("#f8fafc")
|
||||
const HANDLE_BORDER_COLOR := Color("#0f172a")
|
||||
const BULGE_HANDLE_COLOR := Color("#f59e0b")
|
||||
const OUTLINE_ARC_SEGMENTS := 12
|
||||
const CENTER_CIRCLE_RADIUS_M := 4.5
|
||||
const CENTER_CIRCLE_SEGMENTS := 64
|
||||
const GHOST_ALPHA := 0.2
|
||||
const CURVE_SAMPLE_STEP_PX := 3.0
|
||||
const MAX_CURVE_SAMPLES := 2000
|
||||
const SEGMENT_HIT_RADIUS_PX := 14.0
|
||||
const HANDLE_HIT_RADIUS_PX := 22.0
|
||||
const HANDLE_RADIUS_PX := 7.0
|
||||
|
||||
@export var fit_padding_px: float = 32.0
|
||||
@export var drawing_enabled: bool = true
|
||||
|
|
@ -43,6 +62,13 @@ var _pan_touch_index: int = -1
|
|||
var _pinch_center: Vector2 = Vector2.ZERO
|
||||
var _pinch_distance: float = 0.0
|
||||
|
||||
var _selection_enabled: bool = false
|
||||
var _selected_segment_id: String = ""
|
||||
var _handle_drag: Handle = Handle.NONE
|
||||
var _handle_drag_segment_id: String = ""
|
||||
var _handle_touch_index: int = -1
|
||||
var _last_handle_model_point: Vector2 = Vector2.ZERO
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
focus_mode = Control.FOCUS_ALL
|
||||
|
|
@ -84,6 +110,24 @@ func set_drawing_enabled(enabled: bool) -> void:
|
|||
_cancel_drawing()
|
||||
|
||||
|
||||
func set_selection_enabled(enabled: bool) -> void:
|
||||
if _selection_enabled == enabled:
|
||||
return
|
||||
_selection_enabled = enabled
|
||||
if not enabled:
|
||||
_abort_handle_drag()
|
||||
_clear_selection()
|
||||
|
||||
|
||||
func set_selected_segment(segment_id: String) -> void:
|
||||
_selected_segment_id = segment_id
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func get_selected_segment_id() -> String:
|
||||
return _selected_segment_id
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
queue_redraw()
|
||||
|
||||
|
|
@ -113,6 +157,7 @@ func _draw() -> void:
|
|||
|
||||
_draw_center_line()
|
||||
_draw_center_circle()
|
||||
_draw_selection_highlight()
|
||||
_draw_routine()
|
||||
|
||||
if outline.size() >= 3:
|
||||
|
|
@ -126,6 +171,8 @@ func _draw() -> void:
|
|||
true
|
||||
)
|
||||
|
||||
_draw_selection_handles()
|
||||
|
||||
|
||||
func _draw_center_line() -> void:
|
||||
var half_width := _rink.get_half_width()
|
||||
|
|
@ -186,7 +233,7 @@ func _draw_segment(segment: PathSegment, alpha: float) -> void:
|
|||
|
||||
var color := _edge_color(segment.edge)
|
||||
color.a *= alpha
|
||||
var width := maxf(3.0, 0.12 * _transform.pixels_per_meter)
|
||||
var width := _segment_width()
|
||||
|
||||
if points.size() == 1:
|
||||
draw_circle(points[0], width, color)
|
||||
|
|
@ -203,6 +250,52 @@ func _draw_segment(segment: PathSegment, alpha: float) -> void:
|
|||
_draw_arrow_head(points, color)
|
||||
|
||||
|
||||
func _draw_selection_highlight() -> void:
|
||||
var segment := _get_selected_segment()
|
||||
if segment == null:
|
||||
return
|
||||
|
||||
var points := _sample_curve_screen(segment.curve)
|
||||
if points.size() < 2:
|
||||
return
|
||||
|
||||
var halo_width := _segment_width() + 6.0
|
||||
if segment.direction == PathSegment.Direction.BACKWARD:
|
||||
_draw_dashed_polyline(points, SELECTION_HALO_COLOR, halo_width)
|
||||
else:
|
||||
draw_polyline(points, SELECTION_HALO_COLOR, halo_width, true)
|
||||
|
||||
|
||||
func _draw_selection_handles() -> void:
|
||||
var segment := _get_selected_segment()
|
||||
if segment == null:
|
||||
return
|
||||
|
||||
var points := _sample_curve_screen(segment.curve)
|
||||
if points.is_empty():
|
||||
return
|
||||
|
||||
var start := points[0]
|
||||
var end := points[points.size() - 1]
|
||||
_draw_handle(start, HANDLE_FILL_COLOR)
|
||||
_draw_handle(end, HANDLE_FILL_COLOR)
|
||||
|
||||
if not segment.is_arc():
|
||||
return
|
||||
|
||||
var apex := _curve_apex_screen(segment.curve)
|
||||
var chord_midpoint := start.lerp(end, 0.5)
|
||||
var guide := BULGE_HANDLE_COLOR
|
||||
guide.a = 0.55
|
||||
draw_line(chord_midpoint, apex, guide, 1.5, true)
|
||||
_draw_handle(apex, BULGE_HANDLE_COLOR)
|
||||
|
||||
|
||||
func _draw_handle(center: Vector2, fill: Color) -> void:
|
||||
draw_circle(center, HANDLE_RADIUS_PX + 2.0, HANDLE_BORDER_COLOR)
|
||||
draw_circle(center, HANDLE_RADIUS_PX, fill)
|
||||
|
||||
|
||||
func _draw_dashed_polyline(
|
||||
points: PackedVector2Array,
|
||||
color: Color,
|
||||
|
|
@ -276,12 +369,25 @@ func _sample_curve_screen(curve: Curve2D) -> PackedVector2Array:
|
|||
return points
|
||||
|
||||
|
||||
func _curve_apex_screen(curve: Curve2D) -> Vector2:
|
||||
var curve_length := curve.get_baked_length()
|
||||
if curve_length <= 0.0:
|
||||
if curve.point_count == 0:
|
||||
return Vector2.ZERO
|
||||
return _transform.model_to_screen(curve.get_point_position(0))
|
||||
return _transform.model_to_screen(curve.sample_baked(curve_length * 0.5))
|
||||
|
||||
|
||||
func _edge_color(edge: PathSegment.Edge) -> Color:
|
||||
if edge == PathSegment.Edge.OUTSIDE:
|
||||
return OUTSIDE_EDGE_COLOR
|
||||
return INSIDE_EDGE_COLOR
|
||||
|
||||
|
||||
func _segment_width() -> float:
|
||||
return maxf(3.0, 0.12 * _transform.pixels_per_meter)
|
||||
|
||||
|
||||
func _get_active_section() -> RoutineSection:
|
||||
if _routine == null:
|
||||
return null
|
||||
|
|
@ -291,6 +397,72 @@ func _get_active_section() -> RoutineSection:
|
|||
return null
|
||||
|
||||
|
||||
func _get_selected_segment() -> PathSegment:
|
||||
var active := _get_active_section()
|
||||
if active == null or _selected_segment_id.is_empty():
|
||||
return null
|
||||
return active.get_segment_by_id(_selected_segment_id)
|
||||
|
||||
|
||||
func _find_segment_at(screen_point: Vector2) -> PathSegment:
|
||||
var active := _get_active_section()
|
||||
if active == null:
|
||||
return null
|
||||
|
||||
var closest_segment: PathSegment = null
|
||||
var closest_distance := SEGMENT_HIT_RADIUS_PX
|
||||
for segment: PathSegment in active.segments:
|
||||
if segment == null or segment.curve == null:
|
||||
continue
|
||||
var distance := _distance_to_polyline(
|
||||
screen_point,
|
||||
_sample_curve_screen(segment.curve)
|
||||
)
|
||||
if distance <= closest_distance:
|
||||
closest_distance = distance
|
||||
closest_segment = segment
|
||||
return closest_segment
|
||||
|
||||
|
||||
func _distance_to_polyline(
|
||||
point: Vector2,
|
||||
points: PackedVector2Array
|
||||
) -> float:
|
||||
if points.is_empty():
|
||||
return INF
|
||||
if points.size() == 1:
|
||||
return point.distance_to(points[0])
|
||||
|
||||
var closest := INF
|
||||
for index: int in range(points.size() - 1):
|
||||
var candidate := Geometry2D.get_closest_point_to_segment(
|
||||
point,
|
||||
points[index],
|
||||
points[index + 1]
|
||||
)
|
||||
closest = minf(closest, point.distance_to(candidate))
|
||||
return closest
|
||||
|
||||
|
||||
func _handle_at(screen_point: Vector2) -> Handle:
|
||||
var segment := _get_selected_segment()
|
||||
if segment == null:
|
||||
return Handle.NONE
|
||||
|
||||
var points := _sample_curve_screen(segment.curve)
|
||||
if points.is_empty():
|
||||
return Handle.NONE
|
||||
|
||||
if screen_point.distance_to(points[0]) <= HANDLE_HIT_RADIUS_PX:
|
||||
return Handle.START
|
||||
if screen_point.distance_to(points[points.size() - 1]) <= HANDLE_HIT_RADIUS_PX:
|
||||
return Handle.END
|
||||
if segment.is_arc():
|
||||
if screen_point.distance_to(_curve_apex_screen(segment.curve)) <= HANDLE_HIT_RADIUS_PX:
|
||||
return Handle.BULGE
|
||||
return Handle.NONE
|
||||
|
||||
|
||||
func _to_screen(model_points: PackedVector2Array) -> PackedVector2Array:
|
||||
var screen_points := PackedVector2Array()
|
||||
screen_points.resize(model_points.size())
|
||||
|
|
@ -330,18 +502,25 @@ func _handle_mouse_button(event: InputEventMouseButton) -> void:
|
|||
accept_event()
|
||||
MOUSE_BUTTON_MIDDLE:
|
||||
if event.pressed:
|
||||
_abort_handle_drag()
|
||||
_cancel_drawing()
|
||||
_panning = event.pressed
|
||||
accept_event()
|
||||
MOUSE_BUTTON_LEFT:
|
||||
if event.pressed:
|
||||
if drawing_enabled and _begin_drawing(event.position):
|
||||
if _selection_enabled:
|
||||
_begin_selection_press(event.position)
|
||||
accept_event()
|
||||
elif drawing_enabled and _begin_drawing(event.position):
|
||||
accept_event()
|
||||
else:
|
||||
_panning = true
|
||||
accept_event()
|
||||
else:
|
||||
if _drawing:
|
||||
if _handle_drag != Handle.NONE:
|
||||
_finish_handle_drag(event.position)
|
||||
accept_event()
|
||||
elif _drawing:
|
||||
_finish_drawing(event.position)
|
||||
accept_event()
|
||||
elif _panning:
|
||||
|
|
@ -350,32 +529,111 @@ func _handle_mouse_button(event: InputEventMouseButton) -> void:
|
|||
|
||||
|
||||
func _handle_mouse_motion(event: InputEventMouseMotion) -> void:
|
||||
if _drawing:
|
||||
if _handle_drag != Handle.NONE:
|
||||
_last_handle_model_point = _transform.screen_to_model(event.position)
|
||||
segment_handle_dragged.emit(
|
||||
_handle_drag_segment_id,
|
||||
_handle_drag,
|
||||
_last_handle_model_point
|
||||
)
|
||||
elif _drawing:
|
||||
draw_updated.emit(_transform.screen_to_model(event.position))
|
||||
elif _panning:
|
||||
_apply_pan(event.relative)
|
||||
|
||||
|
||||
func _begin_selection_press(screen_point: Vector2) -> void:
|
||||
var handle := _handle_at(screen_point)
|
||||
if handle != Handle.NONE:
|
||||
_handle_drag = handle
|
||||
_handle_drag_segment_id = _selected_segment_id
|
||||
_last_handle_model_point = _transform.screen_to_model(screen_point)
|
||||
segment_handle_drag_started.emit(_handle_drag_segment_id, handle)
|
||||
return
|
||||
|
||||
var segment := _find_segment_at(screen_point)
|
||||
if segment != null:
|
||||
_select_segment(segment)
|
||||
return
|
||||
|
||||
_clear_selection()
|
||||
_panning = true
|
||||
|
||||
|
||||
func _finish_handle_drag(screen_point: Vector2) -> void:
|
||||
if _handle_drag == Handle.NONE:
|
||||
return
|
||||
|
||||
var model_point := _transform.screen_to_model(screen_point)
|
||||
segment_handle_drag_finished.emit(
|
||||
_handle_drag_segment_id,
|
||||
_handle_drag,
|
||||
model_point
|
||||
)
|
||||
_handle_drag = Handle.NONE
|
||||
_handle_drag_segment_id = ""
|
||||
|
||||
|
||||
func _abort_handle_drag() -> void:
|
||||
if _handle_drag == Handle.NONE:
|
||||
return
|
||||
|
||||
segment_handle_drag_finished.emit(
|
||||
_handle_drag_segment_id,
|
||||
_handle_drag,
|
||||
_last_handle_model_point
|
||||
)
|
||||
_handle_drag = Handle.NONE
|
||||
_handle_drag_segment_id = ""
|
||||
|
||||
|
||||
func _select_segment(segment: PathSegment) -> void:
|
||||
_selected_segment_id = segment.segment_id
|
||||
queue_redraw()
|
||||
segment_selected.emit(segment.segment_id)
|
||||
|
||||
|
||||
func _clear_selection() -> void:
|
||||
if _selected_segment_id.is_empty():
|
||||
return
|
||||
_selected_segment_id = ""
|
||||
queue_redraw()
|
||||
selection_cleared.emit()
|
||||
|
||||
|
||||
func _handle_screen_touch(event: InputEventScreenTouch) -> void:
|
||||
if event.pressed:
|
||||
_touch_points[event.index] = event.position
|
||||
if _touch_points.size() == 1:
|
||||
if drawing_enabled and _begin_drawing(event.position):
|
||||
if _selection_enabled:
|
||||
_begin_selection_press(event.position)
|
||||
if _handle_drag != Handle.NONE:
|
||||
_handle_touch_index = event.index
|
||||
elif _panning:
|
||||
_pan_touch_index = event.index
|
||||
elif drawing_enabled and _begin_drawing(event.position):
|
||||
_draw_touch_index = event.index
|
||||
else:
|
||||
_pan_touch_index = event.index
|
||||
elif _touch_points.size() == 2:
|
||||
_abort_handle_drag()
|
||||
_handle_touch_index = -1
|
||||
_cancel_drawing()
|
||||
_draw_touch_index = -1
|
||||
_pan_touch_index = -1
|
||||
_panning = false
|
||||
_reset_pinch_reference()
|
||||
else:
|
||||
_touch_points.erase(event.index)
|
||||
if event.index == _handle_touch_index:
|
||||
_finish_handle_drag(event.position)
|
||||
_handle_touch_index = -1
|
||||
if event.index == _draw_touch_index:
|
||||
_draw_touch_index = -1
|
||||
_finish_drawing(event.position)
|
||||
if event.index == _pan_touch_index:
|
||||
_pan_touch_index = -1
|
||||
|
||||
_touch_points.erase(event.index)
|
||||
if _touch_points.size() < 2:
|
||||
_reset_pinch_reference()
|
||||
if _touch_points.size() == 1:
|
||||
|
|
@ -391,7 +649,14 @@ func _handle_screen_drag(event: InputEventScreenDrag) -> void:
|
|||
var previous: Vector2 = _touch_points[event.index]
|
||||
_touch_points[event.index] = event.position
|
||||
|
||||
if _drawing and event.index == _draw_touch_index:
|
||||
if _handle_drag != Handle.NONE and event.index == _handle_touch_index:
|
||||
_last_handle_model_point = _transform.screen_to_model(event.position)
|
||||
segment_handle_dragged.emit(
|
||||
_handle_drag_segment_id,
|
||||
_handle_drag,
|
||||
_last_handle_model_point
|
||||
)
|
||||
elif _drawing and event.index == _draw_touch_index:
|
||||
draw_updated.emit(_transform.screen_to_model(event.position))
|
||||
elif _touch_points.size() >= 2:
|
||||
_update_pinch()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ extends SceneTree
|
|||
|
||||
const CanvasTransformModel := preload("res://src/whiteboard/view/canvas_transform.gd")
|
||||
const RinkDimensionsModel := preload("res://src/core/model/rink_dimensions.gd")
|
||||
const ArcGeometryModel := preload("res://src/core/model/arc_geometry.gd")
|
||||
|
||||
var _assertions: int = 0
|
||||
var _failures: PackedStringArray = PackedStringArray()
|
||||
|
|
@ -20,6 +21,7 @@ func _init() -> void:
|
|||
_test_pan()
|
||||
_test_visible_rect()
|
||||
_test_rink_outline()
|
||||
_test_arc_geometry()
|
||||
_finish()
|
||||
|
||||
|
||||
|
|
@ -112,6 +114,55 @@ func _test_rink_outline() -> void:
|
|||
_check(rink.contains_point(corner_point), "corner arc lies on the rink surface")
|
||||
|
||||
|
||||
func _test_arc_geometry() -> void:
|
||||
var rink: RinkDimensions = RinkDimensionsModel.new()
|
||||
var start := Vector2(-10.0, 0.0)
|
||||
var end := Vector2(10.0, 0.0)
|
||||
|
||||
var left := ArcGeometryModel.build_points(start, end, true, 0.4, rink)
|
||||
_check(left.size() > 2, "arc geometry returns a sampled curve")
|
||||
_check_vec(left[0], start, "arc keeps the start point")
|
||||
_check_vec(left[left.size() - 1], end, "arc keeps the end point")
|
||||
_check(left[left.size() / 2].y > 1.0, "left arc bulges left of the chord")
|
||||
|
||||
var right := ArcGeometryModel.build_points(start, end, false, 0.4, rink)
|
||||
_check(right[right.size() / 2].y < -1.0, "right arc bulges right of the chord")
|
||||
|
||||
var shallow := ArcGeometryModel.build_points(start, end, true, 0.15, rink)
|
||||
var deep := ArcGeometryModel.build_points(start, end, true, 0.45, rink)
|
||||
_check(
|
||||
absf(deep[deep.size() / 2].y) > absf(shallow[shallow.size() / 2].y),
|
||||
"larger depth ratio produces a deeper arc"
|
||||
)
|
||||
|
||||
var near_board := ArcGeometryModel.build_points(
|
||||
Vector2(-10.0, 10.0),
|
||||
Vector2(10.0, 10.0),
|
||||
true,
|
||||
0.4,
|
||||
rink
|
||||
)
|
||||
for point: Vector2 in near_board:
|
||||
_check(
|
||||
rink.contains_point(point),
|
||||
"arc near the board is flattened: %s" % point
|
||||
)
|
||||
|
||||
_check_approx(
|
||||
ArcGeometryModel.depth_ratio_for_point(start, end, Vector2(0.0, 8.0)),
|
||||
0.4,
|
||||
"depth ratio is derived from the point distance"
|
||||
)
|
||||
_check(
|
||||
ArcGeometryModel.is_left_of_chord(start, end, Vector2(0.0, 8.0)),
|
||||
"point above the chord reports as left"
|
||||
)
|
||||
_check(
|
||||
not ArcGeometryModel.is_left_of_chord(start, end, Vector2(0.0, -8.0)),
|
||||
"point below the chord reports as right"
|
||||
)
|
||||
|
||||
|
||||
func _check(condition: bool, message: String) -> void:
|
||||
_assertions += 1
|
||||
if not condition:
|
||||
|
|
|
|||
|
|
@ -110,6 +110,20 @@ func _test_segment_timing() -> void:
|
|||
"segment with length but no duration is invalid"
|
||||
)
|
||||
|
||||
var arc_segment: PathSegment = PathSegmentModel.new()
|
||||
arc_segment.segment_id = "seg-arc"
|
||||
arc_segment.curve = _make_curve(Vector2(-5.0, 0.0), Vector2(5.0, 0.0))
|
||||
arc_segment.duration_seconds = 2.0
|
||||
arc_segment.template = PathSegment.Template.ARC
|
||||
arc_segment.arc_depth_ratio = 0.4
|
||||
_check(arc_segment.is_arc(), "arc template reports as arc")
|
||||
_check(arc_segment.is_valid(), "arc with a valid depth ratio is valid")
|
||||
arc_segment.arc_depth_ratio = 0.5
|
||||
_check(
|
||||
not arc_segment.is_valid(),
|
||||
"arc depth ratio at or above 0.5 is invalid"
|
||||
)
|
||||
|
||||
|
||||
func _test_section_aggregation() -> void:
|
||||
var section: RoutineSection = RoutineSectionModel.new()
|
||||
|
|
|
|||
|
|
@ -232,21 +232,111 @@ func _run() -> void:
|
|||
"dragged left arc bulges below its chord"
|
||||
)
|
||||
|
||||
var count_before_navigate := section.segments.size()
|
||||
var origin_before_navigate: Vector2 = view.origin_px
|
||||
controller.set_tool(WhiteboardController.Tool.NAVIGATE)
|
||||
var pan_start := view.model_to_screen(Vector2(0.0, 0.0))
|
||||
# Selection and handle editing.
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
var apex_before := arc_left.curve.sample_baked(arc_left.get_length_m() * 0.5)
|
||||
_mouse_button(canvas, view.model_to_screen(apex_before), true)
|
||||
_mouse_button(canvas, view.model_to_screen(apex_before), false)
|
||||
_check(
|
||||
controller.get_selected_segment() == arc_left,
|
||||
"clicking an arc selects it"
|
||||
)
|
||||
_check(
|
||||
canvas.get_selected_segment_id() == arc_left.segment_id,
|
||||
"canvas keeps the selection in sync"
|
||||
)
|
||||
_check(
|
||||
controller.status_label.text.contains("Auswahl: Bogen"),
|
||||
"status bar reports the selected arc"
|
||||
)
|
||||
|
||||
var selected_start := arc_left.curve.get_point_position(0)
|
||||
var new_start := Vector2(-12.0, -2.0)
|
||||
_mouse_button(canvas, view.model_to_screen(selected_start), true)
|
||||
_mouse_motion(canvas, view.model_to_screen(new_start))
|
||||
_mouse_button(canvas, view.model_to_screen(new_start), false)
|
||||
_check_vec(
|
||||
arc_left.curve.get_point_position(0),
|
||||
new_start,
|
||||
"start handle moves the arc start"
|
||||
)
|
||||
_check(
|
||||
arc_left.template == PathSegment.Template.ARC,
|
||||
"editing endpoints keeps the arc template"
|
||||
)
|
||||
|
||||
var start_now := arc_left.curve.get_point_position(0)
|
||||
var end_now := arc_left.curve.get_point_position(arc_left.curve.point_count - 1)
|
||||
var chord_now := end_now - start_now
|
||||
var mid_now := (start_now + end_now) * 0.5
|
||||
var normal_now := Vector2(-chord_now.y, chord_now.x).normalized()
|
||||
var deeper := mid_now + normal_now * (0.46 * chord_now.length())
|
||||
var apex_now := arc_left.curve.sample_baked(arc_left.get_length_m() * 0.5)
|
||||
_mouse_button(canvas, view.model_to_screen(apex_now), true)
|
||||
_mouse_motion(canvas, view.model_to_screen(deeper))
|
||||
_mouse_button(canvas, view.model_to_screen(deeper), false)
|
||||
_check(
|
||||
arc_left.arc_depth_ratio > 0.43,
|
||||
"bulge handle increases the arc depth"
|
||||
)
|
||||
_check(
|
||||
arc_left.arc_bulge_left,
|
||||
"bulge stays left while dragged on the left side"
|
||||
)
|
||||
|
||||
var apex_flip := arc_left.curve.sample_baked(arc_left.get_length_m() * 0.5)
|
||||
var flipped := mid_now - normal_now * (0.3 * chord_now.length())
|
||||
_mouse_button(canvas, view.model_to_screen(apex_flip), true)
|
||||
_mouse_motion(canvas, view.model_to_screen(flipped))
|
||||
_mouse_button(canvas, view.model_to_screen(flipped), false)
|
||||
_check(
|
||||
not arc_left.arc_bulge_left,
|
||||
"bulge handle can flip the arc side"
|
||||
)
|
||||
var apex_after_flip := arc_left.curve.sample_baked(arc_left.get_length_m() * 0.5)
|
||||
_check(
|
||||
(apex_after_flip - mid_now).dot(normal_now) < 0.0,
|
||||
"flipped arc lies on the other side of the chord"
|
||||
)
|
||||
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
_check(
|
||||
controller.get_selected_segment() == null,
|
||||
"switching to a draw tool clears the selection"
|
||||
)
|
||||
_check(
|
||||
canvas.get_selected_segment_id().is_empty(),
|
||||
"canvas selection is cleared with the tool"
|
||||
)
|
||||
|
||||
controller.set_tool(WhiteboardController.Tool.SELECT)
|
||||
controller.select_segment(arc_left.segment_id)
|
||||
_check(
|
||||
controller.get_selected_segment() == arc_left,
|
||||
"select_segment selects programmatically"
|
||||
)
|
||||
var empty_point := Vector2(25.0, -12.0)
|
||||
_mouse_button(canvas, view.model_to_screen(empty_point), true)
|
||||
_mouse_button(canvas, view.model_to_screen(empty_point), false)
|
||||
_check(
|
||||
controller.get_selected_segment() == null,
|
||||
"clicking empty ice clears the selection"
|
||||
)
|
||||
|
||||
var count_before_pan := section.segments.size()
|
||||
var origin_before_pan: Vector2 = view.origin_px
|
||||
var pan_start := view.model_to_screen(empty_point)
|
||||
var pan_delta := Vector2(40.0, 0.0)
|
||||
_mouse_button(canvas, pan_start, true)
|
||||
_mouse_motion(canvas, pan_start + pan_delta, pan_delta)
|
||||
_mouse_button(canvas, pan_start + pan_delta, false)
|
||||
_check(
|
||||
section.segments.size() == count_before_navigate,
|
||||
"navigate mode does not create segments"
|
||||
section.segments.size() == count_before_pan,
|
||||
"select mode does not create segments"
|
||||
)
|
||||
_check(
|
||||
view.origin_px != origin_before_navigate,
|
||||
"navigate mode pans with a left drag"
|
||||
view.origin_px != origin_before_pan,
|
||||
"select mode pans on empty ice"
|
||||
)
|
||||
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue