From 37e587d1eb434e99abaad09ac411692006d7c9ad Mon Sep 17 00:00:00 2001 From: Florian Glawogger <73254596+FlorianGlawogger@users.noreply.github.com> Date: Wed, 19 Feb 2025 13:28:44 +0100 Subject: [PATCH] Remove turning point code again, probably unnecessary --- .../FieldLineStopDrawing/CloseFieldLine.cs | 53 ++++--------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/unity/Assets/Maroon/reusableScripts/FieldLines/FieldLineStopDrawing/CloseFieldLine.cs b/unity/Assets/Maroon/reusableScripts/FieldLines/FieldLineStopDrawing/CloseFieldLine.cs index 53036e5e0..90fd41743 100644 --- a/unity/Assets/Maroon/reusableScripts/FieldLines/FieldLineStopDrawing/CloseFieldLine.cs +++ b/unity/Assets/Maroon/reusableScripts/FieldLines/FieldLineStopDrawing/CloseFieldLine.cs @@ -6,23 +6,12 @@ public class CloseFieldLine : MonoBehaviour { [Tooltip("Don't stop drawing until at least this many line segments have been drawn (i.e. the number of StopDrawing calls)")] [SerializeField] private int minLineSegmentCount = 3; - [Tooltip("Stop drawing when this many FieldLine turning points have been reached")] - [SerializeField] private int maxTurningPoints = 4; private FieldLine fieldLine; private int currentLineSegmentIndex; - private float lastDistanceToStart; + private float furthestDistanceToStart; private float distanceToStartWhenDrawingShouldStop; - /// - /// Describes if the fieldline segment is approaching or receding from the FieldLine's Start Position, and how many times this has changed - /// (Not entierely accurate, but more or less the number of turning points the fieldLine had). - /// An even value means the field Line segment is getting further away from the start pos, odd means coming closer to the start pos. - /// Each time a fieldLine segment reaches a turning point (i.e. changes the approaching/receding status), the value will be increased by 1. - /// E.g. At first the segments receded (0), then they got closer (1), then they receded again (2), then they got closer again (1) - /// - private int fieldLineTurningPoints; - private void Awake() { fieldLine = GetComponent(); @@ -37,8 +26,7 @@ private void OnStartDrawing() { // Reset field line's segment-related variables currentLineSegmentIndex = -1; - lastDistanceToStart = 0f; - fieldLineTurningPoints = 0; + furthestDistanceToStart = 0f; distanceToStartWhenDrawingShouldStop = ((fieldLine.minLineSegmentLength + fieldLine.maxLineSegmentLength) / 2f); } @@ -52,10 +40,14 @@ private bool StopDrawing(Vector3 lineSegmentPosition) { currentLineSegmentIndex++; - // Check if distance to start pos got larger (receding from start pos) + // Check if distance to start pos got larger Vector3 fieldLineStartPosition = fieldLine.transform.TransformPoint(Vector3.zero - fieldLine.originOffset); float lineDistanceToStart = Vector3.Distance(lineSegmentPosition, fieldLineStartPosition); - UpdateSegmentProperties(lineDistanceToStart); + if (lineDistanceToStart > furthestDistanceToStart) + { + // distance to start position got larger + furthestDistanceToStart = lineDistanceToStart; + } // Don't stop drawing when not at least minLineSegmentCount reached if (currentLineSegmentIndex < minLineSegmentCount) @@ -68,41 +60,18 @@ private bool StopDrawing(Vector3 lineSegmentPosition) return true; } - if (PreviousSegmentRecededStartPos()) + if (lineDistanceToStart < furthestDistanceToStart) { - // Don't stop drawing when receding from start pos - return false; - } - else - { - // Approaching start pos again, check if close enough + // furthestDistanceToStart did not update + // i.e. we might be already getting close to start pos if (lineDistanceToStart < distanceToStartWhenDrawingShouldStop) { return true; } } - // If too many turning points reached, stop drawing - if (fieldLineTurningPoints > maxTurningPoints) - return true; - // If very small field line loop, we also should stop when very close to Start even when we have not yet reached a smaller furthestDistanceToStart bool VeryCloseToStartPos = lineDistanceToStart <= (fieldLine.minLineSegmentLength * 2); return VeryCloseToStartPos; } - - private void UpdateSegmentProperties(float newLineDistanceToStart) - { - bool segmentIsNowReceding = newLineDistanceToStart > lastDistanceToStart; - if (segmentIsNowReceding != PreviousSegmentRecededStartPos()) - { - fieldLineTurningPoints++; - } - lastDistanceToStart = newLineDistanceToStart; - } - - private bool PreviousSegmentRecededStartPos() - { - return fieldLineTurningPoints % 2 == 0; - } }