Skip to content

Commit

Permalink
Replace DEGREES -> DEG
Browse files Browse the repository at this point in the history
  • Loading branch information
3b1b committed Dec 12, 2024
1 parent d8e06c6 commit 8cc5195
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/source/documentation/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Mathematical constant
PI = np.pi
TAU = 2 * PI
DEGREES = TAU / 360
DEG = TAU / 360
Text
----
Expand Down
12 changes: 6 additions & 6 deletions docs/source/getting_started/example_scenes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ InteractiveDevlopment
self.play(ReplacementTransform(square, circle))
self.wait()
self.play(circle.animate.stretch(4, 0))
self.play(Rotate(circle, 90 * DEGREES))
self.play(Rotate(circle, 90 * DEG))
self.play(circle.animate.shift(2 * RIGHT).scale(0.25))

text = Text("""
Expand Down Expand Up @@ -221,7 +221,7 @@ TexTransformExample
self.play(
TransformMatchingTex(
lines[0].copy(), lines[1],
path_arc=90 * DEGREES,
path_arc=90 * DEG,
),
**play_kw
)
Expand Down Expand Up @@ -599,8 +599,8 @@ SurfaceExample
# Set perspective
frame = self.camera.frame
frame.set_euler_angles(
theta=-30 * DEGREES,
phi=70 * DEGREES,
theta=-30 * DEG,
phi=70 * DEG,
)

surface = surfaces[0]
Expand All @@ -624,8 +624,8 @@ SurfaceExample
self.play(
Transform(surface, surfaces[2]),
# Move camera frame during the transition
frame.animate.increment_phi(-10 * DEGREES),
frame.animate.increment_theta(-20 * DEGREES),
frame.animate.increment_phi(-10 * DEG),
frame.animate.increment_theta(-20 * DEG),
run_time=3
)
# Add ambient rotation
Expand Down
10 changes: 5 additions & 5 deletions example_scenes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def construct(self):
# to go to a non-equal substring from the target,
# use the key map.
key_map={"+": "-"},
path_arc=90 * DEGREES,
path_arc=90 * DEG,
),
)
self.wait()
Expand All @@ -203,7 +203,7 @@ def construct(self):
TransformMatchingStrings(
lines[2].copy(), lines[3],
key_map={"2": R"\sqrt"},
path_arc=-30 * DEGREES,
path_arc=-30 * DEG,
),
)
self.wait(2)
Expand Down Expand Up @@ -616,8 +616,8 @@ def construct(self):
self.play(
Transform(surface, surfaces[2]),
# Move camera frame during the transition
self.frame.animate.increment_phi(-10 * DEGREES),
self.frame.animate.increment_theta(-20 * DEGREES),
self.frame.animate.increment_phi(-10 * DEG),
self.frame.animate.increment_theta(-20 * DEG),
run_time=3
)
# Add ambient rotation
Expand Down Expand Up @@ -666,7 +666,7 @@ def construct(self):
self.play(ReplacementTransform(square, circle))
self.wait()
self.play(circle.animate.stretch(4, 0))
self.play(Rotate(circle, 90 * DEGREES))
self.play(Rotate(circle, 90 * DEG))
self.play(circle.animate.shift(2 * RIGHT).scale(0.25))

text = Text("""
Expand Down
4 changes: 2 additions & 2 deletions manimlib/animation/indication.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from manimlib.constants import FRAME_X_RADIUS, FRAME_Y_RADIUS
from manimlib.constants import ORIGIN, RIGHT, UP
from manimlib.constants import SMALL_BUFF
from manimlib.constants import DEGREES
from manimlib.constants import DEG
from manimlib.constants import TAU
from manimlib.constants import GREY, YELLOW
from manimlib.mobject.geometry import Circle
Expand Down Expand Up @@ -395,7 +395,7 @@ def interpolate_submobject(


class TurnInsideOut(Transform):
def __init__(self, mobject: Mobject, path_arc: float = 90 * DEGREES, **kwargs):
def __init__(self, mobject: Mobject, path_arc: float = 90 * DEG, **kwargs):
super().__init__(mobject, path_arc=path_arc, **kwargs)

def create_target(self) -> Mobject:
Expand Down
4 changes: 2 additions & 2 deletions manimlib/animation/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np

from manimlib.animation.animation import Animation
from manimlib.constants import DEGREES
from manimlib.constants import DEG
from manimlib.constants import OUT
from manimlib.mobject.mobject import Group
from manimlib.mobject.mobject import Mobject
Expand Down Expand Up @@ -314,7 +314,7 @@ def init_path_func(self) -> None:


class CyclicReplace(Transform):
def __init__(self, *mobjects: Mobject, path_arc=90 * DEGREES, **kwargs):
def __init__(self, *mobjects: Mobject, path_arc=90 * DEG, **kwargs):
super().__init__(Group(*mobjects), path_arc=path_arc, **kwargs)

def create_target(self) -> Mobject:
Expand Down
8 changes: 4 additions & 4 deletions manimlib/camera/camera_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from scipy.spatial.transform import Rotation

from manimlib.constants import DEGREES, RADIANS
from manimlib.constants import DEG, RADIANS
from manimlib.constants import FRAME_SHAPE
from manimlib.constants import DOWN, LEFT, ORIGIN, OUT, RIGHT, UP
from manimlib.constants import PI
Expand All @@ -26,7 +26,7 @@ def __init__(
frame_shape: tuple[float, float] = FRAME_SHAPE,
center_point: Vect3 = ORIGIN,
# Field of view in the y direction
fovy: float = 45 * DEGREES,
fovy: float = 45 * DEG,
euler_axes: str = "zxz",
# This keeps it ordered first in a scene
z_index=-1,
Expand Down Expand Up @@ -181,7 +181,7 @@ def reorient(
Shortcut for set_euler_angles, defaulting to taking
in angles in degrees
"""
self.set_euler_angles(theta_degrees, phi_degrees, gamma_degrees, units=DEGREES)
self.set_euler_angles(theta_degrees, phi_degrees, gamma_degrees, units=DEG)
if center is not None:
self.move_to(np.array(center))
if height is not None:
Expand Down Expand Up @@ -209,7 +209,7 @@ def increment_gamma(self, dgamma: float, units=RADIANS):
self.increment_euler_angles(dgamma=dgamma, units=units)
return self

def add_ambient_rotation(self, angular_speed=1 * DEGREES):
def add_ambient_rotation(self, angular_speed=1 * DEG):
self.add_updater(lambda m, dt: m.increment_theta(angular_speed * dt))
return self

Expand Down
5 changes: 3 additions & 2 deletions manimlib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@
# Angles
PI: float = np.pi
TAU: float = 2 * PI
DEGREES: float = TAU / 360
DEG: float = TAU / 360
DEGREES = DEG # Many older animations use teh full name
# Nice to have a constant for readability
# when juxtaposed with expressions like 30 * DEGREES
# when juxtaposed with expressions like 30 * DEG
RADIANS: float = 1

# Related to Text
Expand Down
6 changes: 3 additions & 3 deletions manimlib/mobject/coordinate_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import itertools as it

from manimlib.constants import BLACK, BLUE, BLUE_D, BLUE_E, GREEN, GREY_A, WHITE, RED
from manimlib.constants import DEGREES, PI
from manimlib.constants import DEG, PI
from manimlib.constants import DL, UL, DOWN, DR, LEFT, ORIGIN, OUT, RIGHT, UP
from manimlib.constants import FRAME_X_RADIUS, FRAME_Y_RADIUS
from manimlib.constants import MED_SMALL_BUFF, SMALL_BUFF
Expand Down Expand Up @@ -307,7 +307,7 @@ def get_graph_label(

point = self.input_to_graph_point(x, graph)
angle = self.angle_of_tangent(x, graph)
normal = rotate_vector(RIGHT, angle + 90 * DEGREES)
normal = rotate_vector(RIGHT, angle + 90 * DEG)
if normal[1] < 0:
normal *= -1
label.next_to(point, normal, buff=buff)
Expand Down Expand Up @@ -474,7 +474,7 @@ def __init__(
),
length=height,
)
self.y_axis.rotate(90 * DEGREES, about_point=ORIGIN)
self.y_axis.rotate(90 * DEG, about_point=ORIGIN)
# Add as a separate group in case various other
# mobjects are added to self, as for example in
# NumberPlane below
Expand Down
4 changes: 2 additions & 2 deletions manimlib/mobject/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from manimlib.constants import DL, DOWN, DR, LEFT, ORIGIN, OUT, RIGHT, UL, UP, UR
from manimlib.constants import GREY_A, RED, WHITE, BLACK
from manimlib.constants import MED_SMALL_BUFF, SMALL_BUFF
from manimlib.constants import DEGREES, PI, TAU
from manimlib.constants import DEG, PI, TAU
from manimlib.mobject.mobject import Mobject
from manimlib.mobject.types.vectorized_mobject import DashedVMobject
from manimlib.mobject.types.vectorized_mobject import VGroup
Expand Down Expand Up @@ -983,7 +983,7 @@ def __init__(
):
# Defaults to 0 for odd, 90 for even
if start_angle is None:
start_angle = (n % 2) * 90 * DEGREES
start_angle = (n % 2) * 90 * DEG
start_vect = rotate_vector(radius * RIGHT, start_angle)
vertices = compass_directions(n, start_vect)
super().__init__(*vertices, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions manimlib/mobject/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from manimlib.constants import DOWN, LEFT, RIGHT, ORIGIN
from manimlib.constants import DEGREES
from manimlib.constants import DEG
from manimlib.mobject.numbers import DecimalNumber
from manimlib.mobject.svg.tex_mobject import Tex
from manimlib.mobject.types.vectorized_mobject import VGroup
Expand Down Expand Up @@ -196,7 +196,7 @@ def swap_entries_for_ellipses(
dots.set_width(hdots_width)
self.swap_entry_for_dots(row[col_index], dots)
if use_vdots and use_hdots:
rows[row_index][col_index].rotate(-45 * DEGREES)
rows[row_index][col_index].rotate(-45 * DEG)
return self

def get_mob_matrix(self) -> VMobjectMatrixType:
Expand Down
4 changes: 2 additions & 2 deletions manimlib/mobject/mobject_update_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import inspect

from manimlib.constants import DEGREES
from manimlib.constants import DEG
from manimlib.constants import RIGHT
from manimlib.mobject.mobject import Mobject
from manimlib.utils.simple_functions import clip
Expand Down Expand Up @@ -71,7 +71,7 @@ def always_shift(

def always_rotate(
mobject: Mobject,
rate: float = 20 * DEGREES,
rate: float = 20 * DEG,
**kwargs
) -> Mobject:
mobject.add_updater(
Expand Down
8 changes: 4 additions & 4 deletions manimlib/mobject/types/vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from manimlib.constants import GREY_A, GREY_C, GREY_E
from manimlib.constants import BLACK
from manimlib.constants import DEFAULT_STROKE_WIDTH
from manimlib.constants import DEGREES
from manimlib.constants import DEG
from manimlib.constants import ORIGIN, OUT
from manimlib.constants import PI
from manimlib.constants import TAU
Expand Down Expand Up @@ -490,7 +490,7 @@ def add_cubic_bezier_curve_to(
v1 = handle1 - last
v2 = anchor - handle2
angle = angle_between_vectors(v1, v2)
if self.use_simple_quadratic_approx and angle < 45 * DEGREES:
if self.use_simple_quadratic_approx and angle < 45 * DEG:
quad_approx = [last, find_intersection(last, v1, anchor, -v2), anchor]
else:
quad_approx = get_quadratic_approximation_of_cubic(
Expand Down Expand Up @@ -616,7 +616,7 @@ def subdivide_curves_by_condition(

def subdivide_sharp_curves(
self,
angle_threshold: float = 30 * DEGREES,
angle_threshold: float = 30 * DEG,
recurse: bool = True
) -> Self:
def tuple_to_subdivisions(b0, b1, b2):
Expand Down Expand Up @@ -656,7 +656,7 @@ def set_points_smoothly(
self.make_smooth(approx=approx)
return self

def is_smooth(self, angle_tol=1 * DEGREES) -> bool:
def is_smooth(self, angle_tol=1 * DEG) -> bool:
angles = np.abs(self.get_joint_angles()[0::2])
return (angles < angle_tol).all()

Expand Down
4 changes: 2 additions & 2 deletions manimlib/scene/interactive_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from manimlib.constants import DL, DOWN, DR, LEFT, ORIGIN, RIGHT, UL, UP, UR
from manimlib.constants import FRAME_WIDTH, FRAME_HEIGHT, SMALL_BUFF
from manimlib.constants import PI
from manimlib.constants import DEGREES
from manimlib.constants import DEG
from manimlib.constants import MANIM_COLORS, WHITE, GREY_A, GREY_C
from manimlib.mobject.geometry import Line
from manimlib.mobject.geometry import Rectangle
Expand Down Expand Up @@ -625,7 +625,7 @@ def copy_frame_positioning(self):
angles = frame.get_euler_angles()

call = f"reorient("
theta, phi, gamma = (angles / DEGREES).astype(int)
theta, phi, gamma = (angles / DEG).astype(int)
call += f"{theta}, {phi}, {gamma}"
if any(center != 0):
call += f", {tuple(np.round(center, 2))}"
Expand Down

0 comments on commit 8cc5195

Please sign in to comment.