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_components

Subclasses 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 alpha along the entire path.

The behavior is different for the curve path component Cmpt_VPoints. Please refer to point_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 own points, excluding descendant-items

class BoundingBox(points: VectArray)

Bases: object

Bounding box, self.data includes 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 UR is passed, it returns the coordinates of the upper-right corner of the bounding box

  • If RIGHT is 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 func to all points as a single parameter, and see the result as new points

Considers about_point as the origin. If it’s None, then the edge in the about_edge direction is considered as about_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 func to each point individually for transformation

Default 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 points

Default 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 points

Default 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 angle around the specified axis, with an optional about_point about 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_factor is (2, 0.5, 1), the item will be scaled by a factor of 2 along the x axis, compressed by half along the y axis, and remain unchanged along the z axis

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 dim direction

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 stretch is False (default), it indicates proportional scaling

set_height(height: float, *, stretch: bool = False, **kwargs) Self

If stretch is False (default), it indicates proportional scaling

set_depth(depth: float, *, stretch: bool = False, **kwargs) Self

If stretch is False (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 item and matches the length in the dim_to_match dimension

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 replace but leaves a buffer space of buff around 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

  • factor represents the degree of shearing

  • direction represents the direction of shearing

  • You can pass about_point or about_edge to 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 start and end

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 vector

  • Considers about_point as the origin. If it’s None, then the edge in the about_edge direction is considered as about_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 camera

  • inverse: Whether to make the item face away from the camera

  • Considers about_point as the origin. If it’s None, then the edge in the about_edge direction is considered as about_point

You can manually specify camera and normal vector normal_vector; if not provided, they will be automatically obtained:

  • camera defaults to self.camera of the timeline

  • normal_vector is calculated by unit_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 the indicator is moved to target, rather than the displacement where self is moved to target in move_to()

Examples:

t1 = TypstMath('x^2 + y^2')
t2 = TypstMath('x + y')
t2.points.move_to_by_indicator(t2[1], t1[2])

Can move t2 to the position of t1, and align the plus sign of t2 with the plus sign of t1

Note

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 move item1 vertically so that its top aligns with the top edge of item2

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 columns

  • v_buff, h_buff: Vertical and horizontal spacing

  • aligned_edge: Aligned edge

  • by_center_point: Default is False; if set to True, 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 the indicator is placed next to target, rather than the displacement where self is placed next to target in move_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 t1 below t2, and place the plus sign of t1 directly below the plus sign of t2

Note

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