feat: Bogen- und Lobe-Vorlagen für das Whiteboard hinzufügen
- Werkzeugauswahl Navigieren, Linie, Bogen links und Bogen rechts - Kreisbogen-Geometrie mit 40 % Pfeilhöhe, automatisch an der Bande abgeflacht - Bogen bleibt als Curve2D im Datenmodell, Darstellung folgt Richtung/Kante - Tests für Bogenparameter, Klemmen und Navigationsmodus ergänzt (164 Assertions)
This commit is contained in:
parent
a0ad7db844
commit
36e25aa559
4 changed files with 305 additions and 44 deletions
|
|
@ -91,11 +91,16 @@ eine Abkürzung. So kann die UI Fehler konkret anzeigen.
|
||||||
Mittelkreis und behandelt Pan/Zoom (Maus, Touch, Pinch).
|
Mittelkreis und behandelt Pan/Zoom (Maus, Touch, Pinch).
|
||||||
- **Controller** übersetzt Touch-/Maus-Eingaben in Modelloperationen
|
- **Controller** übersetzt Touch-/Maus-Eingaben in Modelloperationen
|
||||||
(Segment anlegen, Kante umschalten, Section wechseln, Playback steuern).
|
(Segment anlegen, Kante umschalten, Section wechseln, Playback steuern).
|
||||||
- **Erstes Zeichenwerkzeug:** `WhiteboardController` hält eine Draft-Routine
|
- **Zeichenwerkzeuge:** `WhiteboardController` hält eine Draft-Routine mit
|
||||||
mit einer Section. Linksziehen erzeugt ein gerades `PathSegment`; die
|
einer Section. Die Toolbar bietet Navigieren, Linie, Bogen links und Bogen
|
||||||
Toolbar schaltet Richtung (vorwärts/rückwärts) und Kante (innen/außen) für
|
rechts; Richtung (vorwärts/rückwärts) und Kante (innen/außen) gelten für das
|
||||||
das nächste Segment. Die Dauer wird mit 6 m/s aus der Länge abgeleitet,
|
nächste Segment. Die Dauer wird mit 6 m/s aus der Länge abgeleitet, Züge
|
||||||
Züge über die Bande werden per `clamp_point()` auf die Eisfläche begrenzt.
|
ü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.
|
||||||
- **Darstellung:** vorwärts durchgezogen, rückwärts gestrichelt, außen rot,
|
- **Darstellung:** vorwärts durchgezogen, rückwärts gestrichelt, außen rot,
|
||||||
innen blau. Inaktive Sections werden mit 20 % Deckkraft geghostet.
|
innen blau. Inaktive Sections werden mit 20 % Deckkraft geghostet.
|
||||||
- **Ghosting** ist reine View-Logik: pro Section ein eigener Layer,
|
- **Ghosting** ist reine View-Logik: pro Section ein eigener Layer,
|
||||||
|
|
@ -147,8 +152,9 @@ Aktueller Stand:
|
||||||
Section-Aggregation und Routine-Validierung.
|
Section-Aggregation und Routine-Validierung.
|
||||||
- **Canvas:** 67 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan und die
|
- **Canvas:** 67 Assertions für Meter→Pixel-Mapping, Fit/Zoom/Pan und die
|
||||||
Rink-Kontur inklusive Eckradien.
|
Rink-Kontur inklusive Eckradien.
|
||||||
- **Whiteboard:** 26 Assertions für Controller-Verdrahtung, Segmenterzeugung,
|
- **Whiteboard:** 55 Assertions für Controller-Verdrahtung, Segmenterzeugung,
|
||||||
Klemmen an der Bande, Undo und den Maus-Drag-Pfad.
|
Linien-/Bogenpfade, Klemmen an der Bande, Undo, Navigationsmodus und den
|
||||||
|
Maus-Drag-Pfad.
|
||||||
|
|
||||||
Visuelle Smoke-Tests laufen zusätzlich über `xvfb-run` und einen
|
Visuelle Smoke-Tests laufen zusätzlich über `xvfb-run` und einen
|
||||||
Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
||||||
|
|
@ -165,6 +171,9 @@ Viewport-Screenshot; sie ersetzen die headless Tests nicht.
|
||||||
4. **Section-Übergänge:** Ob Sections eine explizite Startzeit erhalten oder
|
4. **Section-Übergänge:** Ob Sections eine explizite Startzeit erhalten oder
|
||||||
ausschließlich aus Segmentdauern abgeleitet werden, klärt die
|
ausschließlich aus Segmentdauern abgeleitet werden, klärt die
|
||||||
Playback-Implementierung.
|
Playback-Implementierung.
|
||||||
5. **Kurven und Templates:** Das erste Werkzeug erzeugt gerade Segmente.
|
5. **Kurven und Templates:** Linie und Kreisbogen sind umgesetzt. Offen sind
|
||||||
Ob freie Kurven direkt als Bézier-Segmente oder über Template-Geometrie
|
Freihand, das nachträgliche Bearbeiten von Bogenparametern (Start/Ende,
|
||||||
(Lobe, Bogen, Acht) entstehen, ist der nächste Tool-Schritt.
|
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.
|
||||||
|
|
|
||||||
|
|
@ -61,25 +61,22 @@ vertical_alignment = 1
|
||||||
[node name="TitleSeparator" type="VSeparator" parent="Layout/TopBar/Tools"]
|
[node name="TitleSeparator" type="VSeparator" parent="Layout/TopBar/Tools"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="DrawButton" type="Button" parent="Layout/TopBar/Tools"]
|
[node name="ToolLabel" type="Label" parent="Layout/TopBar/Tools"]
|
||||||
unique_name_in_owner = true
|
|
||||||
custom_minimum_size = Vector2(112, 48)
|
|
||||||
layout_mode = 2
|
|
||||||
theme_override_font_sizes/font_size = 16
|
|
||||||
toggle_mode = true
|
|
||||||
button_pressed = true
|
|
||||||
text = "Zeichnen"
|
|
||||||
|
|
||||||
[node name="DrawSeparator" type="VSeparator" parent="Layout/TopBar/Tools"]
|
|
||||||
layout_mode = 2
|
|
||||||
|
|
||||||
[node name="DirectionLabel" type="Label" parent="Layout/TopBar/Tools"]
|
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
||||||
theme_override_font_sizes/font_size = 14
|
theme_override_font_sizes/font_size = 14
|
||||||
text = "Richtung"
|
text = "Werkzeug"
|
||||||
vertical_alignment = 1
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="ToolOption" type="OptionButton" parent="Layout/TopBar/Tools"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
custom_minimum_size = Vector2(170, 48)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/font_size = 16
|
||||||
|
|
||||||
|
[node name="ToolSeparator" type="VSeparator" parent="Layout/TopBar/Tools"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="ForwardButton" type="Button" parent="Layout/TopBar/Tools"]
|
[node name="ForwardButton" type="Button" parent="Layout/TopBar/Tools"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(104, 48)
|
custom_minimum_size = Vector2(104, 48)
|
||||||
|
|
@ -102,13 +99,6 @@ text = "Rückwärts"
|
||||||
[node name="EdgeSeparator" type="VSeparator" parent="Layout/TopBar/Tools"]
|
[node name="EdgeSeparator" type="VSeparator" parent="Layout/TopBar/Tools"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="EdgeLabel" type="Label" parent="Layout/TopBar/Tools"]
|
|
||||||
layout_mode = 2
|
|
||||||
theme_override_colors/font_color = Color(0.580392, 0.639216, 0.721569, 1)
|
|
||||||
theme_override_font_sizes/font_size = 14
|
|
||||||
text = "Kante"
|
|
||||||
vertical_alignment = 1
|
|
||||||
|
|
||||||
[node name="InsideButton" type="Button" parent="Layout/TopBar/Tools"]
|
[node name="InsideButton" type="Button" parent="Layout/TopBar/Tools"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
custom_minimum_size = Vector2(88, 48)
|
custom_minimum_size = Vector2(88, 48)
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,24 @@ extends Control
|
||||||
## Root controller for the Phase 1 whiteboard. Owns the draft routine, turns
|
## Root controller for the Phase 1 whiteboard. Owns the draft routine, turns
|
||||||
## canvas gestures into model mutations and keeps the toolbar/status in sync.
|
## canvas gestures into model mutations and keeps the toolbar/status in sync.
|
||||||
|
|
||||||
|
enum Tool {
|
||||||
|
NAVIGATE,
|
||||||
|
LINE,
|
||||||
|
ARC_LEFT,
|
||||||
|
ARC_RIGHT,
|
||||||
|
}
|
||||||
|
|
||||||
const DEFAULT_SPEED_MPS := 6.0
|
const DEFAULT_SPEED_MPS := 6.0
|
||||||
const MIN_SEGMENT_LENGTH_M := 0.3
|
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
|
@onready var rink_canvas: RinkCanvas = %RinkCanvas
|
||||||
@onready var draw_button: Button = %DrawButton
|
@onready var tool_option: OptionButton = %ToolOption
|
||||||
@onready var forward_button: Button = %ForwardButton
|
@onready var forward_button: Button = %ForwardButton
|
||||||
@onready var backward_button: Button = %BackwardButton
|
@onready var backward_button: Button = %BackwardButton
|
||||||
@onready var inside_button: Button = %InsideButton
|
@onready var inside_button: Button = %InsideButton
|
||||||
|
|
@ -21,6 +34,7 @@ var _routine: Routine
|
||||||
var _active_section: RoutineSection
|
var _active_section: RoutineSection
|
||||||
var _current_segment: PathSegment
|
var _current_segment: PathSegment
|
||||||
var _segment_counter: int = 0
|
var _segment_counter: int = 0
|
||||||
|
var _tool: Tool = Tool.LINE
|
||||||
var _direction: PathSegment.Direction = PathSegment.Direction.FORWARD
|
var _direction: PathSegment.Direction = PathSegment.Direction.FORWARD
|
||||||
var _edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE
|
var _edge: PathSegment.Edge = PathSegment.Edge.OUTSIDE
|
||||||
|
|
||||||
|
|
@ -40,11 +54,12 @@ func _ready() -> void:
|
||||||
sections.append(_active_section)
|
sections.append(_active_section)
|
||||||
_routine.sections = sections
|
_routine.sections = sections
|
||||||
|
|
||||||
|
_setup_tool_options()
|
||||||
|
|
||||||
rink_canvas.set_routine(_routine)
|
rink_canvas.set_routine(_routine)
|
||||||
rink_canvas.set_active_section(_active_section.section_id)
|
rink_canvas.set_active_section(_active_section.section_id)
|
||||||
rink_canvas.set_drawing_enabled(draw_button.button_pressed)
|
|
||||||
|
|
||||||
draw_button.toggled.connect(_on_draw_toggled)
|
tool_option.item_selected.connect(_on_tool_selected)
|
||||||
forward_button.pressed.connect(
|
forward_button.pressed.connect(
|
||||||
_on_direction_pressed.bind(PathSegment.Direction.FORWARD)
|
_on_direction_pressed.bind(PathSegment.Direction.FORWARD)
|
||||||
)
|
)
|
||||||
|
|
@ -72,16 +87,29 @@ func get_active_section() -> RoutineSection:
|
||||||
return _active_section
|
return _active_section
|
||||||
|
|
||||||
|
|
||||||
|
func get_tool() -> Tool:
|
||||||
|
return _tool
|
||||||
|
|
||||||
|
|
||||||
|
## Selects a tool programmatically and keeps the toolbar in sync.
|
||||||
|
func set_tool(tool: Tool) -> void:
|
||||||
|
_apply_tool(tool)
|
||||||
|
var index := tool_option.get_item_index(tool)
|
||||||
|
if index >= 0:
|
||||||
|
tool_option.select(index)
|
||||||
|
|
||||||
|
|
||||||
## Adds a complete segment programmatically. Also used by template tools and
|
## Adds a complete segment programmatically. Also used by template tools and
|
||||||
## by the visual test harness.
|
## by the visual test harness.
|
||||||
func add_segment(
|
func add_segment(
|
||||||
start: Vector2,
|
start: Vector2,
|
||||||
end: Vector2,
|
end: Vector2,
|
||||||
direction: PathSegment.Direction,
|
direction: PathSegment.Direction,
|
||||||
edge: PathSegment.Edge
|
edge: PathSegment.Edge,
|
||||||
|
tool: Tool = Tool.LINE
|
||||||
) -> PathSegment:
|
) -> PathSegment:
|
||||||
var segment := _create_segment(start, direction, edge)
|
var segment := _create_segment(start, direction, edge)
|
||||||
_update_segment_end(segment, end)
|
_update_segment_geometry(segment, end, tool)
|
||||||
_active_section.segments.append(segment)
|
_active_section.segments.append(segment)
|
||||||
rink_canvas.refresh()
|
rink_canvas.refresh()
|
||||||
_update_status()
|
_update_status()
|
||||||
|
|
@ -100,8 +128,36 @@ func undo_last_segment() -> void:
|
||||||
_update_status()
|
_update_status()
|
||||||
|
|
||||||
|
|
||||||
func _on_draw_toggled(enabled: bool) -> void:
|
func _setup_tool_options() -> void:
|
||||||
rink_canvas.set_drawing_enabled(enabled)
|
tool_option.clear()
|
||||||
|
tool_option.add_item("Navigieren", Tool.NAVIGATE)
|
||||||
|
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)
|
||||||
|
tool_option.select(tool_option.get_item_index(Tool.LINE))
|
||||||
|
_apply_tool(Tool.LINE)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_tool_selected(index: int) -> void:
|
||||||
|
_apply_tool(_tool_from_id(tool_option.get_item_id(index)))
|
||||||
|
|
||||||
|
|
||||||
|
func _apply_tool(tool: Tool) -> void:
|
||||||
|
_tool = tool
|
||||||
|
rink_canvas.set_drawing_enabled(tool != Tool.NAVIGATE)
|
||||||
|
|
||||||
|
|
||||||
|
func _tool_from_id(tool_id: int) -> Tool:
|
||||||
|
match tool_id:
|
||||||
|
Tool.NAVIGATE:
|
||||||
|
return Tool.NAVIGATE
|
||||||
|
Tool.LINE:
|
||||||
|
return Tool.LINE
|
||||||
|
Tool.ARC_LEFT:
|
||||||
|
return Tool.ARC_LEFT
|
||||||
|
Tool.ARC_RIGHT:
|
||||||
|
return Tool.ARC_RIGHT
|
||||||
|
return Tool.LINE
|
||||||
|
|
||||||
|
|
||||||
func _on_direction_pressed(direction: PathSegment.Direction) -> void:
|
func _on_direction_pressed(direction: PathSegment.Direction) -> void:
|
||||||
|
|
@ -123,7 +179,7 @@ func _on_draw_started(model_point: Vector2) -> void:
|
||||||
func _on_draw_updated(model_point: Vector2) -> void:
|
func _on_draw_updated(model_point: Vector2) -> void:
|
||||||
if _current_segment == null:
|
if _current_segment == null:
|
||||||
return
|
return
|
||||||
_update_segment_end(_current_segment, model_point)
|
_update_segment_geometry(_current_segment, model_point, _tool)
|
||||||
rink_canvas.refresh()
|
rink_canvas.refresh()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -131,7 +187,7 @@ func _on_draw_finished(model_point: Vector2) -> void:
|
||||||
if _current_segment == null:
|
if _current_segment == null:
|
||||||
return
|
return
|
||||||
|
|
||||||
_update_segment_end(_current_segment, model_point)
|
_update_segment_geometry(_current_segment, model_point, _tool)
|
||||||
if _current_segment.get_length_m() < MIN_SEGMENT_LENGTH_M:
|
if _current_segment.get_length_m() < MIN_SEGMENT_LENGTH_M:
|
||||||
_active_section.segments.erase(_current_segment)
|
_active_section.segments.erase(_current_segment)
|
||||||
|
|
||||||
|
|
@ -171,12 +227,108 @@ func _create_segment(
|
||||||
return segment
|
return segment
|
||||||
|
|
||||||
|
|
||||||
func _update_segment_end(segment: PathSegment, end: Vector2) -> void:
|
func _update_segment_geometry(
|
||||||
|
segment: PathSegment,
|
||||||
|
end: Vector2,
|
||||||
|
tool: Tool
|
||||||
|
) -> void:
|
||||||
if segment == null or segment.curve == null or segment.curve.point_count < 2:
|
if segment == null or segment.curve == null or segment.curve.point_count < 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
segment.curve.set_point_position(1, _routine.rink.clamp_point(end))
|
var start := segment.curve.get_point_position(0)
|
||||||
segment.duration_seconds = maxf(segment.get_length_m() / DEFAULT_SPEED_MPS, 0.001)
|
var clamped_end := _routine.rink.clamp_point(end)
|
||||||
|
|
||||||
|
if tool == Tool.LINE or start.distance_to(clamped_end) <= EPSILON:
|
||||||
|
_set_straight_curve(segment.curve, start, clamped_end)
|
||||||
|
else:
|
||||||
|
var arc_points := _build_arc_points(
|
||||||
|
start,
|
||||||
|
clamped_end,
|
||||||
|
tool == Tool.ARC_LEFT
|
||||||
|
)
|
||||||
|
_set_curve_points(segment.curve, arc_points)
|
||||||
|
|
||||||
|
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:
|
func _update_status() -> void:
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,104 @@ func _run() -> void:
|
||||||
"a tap without drag does not create a segment"
|
"a tap without drag does not create a segment"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var arc_left := controller.add_segment(
|
||||||
|
Vector2(-10.0, 0.0),
|
||||||
|
Vector2(10.0, 0.0),
|
||||||
|
PathSegment.Direction.FORWARD,
|
||||||
|
PathSegment.Edge.OUTSIDE,
|
||||||
|
WhiteboardController.Tool.ARC_LEFT
|
||||||
|
)
|
||||||
|
_check(arc_left.curve.point_count > 2, "arc template samples a curve")
|
||||||
|
_check(
|
||||||
|
arc_left.get_length_m() > 20.0,
|
||||||
|
"arc is longer than its straight chord"
|
||||||
|
)
|
||||||
|
var arc_left_mid := arc_left.curve.sample_baked(arc_left.get_length_m() * 0.5)
|
||||||
|
_check(arc_left_mid.y > 1.0, "left arc bulges to the left of the chord")
|
||||||
|
_check_vec(
|
||||||
|
arc_left.curve.get_point_position(0),
|
||||||
|
Vector2(-10.0, 0.0),
|
||||||
|
"arc keeps its start point"
|
||||||
|
)
|
||||||
|
_check_vec(
|
||||||
|
arc_left.curve.get_point_position(arc_left.curve.point_count - 1),
|
||||||
|
Vector2(10.0, 0.0),
|
||||||
|
"arc keeps its end point"
|
||||||
|
)
|
||||||
|
|
||||||
|
var arc_right := controller.add_segment(
|
||||||
|
Vector2(-10.0, 0.0),
|
||||||
|
Vector2(10.0, 0.0),
|
||||||
|
PathSegment.Direction.BACKWARD,
|
||||||
|
PathSegment.Edge.INSIDE,
|
||||||
|
WhiteboardController.Tool.ARC_RIGHT
|
||||||
|
)
|
||||||
|
var arc_right_mid := arc_right.curve.sample_baked(arc_right.get_length_m() * 0.5)
|
||||||
|
_check(arc_right_mid.y < -1.0, "right arc bulges to the right of the chord")
|
||||||
|
|
||||||
|
var edge_arc := controller.add_segment(
|
||||||
|
Vector2(-10.0, 10.0),
|
||||||
|
Vector2(10.0, 10.0),
|
||||||
|
PathSegment.Direction.FORWARD,
|
||||||
|
PathSegment.Edge.OUTSIDE,
|
||||||
|
WhiteboardController.Tool.ARC_LEFT
|
||||||
|
)
|
||||||
|
for point: Vector2 in edge_arc.curve.get_baked_points():
|
||||||
|
_check(
|
||||||
|
routine.rink.contains_point(point),
|
||||||
|
"arc near the board is flattened to stay inside: %s" % point
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
arc_right.direction == PathSegment.Direction.BACKWARD,
|
||||||
|
"arc keeps the requested direction"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
arc_right.edge == PathSegment.Edge.INSIDE,
|
||||||
|
"arc keeps the requested edge"
|
||||||
|
)
|
||||||
|
_check(routine.is_valid(), "routine stays valid with arc segments")
|
||||||
|
|
||||||
|
var count_before_arc_drag := section.segments.size()
|
||||||
|
controller.set_tool(WhiteboardController.Tool.ARC_LEFT)
|
||||||
|
_check(
|
||||||
|
controller.get_tool() == WhiteboardController.Tool.ARC_LEFT,
|
||||||
|
"tool can be selected programmatically"
|
||||||
|
)
|
||||||
|
_mouse_button(canvas, view.model_to_screen(Vector2(-15.0, 5.0)), true)
|
||||||
|
_mouse_motion(canvas, view.model_to_screen(Vector2(-5.0, 5.0)))
|
||||||
|
_mouse_button(canvas, view.model_to_screen(Vector2(-5.0, 5.0)), false)
|
||||||
|
_check(
|
||||||
|
section.segments.size() == count_before_arc_drag + 1,
|
||||||
|
"arc mode creates a segment through the drag path"
|
||||||
|
)
|
||||||
|
var dragged_arc := section.segments[section.segments.size() - 1]
|
||||||
|
_check(dragged_arc.curve.point_count > 2, "dragged arc uses the template geometry")
|
||||||
|
var dragged_arc_mid := dragged_arc.curve.sample_baked(
|
||||||
|
dragged_arc.get_length_m() * 0.5
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
dragged_arc_mid.y > 5.5,
|
||||||
|
"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))
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
_check(
|
||||||
|
view.origin_px != origin_before_navigate,
|
||||||
|
"navigate mode pans with a left drag"
|
||||||
|
)
|
||||||
|
controller.set_tool(WhiteboardController.Tool.LINE)
|
||||||
|
|
||||||
scene.queue_free()
|
scene.queue_free()
|
||||||
await process_frame
|
await process_frame
|
||||||
_finish()
|
_finish()
|
||||||
|
|
@ -178,12 +276,24 @@ func _mouse_button(canvas: RinkCanvas, position: Vector2, pressed: bool) -> void
|
||||||
canvas._gui_input(event)
|
canvas._gui_input(event)
|
||||||
|
|
||||||
|
|
||||||
func _mouse_motion(canvas: RinkCanvas, position: Vector2) -> void:
|
func _mouse_motion(
|
||||||
|
canvas: RinkCanvas,
|
||||||
|
position: Vector2,
|
||||||
|
relative: Vector2 = Vector2.ZERO
|
||||||
|
) -> void:
|
||||||
var event := InputEventMouseMotion.new()
|
var event := InputEventMouseMotion.new()
|
||||||
event.position = position
|
event.position = position
|
||||||
|
event.relative = relative
|
||||||
canvas._gui_input(event)
|
canvas._gui_input(event)
|
||||||
|
|
||||||
|
|
||||||
|
func _check_vec(actual: Vector2, expected: Vector2, message: String) -> void:
|
||||||
|
_check(
|
||||||
|
actual.distance_to(expected) <= 0.001,
|
||||||
|
"%s (expected %s, got %s)" % [message, expected, actual]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
func _contains_error(errors: PackedStringArray, fragment: String) -> bool:
|
func _contains_error(errors: PackedStringArray, fragment: String) -> bool:
|
||||||
for error: String in errors:
|
for error: String in errors:
|
||||||
if error.contains(fragment):
|
if error.contains(fragment):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue