Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename InternalPoint3D to Point3D, Point3D to Point3DLike and other point-related type aliases #4027

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 38 additions & 27 deletions manim/mobject/geometry/arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@
from manim.mobject.text.tex_mobject import SingleStringMathTex, Tex
from manim.mobject.text.text_mobject import Text
from manim.typing import (
CubicBezierPoints,
InternalPoint3D,
Point3D,
QuadraticBezierPoints,
Point3DLike,
QuadraticSpline,
Vector3D,
)

Expand Down Expand Up @@ -269,22 +268,27 @@
def get_default_tip_length(self) -> float:
return self.tip_length

def get_first_handle(self) -> InternalPoint3D:
def get_first_handle(self) -> Point3D:
# Type inference of extracting an element from a list, is not
# supported by numpy, see this numpy issue
# https://github.com/numpy/numpy/issues/16544
return self.points[1]
first_handle: Point3D = self.points[1]
return first_handle

def get_last_handle(self) -> InternalPoint3D:
return self.points[-2]
def get_last_handle(self) -> Point3D:
# Type inference of extracting an element from a list, is not
# supported by numpy, see this numpy issue
# https://github.com/numpy/numpy/issues/16544
last_handle: Point3D = self.points[-2]
return last_handle

def get_end(self) -> InternalPoint3D:
def get_end(self) -> Point3D:
if self.has_tip():
return self.tip.get_start()
else:
return super().get_end()

