Segment
The Segment object represents the points of a path through which its Curve objects pass. The segments of a path can be accessed through its path.segments array.
Each segment consists of an anchor point (segment.point) and optionally an incoming and an outgoing handle (segment.handleIn and segment.handleOut), describing the tangents of the two Curve objects that are connected by this segment.
Constructors
Creates a new Segment object.
- point: Point — the anchor point of the segment — optional, default: {x: 0, y: 0}
- handleIn: Point — the handle point relative to the anchor point of the segment that describes the in tangent of the segment — optional, default: {x: 0, y: 0}
- handleOut: Point — the handle point relative to the anchor point of the segment that describes the out tangent of the segment — optional, default: {x: 0, y: 0}
Parameters:
- Segment
Returns:
Example:
Creates a new Segment object.
- object: Object — an object containing properties to be set on the segment
Parameters:
- Segment
Returns:
Example:Creating segments using object notation:
Properties
The name of the segment. If the segment has a name, it can be accessed by name through its path’s segments list. If several segments share a name, the first one is found.
The name is stored in JSON, but not in SVG.
- String⟋null
Type:
Example:
var path = new Path([10, 10], [50, 10], [50, 50]);
path.segments[1].name = 'corner';
console.log(path.segments['corner'].point); // { x: 50, y: 10 }
A plain javascript object which can be used to store arbitrary data on the segment.
The data is stored in JSON, but not in SVG.
- Object
Type:
Example:
var segment = new Segment(100, 100);
segment.data.isCorner = true;
Example:
var segment = new Segment({
point: [100, 50],
handleOut: [80, 100],
data: {
isCorner: true
}
});
console.log(segment.data.isCorner); // true
The handle point relative to the anchor point of the segment that describes the in tangent of the segment.
- Point
Type:
The handle point relative to the anchor point of the segment that describes the out tangent of the segment.
- Point
Type:
Specifies whether the segment is selected.
- Boolean
Type:
Example:
Hierarchy
The index of the segment in the path.segments array that the segment belongs to.
Read only.
- Number
Type:
The curve that the segment belongs to. For the last segment of an open path, the previous segment is returned.
Read only.
- Curve
Type:
The curve location that describes this segment’s position on the path.
Read only.
- CurveLocation
Type:
Sibling Segments
The next segment in the path.segments array that the segment belongs to. If the segments belongs to a closed path, the first segment is returned for the last segment of the path.
Read only.
- Segment
Type:
The previous segment in the path.segments array that the segment belongs to. If the segments belongs to a closed path, the last segment is returned for the first segment of the path.
Read only.
- Segment
Type:
Methods
Checks if the segment has any curve handles set. Handles of which both coordinates are 0 within a tolerance of 1e-12 count as not set, see point.isZero().
- Boolean — true if the segment has handles set, false otherwise
Returns:
- segment.handleIn
- segment.handleOut
- curve.hasHandles()
- path.hasHandles()
See also:
Checks if the segment connects two curves smoothly, meaning that its two handles are collinear and segment does not form a corner.
- Boolean — true if the segment is smooth, false otherwise
Returns:
- point.isCollinear()
See also:
Clears the segment’s handles by setting their coordinates to zero, turning the segment into a corner.
Smooths the bezier curves that pass through this segment by taking into account the segment’s position and distance to the neighboring segments and changing the direction and length of the segment’s handles accordingly without moving the segment itself.
Two different smoothing methods are available:
-
'catmull-rom'uses the Catmull-Rom spline to smooth the segment.The optionally passed factor controls the knot parametrization of the algorithm:
0.0: the standard, uniform Catmull-Rom spline0.5: the centripetal Catmull-Rom spline, guaranteeing no self-intersections1.0: the chordal Catmull-Rom spline
-
'geometric'use a simple heuristic and empiric geometric method to smooth the segment’s handles. The handles were weighted, meaning that big differences in distances between the segments will lead to probably undesired results.The optionally passed factor defines the tension parameter (
0…1), controlling the amount of smoothing as a factor by which to scale each handle.
- options.type: String — the type of smoothing method: ‘catmull-rom’, ‘geometric’ — default: ‘catmull-rom’
- options.factor: Number — the factor parameterizing the smoothing method — default:
0.5for'catmull-rom',0.4for'geometric'
Options:
- options: Object — the smoothing options — optional
Parameters:
- pathItem.smooth([options])
See also:
Checks if the this is the first segment in the path.segments array.
- Boolean — true if this is the first segment, false otherwise
Returns:
Checks if the this is the last segment in the path.segments array.
- Boolean — true if this is the last segment, false otherwise
Returns:
Returns the reversed the segment, without modifying the segment itself.
- Segment — the reversed segment
Returns:
Removes the segment from the path that it belongs to.
- Boolean — true if the segment was removed, false otherwise
Returns:
- String — a string representation of the segment
Returns:
Transform the segment by the specified matrix.
- matrix: Matrix — the matrix to transform the segment by
Parameters:
Interpolates between the two specified segments and sets the point and handles of this segment accordingly.
Paper.js v0.16.0
Copyright © 2011—2026 Jürg Lehni & Jonathan Puckey. All Rights Reserved.