class

CP::Shape::Segment

Inherits CP::Shape / Reference / Object

A line segment shape between two points.

Meant mainly as a static shape. Can be beveled in order to give them a thickness.

Constructors

new(body : Body | Nil, a : Vect, b : Vect, radius : Number = 0)

The parameters are: the body to attach the segment to; the endpoints (a, b) to attach the segment to; the radius of the half-circles at the ends of the segment (thickness is twice the radius).

Source

Class methods

area(a : Vect, b : Vect, radius : Number) : Float64

Calculate the area of a fattened (capsule shaped) line segment.

Source
moment(m : Number, a : Vect, b : Vect, radius : Number = 0) : Float64

Calculate the moment of inertia for a line segment.

Beveling radius is not supported.

Source

Instance methods

a

Get the first endpoint of a segment shape.

Source
b

Get the second endpoint of a segment shape.

Source
normal

Get the normal of a segment shape.

Source
radius

Get the radius of a segment shape.

Source
radius=(radius : Number)

Unsafe. Set the radius of a segment shape.

This change is only picked up as a change to the position of the shape's surface, but not its velocity. Changing it will not result in realistic physical behavior. Only use if you know what you are doing!

Source
set_endpoints(a : Vect, b : Vect)

Unsafe. Set the endpoints of a segment shape.

This change is only picked up as a change to the position of the shape's surface, but not its velocity. Changing it will not result in realistic physical behavior. Only use if you know what you are doing!

Source
set_neighbors(prev : Vect, next next_ : Vect)

Let Chipmunk know about the geometry of adjacent segments to avoid colliding with endcaps.

When you have a number of segment shapes that are all joined together, things can still collide with the "cracks" between the segments. By setting the neighbor segment endpoints you can tell Chipmunk to avoid colliding with the inner parts of the crack.

Source