Refactor ESCMovable._is_angle_in_interval() (#373)
* Refactor ESCMovable._is_angle_in_interval(). Fixes #349 * docs: Automatic update of API docs * Fixes Co-authored-by: StraToN <StraToN@users.noreply.github.com>
This commit is contained in:
@@ -327,7 +327,7 @@ func _get_dir_deg(deg: int, animations: ESCAnimationResource) -> int:
|
|||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
for direction_angle in animations.dir_angles:
|
for direction_angle in animations.dir_angles:
|
||||||
if is_angle_in_interval(deg, direction_angle):
|
if _is_angle_in_interval(deg, direction_angle):
|
||||||
dir = i
|
dir = i
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -353,7 +353,7 @@ func _get_dir_deg(deg: int, animations: ESCAnimationResource) -> int:
|
|||||||
# - direction_angle: ESCDirectionAngle resource, containing the starting angle,
|
# - direction_angle: ESCDirectionAngle resource, containing the starting angle,
|
||||||
# and the size of interval
|
# and the size of interval
|
||||||
# eg: angle_start=90, angle_size=40 corresponds to angle between 90° and 130°
|
# eg: angle_start=90, angle_size=40 corresponds to angle between 90° and 130°
|
||||||
func is_angle_in_interval(
|
func _is_angle_in_interval(
|
||||||
angle: float,
|
angle: float,
|
||||||
direction_angle: ESCDirectionAngle
|
direction_angle: ESCDirectionAngle
|
||||||
) -> bool:
|
) -> bool:
|
||||||
@@ -364,19 +364,47 @@ func is_angle_in_interval(
|
|||||||
var angle_area = direction_angle.angle_size
|
var angle_area = direction_angle.angle_size
|
||||||
var end_angle = wrapi(direction_angle.angle_start + angle_area, 0, 360)
|
var end_angle = wrapi(direction_angle.angle_start + angle_area, 0, 360)
|
||||||
|
|
||||||
if ((angle >= 270 and angle <= 360) \
|
# First we want to test if angle is in upper part of the clock.
|
||||||
or (angle >= 0 and angle <= 90)) \
|
# If it is, we add 180 to all angles so that we test in lower part of the
|
||||||
and wrapi(angle + 180, 0, 360) > wrapi(direction_angle.angle_start
|
# clock, so we avoid messing with calculations wrapping around 360° and 0°.
|
||||||
+ 180, 0, 360) \
|
if _angle_is_between_270_to_90(angle):
|
||||||
and wrapi(angle + 180, 0, 360) <= wrapi(
|
return _angle_is_between(
|
||||||
direction_angle.angle_start + angle_area + 180, 0, 360
|
angle + 180,
|
||||||
):
|
start_angle + 180,
|
||||||
return true
|
start_angle + angle_area + 180
|
||||||
elif wrapi(angle, 0, 360) > start_angle \
|
)
|
||||||
and wrapi(angle, 0, 360) <= end_angle:
|
else:
|
||||||
return true
|
return _angle_is_between(angle, start_angle, end_angle)
|
||||||
|
|
||||||
|
|
||||||
|
# Returns true if angle is in upper part of trigonometric circle
|
||||||
|
# ie. between 0 and PI
|
||||||
|
# ie. between 270° and 90°
|
||||||
|
# ie. between 9 o'clock and 3 o'clock
|
||||||
|
#
|
||||||
|
# #### Parameters
|
||||||
|
#
|
||||||
|
# - angle: the angle in degrees
|
||||||
|
func _angle_is_between_270_to_90(angle: float) -> bool:
|
||||||
|
return (angle >= 270 and angle <= 360) or (angle >= 0 and angle <= 90)
|
||||||
|
|
||||||
|
|
||||||
|
# Returns true if angle is between start angle and end angle. All angle values
|
||||||
|
# will clamped between 0 and 360 degrees.
|
||||||
|
#
|
||||||
|
# #### Parameters
|
||||||
|
#
|
||||||
|
# - angle: the angle in degrees
|
||||||
|
# - start_angle: the start value of the angle interval
|
||||||
|
# - end_angle: the end value of the angle interval
|
||||||
|
func _angle_is_between(
|
||||||
|
angle: float,
|
||||||
|
start_angle: float,
|
||||||
|
end_angle: float
|
||||||
|
) -> bool:
|
||||||
|
return wrapi(angle, 0, 360) >= wrapi(start_angle, 0, 360) \
|
||||||
|
and wrapi(angle, 0, 360) <= wrapi(end_angle, 0, 360)
|
||||||
|
|
||||||
return false
|
|
||||||
|
|
||||||
# Sets character's angle and plays according animation.
|
# Sets character's angle and plays according animation.
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -175,12 +175,6 @@ Update the sprite scale and lighting
|
|||||||
|
|
||||||
- on_event_finished_name: Used if this function is called from an ESC event
|
- on_event_finished_name: Used if this function is called from an ESC event
|
||||||
|
|
||||||
### is\_angle\_in\_interval
|
|
||||||
|
|
||||||
```gdscript
|
|
||||||
func is_angle_in_interval(angle: float, direction_angle: ESCDirectionAngle) -> bool
|
|
||||||
```
|
|
||||||
|
|
||||||
### set\_angle
|
### set\_angle
|
||||||
|
|
||||||
```gdscript
|
```gdscript
|
||||||
|
|||||||
Reference in New Issue
Block a user