Curve2D
Inherits: Resource < Reference < Object Describes a Bézier curve in 2D space.
Description
Path2D, but can be manually sampled for other purposes. It keeps a cache of precalculated points along the curve, to speed up further calculations.
Properties
Methods
Property Descriptions
- float bake_interval
get_baked_points or get_baked_length function is called. The smaller the distance, the more points in the cache and the more memory it will consume, so use with care.
Method Descriptions
- add_point ( Vector2 position, Vector2 in=Vector2( 0, 0 ), Vector2 out=Vector2( 0, 0 ), int at_position=-1 )
position, with control pointsinandout.at_positionis given, the point is inserted before the point numberat_position, moving that point (and every point after) after the inserted point. Ifat_positionis not given, or is an illegal value (at_position <0orat_position >= [method get_point_count]), the point will be appended at the end of the point list.
- clear_points ( ) Removes all points from the curve.
- float get_baked_length ( ) const bake_interval), it should be approximate enough.
- PoolVector2Array get_baked_points ( ) const PoolVector2Array.
- float get_closest_offset ( Vector2 to_point ) const
to_point. This offset is meant to be used in interpolate_baked.to_pointmust be in this curve’s local space.
- Vector2 get_closest_point ( Vector2 to_point ) const
to_point.to_pointmust be in this curve’s local space.
- int get_point_count ( ) const Returns the number of points describing the curve.
- Vector2 get_point_in ( int idx ) const
idx. The returned position is relative to the vertexidx. If the index is out of bounds, the function sends an error to the console, and returns(0, 0).
- Vector2 get_point_out ( int idx ) const
idx. The returned position is relative to the vertexidx. If the index is out of bounds, the function sends an error to the console, and returns(0, 0).
- Vector2 get_point_position ( int idx ) const
idx. If the index is out of bounds, the function sends an error to the console, and returns(0, 0).
- Vector2 interpolate ( int idx, float t ) const
idxand the vertexidx + 1, wheretcontrols if the point is the first vertex (t = 0.0), the last vertex (t = 1.0), or in between. Values oftoutside the range (0.0 >= t <=1) give strange, but predictable results.idxis out of bounds it is truncated to the first or last vertex, andtis ignored. If the curve has no points, the function sends an error to the console, and returns(0, 0).
- Vector2 interpolate_baked ( float offset, bool cubic=false ) const
offset, whereoffsetis measured as a pixel distance along the curve.offsetlies between, then interpolates the values. This interpolation is cubic ifcubicis set totrue, or linear if set tofalse. Cubic interpolation tends to follow the curves better, but linear is faster (and often, precise enough).
- Vector2 interpolatef ( float fofs ) const
fofs. It calls interpolate using the integer part offofsasidx, and its fractional part ast.
- remove_point ( int idx )
idxfrom the curve. Sends an error to the console ifidxis out of bounds.
- set_point_in ( int idx, Vector2 position )
idx. If the index is out of bounds, the function sends an error to the console. The position is relative to the vertex.
- set_point_out ( int idx, Vector2 position )
idx. If the index is out of bounds, the function sends an error to the console. The position is relative to the vertex.
- set_point_position ( int idx, Vector2 position )
idx. If the index is out of bounds, the function sends an error to the console.
- PoolVector2Array tessellate ( int max_stages=5, float tolerance_degrees=4 ) const
Returns a list of points along the curve, with a curvature controlled point density. That is, the curvier parts will have more points than the straighter parts.
This approximation makes straight segments between each point, then subdivides those segments until the resulting shape is similar enough.
max_stagescontrols how many subdivisions a curve segment may face before it is considered approximate enough. Each subdivision splits the segment in half, so the default 5 stages may mean up to 32 subdivisions per curve segment. Increase with care!tolerance_degreescontrols how many degrees the midpoint of a segment may deviate from the real curve, before the segment has to be subdivided.
