mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Don't have joint_angles, unit_normal and path_end_indices get refreshed for shift/scale/rotate
Change unit_normal directly in rotate In general, don't trigger refresh on apply_points_function
This commit is contained in:
parent
7519ce15da
commit
5cf5e497e7
1 changed files with 23 additions and 25 deletions
|
@ -46,6 +46,7 @@ from manimlib.utils.space_ops import get_unit_normal
|
||||||
from manimlib.utils.space_ops import line_intersects_path
|
from manimlib.utils.space_ops import line_intersects_path
|
||||||
from manimlib.utils.space_ops import midpoint
|
from manimlib.utils.space_ops import midpoint
|
||||||
from manimlib.utils.space_ops import rotation_between_vectors
|
from manimlib.utils.space_ops import rotation_between_vectors
|
||||||
|
from manimlib.utils.space_ops import rotation_matrix_transpose
|
||||||
from manimlib.utils.space_ops import poly_line_length
|
from manimlib.utils.space_ops import poly_line_length
|
||||||
from manimlib.utils.space_ops import z_to_vector
|
from manimlib.utils.space_ops import z_to_vector
|
||||||
from manimlib.shader_wrapper import ShaderWrapper
|
from manimlib.shader_wrapper import ShaderWrapper
|
||||||
|
@ -865,11 +866,11 @@ class VMobject(Mobject):
|
||||||
(sums[:, 0] * diffs[:, 1]).sum(), # Add up (x0 + x1)*(y1 - y0)
|
(sums[:, 0] * diffs[:, 1]).sum(), # Add up (x0 + x1)*(y1 - y0)
|
||||||
])
|
])
|
||||||
|
|
||||||
def get_unit_normal(self) -> Vect3:
|
def get_unit_normal(self, refresh: bool = False) -> Vect3:
|
||||||
if self.get_num_points() < 3:
|
if self.get_num_points() < 3:
|
||||||
return OUT
|
return OUT
|
||||||
|
|
||||||
if not self.needs_new_unit_normal:
|
if not self.needs_new_unit_normal and not refresh:
|
||||||
return self.data["base_normal"][1, :]
|
return self.data["base_normal"][1, :]
|
||||||
|
|
||||||
area_vect = self.get_area_vector()
|
area_vect = self.get_area_vector()
|
||||||
|
@ -1218,31 +1219,28 @@ class VMobject(Mobject):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
@triggers_refresh
|
@triggers_refresh
|
||||||
def apply_points_function(self, *args, **kwargs) -> Self:
|
def stretch(self, *args, **kwargs) -> Self:
|
||||||
return super().apply_points_function(*args, **kwargs)
|
return super().stretch(*args, **kwargs)
|
||||||
|
|
||||||
# General calls to apply_points_function should trigger a refresh
|
@triggers_refresh
|
||||||
# to the joint angles, but these common ones shouldn't
|
def apply_matrix(self, *args, **kwargs) -> Self:
|
||||||
def dont_refresh_joint_angles(func: Callable):
|
return super().apply_matrix(*args, **kwargs)
|
||||||
@wraps(func)
|
|
||||||
def wrapper(self, *args, **kwargs):
|
|
||||||
nnja = self.needs_new_joint_angles
|
|
||||||
result = func(self, *args, **kwargs)
|
|
||||||
self.needs_new_joint_angles = nnja
|
|
||||||
return result
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
@dont_refresh_joint_angles
|
def rotate(
|
||||||
def shift(self, *args, **kwargs) -> Self:
|
self,
|
||||||
return super().shift(*args, **kwargs)
|
angle: float,
|
||||||
|
axis: Vect3 = OUT,
|
||||||
@dont_refresh_joint_angles
|
about_point: Vect3 | None = None,
|
||||||
def scale(self, *args, **kwargs) -> Self:
|
**kwargs
|
||||||
return super().scale(*args, **kwargs)
|
) -> Self:
|
||||||
|
rot_matrix_T = rotation_matrix_transpose(angle, axis)
|
||||||
@dont_refresh_joint_angles
|
self.apply_points_function(
|
||||||
def rotate(self, *args, **kwargs) -> Self:
|
lambda points: np.dot(points, rot_matrix_T),
|
||||||
return super().rotate(*args, **kwargs)
|
about_point,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
self.data["base_normal"][1::2] = np.dot(self.data["base_normal"][1::2], rot_matrix_T)
|
||||||
|
return self
|
||||||
|
|
||||||
def set_animating_status(self, is_animating: bool, recurse: bool = True):
|
def set_animating_status(self, is_animating: bool, recurse: bool = True):
|
||||||
super().set_animating_status(is_animating, recurse)
|
super().set_animating_status(is_animating, recurse)
|
||||||
|
|
Loading…
Add table
Reference in a new issue