File tree Expand file tree Collapse file tree 3 files changed +48
-7
lines changed Expand file tree Collapse file tree 3 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -624,7 +624,31 @@ def get_curve_functions_with_lengths(
624624 for n in range (num_curves ):
625625 yield self .get_nth_curve_function_with_length (n , ** kwargs )
626626
627- def point_from_proportion (self , alpha ):
627+ def point_from_proportion (self , alpha : float ) -> np .ndarray :
628+ """Gets the point at a proportion along the path of the :class:`OpenGLVMobject`.
629+
630+ Parameters
631+ ----------
632+ alpha
633+ The proportion along the the path of the :class:`OpenGLVMobject`.
634+
635+ Returns
636+ -------
637+ :class:`numpy.ndarray`
638+ The point on the :class:`OpenGLVMobject`.
639+
640+ Raises
641+ ------
642+ :exc:`ValueError`
643+ If ``alpha`` is not between 0 and 1.
644+ :exc:`Exception`
645+ If the :class:`OpenGLVMobject` has no points.
646+ """
647+
648+ if alpha < 0 or alpha > 1 :
649+ raise ValueError (f"Alpha { alpha } not between 0 and 1." )
650+
651+ self .throw_error_if_no_points ()
628652 if alpha == 1 :
629653 return self .get_points ()[- 1 ]
630654
Original file line number Diff line number Diff line change @@ -977,20 +977,30 @@ def get_curve_functions_with_lengths(
977977 yield self .get_nth_curve_function_with_length (n , ** kwargs )
978978
979979 def point_from_proportion (self , alpha : float ) -> np .ndarray :
980- """Get the bezier curve evaluated at a position P,
981- where P is the point corresponding to the proportion defined by the given alpha.
980+ """Gets the point at a proportion along the path of the :class:`VMobject`.
982981
983982 Parameters
984983 ----------
985- alpha : float
986- Proportion .
984+ alpha
985+ The proportion along the the path of the :class:`VMobject` .
987986
988987 Returns
989988 -------
990- np.ndarray
991- Point evaluated.
989+ :class:`numpy.ndarray`
990+ The point on the :class:`VMobject`.
991+
992+ Raises
993+ ------
994+ :exc:`ValueError`
995+ If ``alpha`` is not between 0 and 1.
996+ :exc:`Exception`
997+ If the :class:`VMobject` has no points.
992998 """
993999
1000+ if alpha < 0 or alpha > 1 :
1001+ raise ValueError (f"Alpha { alpha } not between 0 and 1." )
1002+
1003+ self .throw_error_if_no_points ()
9941004 if alpha == 1 :
9951005 return self .get_points ()[- 1 ]
9961006
Original file line number Diff line number Diff line change @@ -20,6 +20,13 @@ def test_vmobject_point_from_propotion():
2020 # would be at length 3, which lands in the first, long line.
2121 assert np .all (obj .point_from_proportion (0.5 ) == np .array ([3 , 0 , 0 ]))
2222
23+ with pytest .raises (ValueError , match = "between 0 and 1" ):
24+ obj .point_from_proportion (2 )
25+
26+ obj .clear_points ()
27+ with pytest .raises (Exception , match = "with no points" ):
28+ obj .point_from_proportion (0 )
29+
2330
2431def test_vgroup_init ():
2532 """Test the VGroup instantiation."""
You can’t perform that action at this time.
0 commit comments