points

class janim.components.points.Cmpt_Points(*args, **kwargs)

基类:Component, Generic

static resize_func(array: ~numpy.ndarray, length: int, fall_back: ~typing.Callable[[int], ~numpy.ndarray] = <function <lambda>>) ndarray
init_bind(bind: BindInfo)

用于 Item._init_components

子类可以继承该函数,进行与所在物件相关的处理

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_all() ndarray

得到自己以及后代物件的所有点坐标数据

set(points: VectArray) Self

设置点坐标数据,每个坐标点都有三个分量

使用形如 .set([[1.5, 3, 2], [2, 1.5, 0]]) 的形式

clear() Self

清除点

extend(points: VectArray) Self

追加点坐标数据,每个坐标点都有三个分量

使用形如 .append([[1.5, 3, 2], [2, 1.5, 0]]) 的形式

reverse() Self

使点倒序

resize(length: int) Self
count() int

点的数量

has() bool

是否有点坐标数据

get_start() ndarray

得到 points 的第一个点

get_end() ndarray

得到 points 的最后一个点

get_start_and_end() tuple[ndarray, ndarray]

得到 points 的第一个和最后一个点

point_from_proportion(alpha: float) ndarray
pfp(alpha) ndarray

point_from_proportion 的缩写

property box: BoundingBox

表示物件(包括后代物件)的矩形包围框

property self_box: BoundingBox

box,但仅表示自己 points 的包围框,不考虑后代物件的

class BoundingBox(points: VectArray)

基类:object

边界框,self.data 包含三个元素,分别为左下,中心,右上

static compute(points: VectArray) ndarray

根据传入的 points 计算得到包围框的 左下、中心、右上 三个点

get(direction: Vect) ndarray

获取边界框边上的坐标

例如:

  • 传入 UR,则返回边界框右上角的坐标

  • 传入 RIGHT,则返回边界框右侧中心的坐标

get_continuous(direction: Vect) ndarray

得到从中心发出的方向为 direction 的射线与边界框的交点

get_corners() ndarray

得到包围框(立方体)的八个顶点

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

将所有点作为单独的一个参数传入 func,并将 func 返回的结果作为新的点坐标数据

about_point 为原点,若其为 None,则将物件在 about_edge 方向上的边界作为 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

对每个点依次传入 func 进行变换;以默认的原点作用变换,而不是物件的中心

apply_matrix(matrix: VectArray, *, about_point: Vect | None = None, about_edge: Vect | None = None, root_only: bool = False) Self

将矩阵变换作用于 points;以默认的原点作用变换,而不是物件的中心

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

将复变函数作用于 points;以默认的原点作用变换,而不是物件的中心

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

axis 为方向,angle 为角度旋转,可传入 about_point 指定相对于以哪个点为中心

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

绕 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_factor(2, 0.5, 1) 则是在 x 方向上缩放为两倍,在 y 方向上压缩为原来的一半,在 z 方向上保持不变

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

在指定的 dim 方向上使物件伸缩

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

如果 stretchFalse (默认),则表示等比缩放

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

如果 stretchFalse (默认),则表示等比缩放

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

如果 stretchFalse (默认),则表示等比缩放

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

放到 item 的位置,并且在 dim_to_match 维度上长度相同

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

replace 类似,但是会向外留出 buff 间距

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

切变

  • factor 表示切变的程度

  • direction 表示切变的方向

  • 可以传入 about_pointabout_edge 控制参考点

put_start_and_end_on(start: Vect, end: Vect) Self

通过旋转和缩放,使得物件的起点和终点被置于 startend

shift(vector: Vect, *, root_only=False) Self

相对移动 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

移动到 target 的位置

move_to_by_indicator(indicator: Item, target: Item, *, 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

move_to() 类似,但是该方法作用 indicator 被移动到 target 所计算出的位移, 而不是 move_to()self 被移动到 target 的位移

例如:

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

可以将 t2 移动至 t1 的位置, 并且使得 t2 的加号与 t1 的加号对齐

备注

这个示例使用 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

对齐

例如,item1.align_to(item2, UP) 会将 item1 垂直移动,顶部与 item2 的上边缘对齐

arrange(direction: Vect = array([1., 0., 0.]), center: bool = True, **kwargs) Self

将子物件按照 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

将子物件按网格方式排列

  • n_rows, n_cols: 行数、列数

  • v_buff, h_buff: 行距、列距

  • aligned_edge: 对齐边缘

  • by_center_point: 默认为 False;若设置为 True,则仅将物件视为中心点,不考虑物件的宽高

arrange_by_offset(offset: Vect, *, aligned_edge: Vect = array([0., 0., 0.]), center: bool = True) Self
to_center(root_only=False) Self

移动到原点 (0, 0, 0)

to_border(direction: Vect, buff: float = 0.5) Self

移动到视框的边界

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

将该物件放到 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

next_to() 类似,但是该方法作用 indicator 被放到 target 旁边所计算出的位移, 而不是 move_to()self 被放到 target 旁边的位移

例如:

t1 = Typst('x^2 + y^2')
t2 = Typst('x + y z w')
t2.points.next_to_by_indicator(t2[1], t1[2], DOWN)

可以将 t1 对齐到 t2 的下方, 并且使得 t1 的加号在 t2 的加号的正下方

备注

这个示例也可以使用字符索引

shift_onto_screen(**kwargs) 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