Feature: argument coor_mask for move_to / next_to:

setting coor_mask = X_AXIS or Y_AXIS makes the alignment in just one coordinate
This commit is contained in:
mirefek
2018-02-12 22:41:34 +01:00
parent bc83c8a4f3
commit 6b39ba0502
2 changed files with 8 additions and 3 deletions

View File

@ -53,6 +53,9 @@ RIGHT = np.array(( 1., 0., 0.))
LEFT = np.array((-1., 0., 0.))
IN = np.array(( 0., 0.,-1.))
OUT = np.array(( 0., 0., 1.))
X_AXIS = np.array(( 1., 0., 0.))
Y_AXIS = np.array(( 0., 1., 0.))
Z_AXIS = np.array(( 0., 0., 1.))
TOP = SPACE_HEIGHT*UP
BOTTOM = SPACE_HEIGHT*DOWN

View File

@ -296,6 +296,7 @@ class Mobject(Container):
aligned_edge = ORIGIN,
submobject_to_align = None,
index_of_submobject_to_align = None,
coor_mask = np.array([1,1,1]),
):
if isinstance(mobject_or_point, Mobject):
mob = mobject_or_point
@ -315,7 +316,7 @@ class Mobject(Container):
else:
aligner = self
point_to_align = aligner.get_critical_point(aligned_edge - direction)
self.shift(target_point - point_to_align + buff*direction)
self.shift((target_point - point_to_align + buff*direction)*coor_mask)
return self
def align_to(self, mobject_or_point, direction = ORIGIN, alignment_vect = UP):
@ -403,13 +404,14 @@ class Mobject(Container):
submob.scale(1./factor)
return self
def move_to(self, point_or_mobject, aligned_edge = ORIGIN):
def move_to(self, point_or_mobject, aligned_edge = ORIGIN,
coor_mask = np.array([1,1,1])):
if isinstance(point_or_mobject, Mobject):
target = point_or_mobject.get_critical_point(aligned_edge)
else:
target = point_or_mobject
point_to_align = self.get_critical_point(aligned_edge)
self.shift(target - point_to_align)
self.shift((target - point_to_align)*coor_mask)
return self
def replace(self, mobject, dim_to_match = 0, stretch = False):