Segment

class Segment : ShapeContourProvider

Creates a new Segment, which specifies a linear or a Bézier curve path between two anchor points (and up to two control points for curvature).

Constructors

Segment
Link copied to clipboard
common
fun Segment(start: Vector2, end: Vector2, corner: Boolean = true)

Linear segment constructor.

Segment
Link copied to clipboard
common
fun Segment(start: Vector2, c0: Vector2, end: Vector2, corner: Boolean = true)

Quadratic Bézier segment constructor.

Segment
Link copied to clipboard
common
fun Segment(start: Vector2, c0: Vector2, c1: Vector2, end: Vector2, corner: Boolean = true)

Cubic Bézier segment constructor.

Segment
Link copied to clipboard
common
fun Segment(start: Vector2, control: Array<Vector2>, end: Vector2, corner: Boolean = true)

Functions

adaptivePositions
Link copied to clipboard
common
fun adaptivePositions(distanceTolerance: Double = 0.5): List<Vector2>

Recursively subdivides Segment to approximate Bézier curve.

adaptivePositionsAndNormals
Link copied to clipboard
common
fun adaptivePositionsAndNormals(distanceTolerance: Double = 0.5): Pair<List<Vector2>, List<Vector2>>

Recursively subdivides Segment to approximate Bézier curve.

copy
Link copied to clipboard
common
fun copy(start: Vector2 = this.start, control: Array<Vector2> = this.control, end: Vector2 = this.end): Segment

Returns a shallow copy of the Segment.

derivative
Link copied to clipboard
common
fun derivative(t: Double): Vector2
direction
Link copied to clipboard
common
fun direction(): Vector2

Returns the direction Vector2 of between the Segment anchor points.

fun direction(t: Double): Vector2
div
Link copied to clipboard
common
operator fun div(scale: Double): Segment
equals
Link copied to clipboard
common
open operator override fun equals(other: Any?): Boolean
equidistantPositions
Link copied to clipboard
common
fun equidistantPositions(pointCount: Int): List<Vector2>

Samples specified amount of points on the Segment.

extrema
Link copied to clipboard
common
fun extrema(): List<Double>

Returns the t values of the extrema for the current Segment.

extremaPoints
Link copied to clipboard
common
fun extremaPoints(): List<Vector2>

Returns the extrema points as Vector2s for current Segment

hashCode
Link copied to clipboard
common
open override fun hashCode(): Int
isStraight
Link copied to clipboard
common
fun isStraight(epsilon: Double = 0.01): Boolean

Determines if the Segment forms a straight line.

lut
Link copied to clipboard
common
fun lut(size: Int = 100): List<Vector2>
minus
Link copied to clipboard
common
operator fun minus(right: Segment): Segment
nearest
Link copied to clipboard
common
fun nearest(point: Vector2): SegmentPoint

Find point on segment nearest to given point.

normal
Link copied to clipboard
common
fun normal(ut: Double, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): Vector2

Returns a normal Vector2 at given value of t in the range of 0.0 to 1.0.

offset
Link copied to clipboard
common
fun offset(distance: Double, stepSize: Double = 0.01, yPolarity: YPolarity = YPolarity.CW_NEGATIVE_Y): List<Segment>
on
Link copied to clipboard
common
fun on(point: Vector2, error: Double = 5.0): Double?
plus
Link copied to clipboard
common
operator fun plus(right: Segment): Segment
pose
Link copied to clipboard
common
fun pose(t: Double, polarity: YPolarity = YPolarity.CW_NEGATIVE_Y): Matrix44

Calculates the pose Matrix44 (i.e. translation and rotation) that describes an orthonormal basis formed by normal and tangent of the contour at t.

position
Link copied to clipboard
common
fun position(ut: Double): Vector2

Returns a point on the segment.

reduced
Link copied to clipboard
common
fun reduced(stepSize: Double = 0.01): List<Segment>
scale
Link copied to clipboard
common
fun scale(scale: Double, polarity: YPolarity): Segment
fun scale(polarity: YPolarity, scale: (Double) -> Double): Segment
split
Link copied to clipboard
common
fun split(t: Double): Array<Segment>

Splits the path into one or two parts, depending on if the cut was successful.

sub
Link copied to clipboard
common
fun sub(t0: Double, t1: Double): Segment

Samples a new Segment from the current Segment starting at t0 and ending at t1.

tForLength
Link copied to clipboard
common
fun tForLength(length: Double): Double

Estimate t value for a given length

times
Link copied to clipboard
common
operator fun times(scale: Double): Segment
toString
Link copied to clipboard
common
open override fun toString(): String
transform
Link copied to clipboard
common
fun transform(transform: Matrix44): Segment

Applies given linear transformation.

Properties

bounds
Link copied to clipboard
common
val bounds: Rectangle

Returns the bounding box.

clockwise
Link copied to clipboard
common
val clockwise: Boolean
contour
Link copied to clipboard
common
open override val contour: ShapeContour

the provided contour

control
Link copied to clipboard
common
val control: Array<Vector2>

Array of control points which control the curvature of the Segment.

corner
Link copied to clipboard
common
val corner: Boolean
cubic
Link copied to clipboard
common
val cubic: Segment

Converts the Segment to a cubic Bézier curve.

end
Link copied to clipboard
common
val end: Vector2

The end point of the Segment.

length
Link copied to clipboard
common
val length: Double

Calculates approximate Euclidean length of the Segment.

linear
Link copied to clipboard
common
val linear: Boolean

Indicates whether or not the Segment is linear.

quadratic
Link copied to clipboard
common
val quadratic: Segment

Converts the Segment to a quadratic Bézier curve.

reverse
Link copied to clipboard
common
val reverse: Segment

Reverses the order of control points of the given path Segment.

simple
Link copied to clipboard
common
val simple: Boolean
start
Link copied to clipboard
common
val start: Vector2

The start point of the Segment.

type
Link copied to clipboard
common
val type: SegmentType

Returns the type of the segment.

Extensions

intersections
Link copied to clipboard
common
fun Segment.intersections(other: Segment): List<SegmentIntersection>

Calculates a List of all points where two Segments intersect.

fun Segment.intersections(other: ShapeContour): List<ContourIntersection>

Calculates a List of all points of where a Segment and a ShapeContour intersect.

fun Segment.intersections(other: Shape): List<ContourIntersection>

Calculates a List of all points of where a Segment and a Shape intersect.