Curve2D

Inherits: Resource < Reference < Object

描述二维空间的贝兹尔曲线。

描述

该类描述了二维空间中的贝兹尔曲线。它主要用于给Path2D一个形状,但也可以手动采样用于其他目的。

它保留了沿曲线的预计算点的缓存,以加快进一步的计算。

属性

float

bake_interval

5.0

方法

void

add_point ( Vector2 position, Vector2 in=Vector2( 0, 0 ), Vector2 out=Vector2( 0, 0 ), int at_position=-1 )

void

clear_points ( )

float

get_baked_length ( ) const

PoolVector2Array

get_baked_points ( ) const

float

get_closest_offset ( Vector2 to_point ) const

Vector2

get_closest_point ( Vector2 to_point ) const

int

get_point_count ( ) const

Vector2

get_point_in ( int idx ) const

Vector2

get_point_out ( int idx ) const

Vector2

get_point_position ( int idx ) const

Vector2

interpolate ( int idx, float t ) const

Vector2

interpolate_baked ( float offset, bool cubic=false ) const

Vector2

interpolatef ( float fofs ) const

void

remove_point ( int idx )

void

set_point_in ( int idx, Vector2 position )

void

set_point_out ( int idx, Vector2 position )

void

set_point_position ( int idx, Vector2 position )

PoolVector2Array

tessellate ( int max_stages=5, float tolerance_degrees=4 ) const

属性说明

Default

5.0

Setter

set_bake_interval(value)

Getter

get_bake_interval()

相邻两个缓存点之间的距离,以像素为单位。改变它将迫使缓存在下次调用get_baked_pointsget_baked_length函数时重新计算。距离越小,缓存中的点越多,占用的内存也越多,所以使用时要注意。

方法说明

在曲线的 position 上添加一个点,控制点 inout

如果给定了 at_position,这个点会被插入到点号 at_position 之前,并将这个点(以及之后的每一个点)移到被插入点之后。如果at_position没有给定,或者是一个非法值(at_position <0at_position >= [method get_point_count]),该点将被追加在点列表的最后。


  • void clear_points ( )

从曲线中删除所有点。


  • float get_baked_length ( ) const

根据缓存的点,返回曲线的总长度。给予足够的密度(参阅bake_interval),它应该是足够近似的。


PoolVector2Array的形式返回缓存的点。


返回与 to_point 最近的偏移量。这个偏移量在 interpolate_baked 中使用。

to_point 必须在这条曲线的局部空间中。


返回最接近 to_point 并烘焙好的点(在曲线的局部空间)。

to_point 必须是在这个曲线的局部空间。


  • int get_point_count ( ) const

返回描述曲线的点数。


返回指向顶点idx的控制点位置。返回的位置是相对于顶点idx的。如果索引超出了范围,函数会向控制台发送一条错误,并返回(0, 0)


返回从顶点idx引出的控制点位置。返回的位置是相对于顶点 idx。如果索引越界,函数会向控制台发送错误,并返回 (0, 0)


返回顶点的位置idx。如果索引超出边界,函数会向控制台发送一个错误信息,并返回(0,0)


返回顶点 idx 和顶点 idx + 1 之间的位置,其中 t 控制该点是第一个顶点 (t = 0.0)、最后一个顶点 (t = 1.0),还是介于两者之间。范围外的t的值(0.0 >= t <=1)会产生奇怪但可预测的结果。

如果idx超出边界,则截断到第一个或最后一个顶点,而t则被忽略。如果曲线没有点,函数会向控制台发送一个错误,并返回 (0,0)


返回曲线中位于 offset 位置的一个点,其中 offset 是沿曲线的像素距离。

为此,它找到 offset 所在的两个缓存点,然后对其进行插值。如果将 cubic 设置为 true 则为立方插值,如果设置为 false 则为线性插值。

立方内插往往能更好地跟随曲线,但线性内插速度更快(而且通常足够精确)。


返回顶点 fofs 的位置。它使用 fofs 的整数部分作为 idx 和分数部分作为 t 调用 interpolate


  • void remove_point ( int idx )

从曲线上删除点 idx 。如果 idx 越界,会向控制台发送错误信息。


设置通往顶点 idx 的控制点位置。如果索引超出范围,函数会向控制台发送错误信息。


设置从顶点idx引出的控制点位置。如果索引超出范围,该函数会向控制台发送错误。位置是相对于顶点的。


  • void set_point_position ( int idx, Vector2 position )

设置顶点idx的位置。如果索引超出范围,函数会向控制台发送一个错误信息。


返回沿曲线的点的列表,点的密度由曲率控制。也就是说,曲线部分比直线部分有更多的点。

这个近似值在每个点之间做了直段,然后将这些直段细分,直到得到的形状足够相似。

max_stages 控制一个曲线段在被认为足够近似之前可能面临多少次细分。每一次细分都会将曲线段分成两半,所以默认的 5 个阶段意味着每条曲线段最多可以细分 32 次。请谨慎增加!

tolerance_degrees 控制一个曲线段的中点与实际曲线的偏差多少度才会被细分。