points¶
- class janim.components.points.Cmpt_Points(*args, **kwargs)¶
Bases:
Component,Generic- static resize_func(array: ~numpy.ndarray, length: int, fall_back: ~typing.Callable[[int], ~numpy.ndarray] = <function <lambda>>) ndarray¶
- init_bind(bind: BindInfo)¶
Used for
Item._init_componentsSubclasses can inherit this function to perform item-related processing
- copy() Self¶
- become(other: Cmpt_Points) Self¶
- not_changed(other: Cmpt_Points) bool¶
- classmethod align_for_interpolate(cmpt1: Cmpt_Points, cmpt2: Cmpt_Points) AlignedData[Self]¶
- interpolate(cmpt1: ~typing.Self, cmpt2: ~typing.Self, alpha: float, *, path_func: PathFunc = <function straight_path>) None¶
- get() ndarray¶
Get the points
- get_all() ndarray¶
Get all points for self and descendant-items
- set(points: VectArray) Self¶
Set point coordinate data, with each point having three components
Use a format like
.set([[1.5, 3, 2], [2, 1.5, 0]])
- clear() Self¶
Clear points
- extend(points: VectArray) Self¶
Append point coordinate data, with each point having three components
Use a format like
.append([[1.5, 3, 2], [2, 1.5, 0]])
- reverse() Self¶
Reverse the order of points
- resize(length: int) Self¶
- count() int¶
The count of points
- has() bool¶
Checks if having points
- get_start() ndarray¶
Get the first point
- get_end() ndarray¶
Get the last point
- get_start_and_end() tuple[ndarray, ndarray]¶
Get the first and last points
- point_from_proportion(alpha: float) ndarray¶
Treats the points as a path connected by line segments, and returns the point at proportion
alphaalong the entire path.The behavior is different for the curve path component
Cmpt_VPoints. Please refer topoint_from_proportion().
- pfp(alpha) ndarray¶
Abbreviation for
point_from_proportion()
- property box: BoundingBox¶
Rectangular bounding box of the item (including descendant-items)
- property self_box: BoundingBox¶
Same as
box, but only represents the bounding box of its ownpoints, excluding descendant-items
- class BoundingBox(points: VectArray)¶
Bases:
objectBounding box,
self.dataincludes three elements representing the bottom-left, center, and top-right- static compute(points: VectArray) ndarray¶
Calculates the left-bottom, center, and right-top points of the bounding box based on the provided
points
- get(direction: Vect) ndarray¶
Get the coordinates on the borders of the bounding box
Examples:
If
URis passed, it returns the coordinates of the upper-right corner of the bounding boxIf
RIGHTis passed, it returns the coordinates of the center on the right side of the bounding box
- get_continuous(direction: Vect) ndarray¶
Get the intersection point between a ray, emitted from the center in the direction of
direction, and the bounding box
- get_corners() ndarray¶
Get the eight vertices of the bounding box (cube)
- property top: ndarray¶
- property bottom: ndarray¶
- property right: ndarray¶
- property left: ndarray¶
- property zenith: ndarray¶
- property nadir: ndarray¶
- property center: ndarray¶
- length_over_dim(dim: int) float¶
- property width: float¶
- property height: float¶
- property depth: float¶
- property size: tuple[float, float]¶
That is, (width, height)
- coord(dim: int, direction=array([0., 0., 0.])) float¶
- get_x(direction=array([0., 0., 0.])) float¶
- property x: float¶
- get_y(direction=array([0., 0., 0.])) float¶
- property y: float¶
- get_z(direction=array([0., 0., 0.])) float¶
- property z: float¶
- apply_points_fn(func: PointsFn, *, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Applies the given function
functo all points as a single parameter, and see the result as new pointsConsiders
about_pointas the origin. If it’sNone, then the edge in theabout_edgedirection is considered asabout_point
- apply_point_fn(func: PointFn, *, about_point: Vect | None = array([0., 0., 0.]), about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Applies the given function
functo each point individually for transformationDefault to applying the transformation about the origin, not items center
- apply_matrix(matrix: VectArray, *, about_point: Vect | None = None, about_edge: Vect | None = None, root_only: bool = False) Self¶
Apply a matrix transformation to the
pointsDefault to applying the transformation about the origin, not items center
- apply_complex_fn(func: ComplexFn, *, about_point: Vect | None = array([0., 0., 0.]), about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
“Apply a complex-valued function to the
pointsDefault to applying the transformation about the origin, not items center
- rotate(angle: float, *, axis: Vect = array([0., 0., 1.]), about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Rotate the item by an
anglearound the specifiedaxis, with an optionalabout_pointabout which the rotation should be performed
- flip(axis: Vect = array([0., 1., 0.]), *, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Flip the item around the specified axis
- scale(scale_factor: float | Iterable, *, min_scale_factor: float = 1e-08, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Scale the item by a specified factor
If the scale factor provided is an iterable object, each element will be used as the scaling factor for the corresponding coordinate component. For example, if
scale_factoris(2, 0.5, 1), the item will be scaled by a factor of 2 along thexaxis, compressed by half along theyaxis, and remain unchanged along thezaxis
- stretch(factor: float, *, dim: int, min_scale_factor: float = 1e-08, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Stretch the object along the specified
dimdirection
- rescale_to_fit(length: float, *, dim: int, stretch: bool = False, min_scale_factor: float = 1e-08, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
- set_width(width: float, *, stretch: bool = False, **kwargs) Self¶
If
stretchisFalse(default), it indicates proportional scaling
- set_height(height: float, *, stretch: bool = False, **kwargs) Self¶
If
stretchisFalse(default), it indicates proportional scaling
- set_depth(depth: float, *, stretch: bool = False, **kwargs) Self¶
If
stretchisFalse(default), it indicates proportional scaling
- set_size(width: float | None = None, height: float | None = None, depth: float | None = None, **kwargs) Self¶
- replace(item: Item, dim_to_match: int = 0, *, stretch: bool = False, root_only: bool = False, item_root_only: bool = False) Self¶
Moves to the position of the specified
itemand matches the length in thedim_to_matchdimension
- surround(item: Item, dim_to_match: int = 0, *, stretch: bool = False, buff: float = 0.25, root_only: bool = False, item_root_only: bool = False) Self¶
Similar to
replacebut leaves a buffer space ofbuffaround the item
- shear(factor: float = 0.2, direction: Vect = array([1., 0., 0.]), *, about_point: Vect | None = None, about_edge: Vect = array([0., 0., 0.]), root_only: bool = False) Self¶
Shear
factorrepresents the degree of shearingdirectionrepresents the direction of shearingYou can pass
about_pointorabout_edgeto control the reference point
- put_start_and_end_on(start: Vect, end: Vect) Self¶
Rotate and scale this item such that its start and end points are positioned at
startandend
- property unit_normal: ndarray¶
Calculate the unit normal vector of the fitted plane for a 3D point set
- face_to_vector(vector: Vect, *, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Rotate the item to align its normal direction with
vectorConsiders
about_pointas the origin. If it’sNone, then the edge in theabout_edgedirection is considered asabout_point
- face_to_camera(camera: Camera | types.EllipsisType = Ellipsis, *, rotate: float = 0, inverse: bool = False, normal_vector: Vect | types.EllipsisType = Ellipsis, about_point: Vect | None = None, about_edge: Vect | None = array([0., 0., 0.]), root_only: bool = False) Self¶
Make the item face the camera
Useful parameters:
rotate: The angle to rotate around the camera’s view direction after facing the camerainverse: Whether to make the item face away from the cameraConsiders
about_pointas the origin. If it’sNone, then the edge in theabout_edgedirection is considered asabout_point
You can manually specify
cameraand normal vectornormal_vector; if not provided, they will be automatically obtained:cameradefaults toself.cameraof the timelinenormal_vectoris calculated byunit_normal()by default
- shift(vector: Vect, *, root_only=False) Self¶
Shift by the specified
vector
- move_to(target: Item | Vect, *, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, item_root_only: bool = False) Self¶
Move to the position of
target
- move_to_by_indicator(indicator: Item, target: Item | Vect, *, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, indicator_root_only: bool = False, item_root_only: bool = False) Self¶
Similar to
move_to(), but this method calculates the displacement where theindicatoris moved totarget, rather than the displacement whereselfis moved totargetinmove_to()Examples:
t1 = TypstMath('x^2 + y^2') t2 = TypstMath('x + y') t2.points.move_to_by_indicator(t2[1], t1[2])
Can move
t2to the position oft1, and align the plus sign oft2with the plus sign oft1Note
This example would be more concise using
match_pattern()
- align_to(item_or_point: Item | Vect, direction: Vect = array([0., 0., 0.]), *, root_only: bool = False, item_root_only: bool = False) Self¶
Align
For example,
item1.align_to(item2, UP)will moveitem1vertically so that its top aligns with the top edge ofitem2
- arrange(direction: Vect = array([1., 0., 0.]), center: bool = True, **kwargs) Self¶
Arrange child items along the
direction
- arrange_in_grid(n_rows: int | None = None, n_cols: int | None = None, buff: float | None = None, h_buff: float | None = None, v_buff: float | None = None, aligned_edge: ndarray = array([0., 0., 0.]), by_center_point: bool = False, fill_rows_first: bool = True) Self¶
Arrange child items in a grid layout
n_rows,n_cols: Number of rows and columnsv_buff,h_buff: Vertical and horizontal spacingaligned_edge: Aligned edgeby_center_point: Default isFalse; if set toTrue, items are treated only as center points, ignoring their width and height
- arrange_by_offset(offset: Vect, *, aligned_edge: Vect = array([0., 0., 0.]), center: bool = True) Self¶
- to_center(*, root_only=False) Self¶
Move this item to the origin
(0, 0, 0)
- to_border(direction: Vect, buff: float = 0.5) Self¶
Move to the border of the frame
- next_to(target: Item | Vect, direction: Vect = array([1., 0., 0.]), *, buff: float = 0.25, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, item_root_only: bool = False) Self¶
Position this item next to
target
- next_to_by_indicator(indicator: Item, target: Item | Vect, direction: Vect = array([1., 0., 0.]), *, buff: float = 0.25, aligned_edge: Vect = array([0., 0., 0.]), coor_mask: Iterable = (1, 1, 1), root_only: bool = False, indicator_root_only: bool = False, item_root_only: bool = False) Self¶
Similar to
next_to(), but this method calculates the displacement where theindicatoris placed next totarget, rather than the displacement whereselfis placed next totargetinmove_to()Examples:
t1 = Typst('x^2 + y^2') t2 = Typst('x + y z w') t2.points.next_to_by_indicator(t2[1], t1[2], DOWN)
Can align
t1belowt2, and place the plus sign oft1directly below the plus sign oft2Note
This example can also use character indexing
- shift_onto_screen(**kwargs) Self¶
- shift_onto_screen_along_direction(direction: Vect, *, buff: float = 0.5) Self¶
- set_coord(value: float, *, dim: int, direction: Vect = array([0., 0., 0.]), root_only=False) Self¶
- set_x(x: float, direction: Vect = array([0., 0., 0.])) Self¶
- set_y(y: float, direction: Vect = array([0., 0., 0.])) Self¶
- set_z(z: float, direction: Vect = array([0., 0., 0.])) Self¶