def get_start(self) -> InternalPoint3D:
def get_start(self) -> Point3D:
if self.has_start_tip():
return self.start_tip.get_start()
else:
Expand Down Expand Up @@ -316,7 +320,7 @@
start_angle: float = 0,
angle: float = TAU / 4,
num_components: int = 9,
arc_center: InternalPoint3D = ORIGIN,
arc_center: Point3D = ORIGIN,
**kwargs: Any,
):
if radius is None: # apparently None is passed by ArcBetweenPoints
Expand Down Expand Up @@ -351,7 +355,7 @@
@staticmethod
def _create_quadratic_bezier_points(
angle: float, start_angle: float = 0, n_components: int = 8
) -> QuadraticBezierPoints:
) -> QuadraticSpline:
samples = np.array(
[
[np.cos(a), np.sin(a), 0]
Expand Down Expand Up @@ -394,7 +398,7 @@
handles2 = anchors[1:] - (d_theta / 3) * tangent_vectors[1:]
self.set_anchors_and_handles(anchors[:-1], handles1, handles2, anchors[1:])

def get_arc_center(self, warning: bool = True) -> InternalPoint3D:
def get_arc_center(self, warning: bool = True) -> Point3D:
"""Looks at the normals to the first two
anchors, and finds their intersection points
"""
Expand Down Expand Up @@ -422,7 +426,7 @@
self._failed_to_get_center = True
return np.array(ORIGIN)

def move_arc_center_to(self, point: InternalPoint3D) -> Self:
def move_arc_center_to(self, point: Point3D) -> Self:
self.shift(point - self.get_arc_center())
return self

Expand Down Expand Up @@ -454,8 +458,8 @@

def __init__(
self,
start: Point3D,
end: Point3D,
start: Point3DLike,
end: Point3DLike,
angle: float = TAU / 4,
radius: float | None = None,
**kwargs: Any,
Expand Down Expand Up @@ -484,14 +488,18 @@
if radius is None:
center = self.get_arc_center(warning=False)
if not self._failed_to_get_center:
temp_radius: float = np.linalg.norm(np.array(start) - np.array(center))
self.radius = temp_radius
# np.linalg.norm returns floating[Any] which is not compatible with float
self.radius = cast(
float, np.linalg.norm(np.array(start) - np.array(center))
)
Dismissed Show dismissed Hide dismissed
else:
self.radius = np.inf


class CurvedArrow(ArcBetweenPoints):
def __init__(self, start_point: Point3D, end_point: Point3D, **kwargs: Any) -> None:
def __init__(
self, start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any
) -> None:
from manim.mobject.geometry.tips import ArrowTriangleFilledTip

tip_shape = kwargs.pop("tip_shape", ArrowTriangleFilledTip)
Expand All @@ -500,7 +508,9 @@


class CurvedDoubleArrow(CurvedArrow):
def __init__(self, start_point: Point3D, end_point: Point3D, **kwargs: Any) -> None:
def __init__(
self, start_point: Point3DLike, end_point: Point3DLike, **kwargs: Any
) -> None:
if "tip_shape_end" in kwargs:
kwargs["tip_shape"] = kwargs.pop("tip_shape_end")
from manim.mobject.geometry.tips import ArrowTriangleFilledTip
Expand Down Expand Up @@ -637,7 +647,7 @@

@staticmethod
def from_three_points(
p1: Point3D, p2: Point3D, p3: Point3D, **kwargs: Any
p1: Point3DLike, p2: Point3DLike, p3: Point3DLike, **kwargs: Any
) -> Circle:
"""Returns a circle passing through the specified
three points.
Expand All @@ -661,7 +671,8 @@
perpendicular_bisector([np.asarray(p1), np.asarray(p2)]),
perpendicular_bisector([np.asarray(p2), np.asarray(p3)]),
)
radius: float = np.linalg.norm(p1 - center)
# np.linalg.norm returns floating[Any] which is not compatible with float
radius = cast(float, np.linalg.norm(p1 - center))
return Circle(radius=radius, **kwargs).shift(center)


Expand Down Expand Up @@ -698,7 +709,7 @@

def __init__(
self,
point: Point3D = ORIGIN,
point: Point3DLike = ORIGIN,
radius: float = DEFAULT_DOT_RADIUS,
stroke_width: float = 0,
fill_opacity: float = 1.0,
Expand Down Expand Up @@ -1006,10 +1017,10 @@

def __init__(
self,
start_anchor: CubicBezierPoints,
start_handle: CubicBezierPoints,
end_handle: CubicBezierPoints,
end_anchor: CubicBezierPoints,
start_anchor: Point3DLike,
start_handle: Point3DLike,
end_handle: Point3DLike,
end_anchor: Point3DLike,
**kwargs: Any,
) -> None:
super().__init__(**kwargs)
Expand Down Expand Up @@ -1097,7 +1108,7 @@

def __init__(
self,
*vertices: Point3D,
*vertices: Point3DLike,
angle: float = PI / 4,
radius: float | None = None,
arc_config: list[dict] | None = None,
Expand Down
11 changes: 6 additions & 5 deletions manim/mobject/geometry/boolean_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
from manim.mobject.types.vectorized_mobject import VMobject

if TYPE_CHECKING:
from collections.abc import Sequence
from typing import Any

from manim.typing import InternalPoint3D_Array, Point2D_Array
from manim.typing import Point2DLike, Point3D_Array, Point3DLike

from ...constants import RendererType

Expand All @@ -30,17 +31,17 @@ class _BooleanOps(VMobject, metaclass=ConvertToOpenGL):

def _convert_2d_to_3d_array(
self,
points: Point2D_Array,
points: Sequence[Point2DLike | Point3DLike],
z_dim: float = 0.0,
) -> InternalPoint3D_Array:
) -> Point3D_Array:
"""Converts an iterable with coordinates in 2D to 3D by adding
:attr:`z_dim` as the Z coordinate.

Parameters
----------
points:
points
An iterable of points.
z_dim:
z_dim
Default value for the Z coordinate.

Returns
Expand Down
10 changes: 7 additions & 3 deletions manim/mobject/geometry/labeled.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
if TYPE_CHECKING:
from typing import Any

from manim.typing import Point3D_Array
from manim.typing import Point3DLike_Array


class Label(VGroup):
Expand Down Expand Up @@ -344,7 +344,7 @@ def construct(self):

def __init__(
self,
*vertex_groups: Point3D_Array,
*vertex_groups: Point3DLike_Array,
label: str | Tex | MathTex | Text,
precision: float = 0.01,
label_config: dict[str, Any] | None = None,
Expand All @@ -365,7 +365,11 @@ def __init__(

# Close Vertex Groups
rings = [
group if np.array_equal(group[0], group[-1]) else list(group) + [group[0]]
np.asarray(
group
if np.array_equal(group[0], group[-1])
else list(group) + [group[0]]
)
for group in vertex_groups
]

Expand Down
Loading