svg_path/marker
Marker placement helpers.
SVG markers are full rendering objects with their own viewport, reference point, units, and content. This module only covers the part supplied by path data: marker positions and path-derived orientation angles.
Types
Alignment used by SVG preserveAspectRatio.
pub type AspectAlign {
XMinYMin
XMidYMin
XMaxYMin
XMinYMid
XMidYMid
XMaxYMid
XMinYMax
XMidYMax
XMaxYMax
}
Constructors
-
XMinYMin -
XMidYMin -
XMaxYMin -
XMinYMid -
XMidYMid -
XMaxYMid -
XMinYMax -
XMidYMax -
XMaxYMax
Errors returned while computing marker poses.
pub type Error {
EmptySubpath
DegenerateTangent
PathError(svg_path.Error)
InvalidMarkerWidth(width: Float)
InvalidMarkerHeight(height: Float)
InvalidStrokeWidth(width: Float)
InvalidViewBox(view_box: svg_path.BoundingBox)
}
Constructors
-
EmptySubpathThe subpath has no drawable segments.
-
DegenerateTangentA marker orientation could not be computed from a zero derivative.
-
PathError(svg_path.Error)An underlying path operation failed.
-
InvalidMarkerWidth(width: Float)Marker viewport width must be finite and greater than zero.
-
InvalidMarkerHeight(height: Float)Marker viewport height must be finite and greater than zero.
-
InvalidStrokeWidth(width: Float)Stroke width must be finite and greater than zero when marker units use stroke width.
-
InvalidViewBox(view_box: svg_path.BoundingBox)Marker viewBox width and height must be finite and greater than zero.
Which SVG marker slot a pose belongs to.
pub type MarkerKind {
MarkerStart
MarkerMid
MarkerEnd
}
Constructors
-
MarkerStart -
MarkerMid -
MarkerEnd
Transform-only SVG marker layout inputs.
reference corresponds to SVG refX and refY. marker_width and
marker_height are the marker viewport size. If view_box is Some, the
marker content coordinate system is mapped into that viewport using
preserve_aspect_ratio; otherwise marker content coordinates are already
viewport coordinates. stroke_width is used only with StrokeWidth units.
pub type MarkerLayout {
MarkerLayout(
reference: svg_path.Point,
marker_width: Float,
marker_height: Float,
marker_units: MarkerUnits,
stroke_width: Float,
view_box: option.Option(svg_path.BoundingBox),
preserve_aspect_ratio: PreserveAspectRatio,
)
}
Constructors
-
MarkerLayout( reference: svg_path.Point, marker_width: Float, marker_height: Float, marker_units: MarkerUnits, stroke_width: Float, view_box: option.Option(svg_path.BoundingBox), preserve_aspect_ratio: PreserveAspectRatio, )
SVG-style marker orientation policy.
pub type MarkerOrient {
Auto
AutoStartReverse
Fixed(Float)
}
Constructors
-
AutoUse path-derived marker angles.
-
AutoStartReverseUse path-derived marker angles, but rotate the start marker by 180 degrees.
-
Fixed(Float)Use one fixed absolute angle for every marker.
A marker position and absolute orientation angle in degrees.
pub type MarkerPose {
MarkerPose(
kind: MarkerKind,
point: svg_path.Point,
angle: Float,
)
}
Constructors
-
MarkerPose(kind: MarkerKind, point: svg_path.Point, angle: Float)
How marker viewport units relate to the stroked path.
pub type MarkerUnits {
StrokeWidth
UserSpaceOnUse
}
Constructors
-
StrokeWidthMarker viewport units are multiplied by the path stroke width.
-
UserSpaceOnUseMarker viewport units are ordinary user-space units.
SVG preserveAspectRatio behavior for marker viewBox fitting.
pub type PreserveAspectRatio {
Stretch
Meet(AspectAlign)
Slice(AspectAlign)
}
Constructors
-
StretchScale x and y independently so the viewBox exactly fills the viewport.
-
Meet(AspectAlign)Use uniform scale so the whole viewBox fits inside the viewport.
-
Slice(AspectAlign)Use uniform scale so the viewBox covers the viewport.
Values
pub fn layout_transform(
point point: svg_path.Point,
angle angle: Float,
layout layout: MarkerLayout,
) -> Result(transform.Matrix, Error)
Return a full marker-content transform at point and angle.
pub fn pose_layout_transform(
pose: MarkerPose,
layout layout: MarkerLayout,
) -> Result(transform.Matrix, Error)
Return a full marker-content transform for a pose and marker layout.
This computes the transform-only portion of SVG marker placement. It maps
marker content coordinates through optional viewBox fitting, optional
strokeWidth unit scaling, reference-point placement, pose rotation, and
pose translation.
pub fn pose_transform(pose: MarkerPose) -> transform.Matrix
Return a transform that places marker-local coordinates at a pose.
The returned matrix rotates marker-local coordinates by the pose angle, then
translates marker-local (0, 0) to the pose point.
pub fn pose_transform_with_reference(
pose: MarkerPose,
reference reference: svg_path.Point,
) -> transform.Matrix
Return a transform that places a marker-local reference point at a pose.
The returned matrix rotates marker-local coordinates by the pose angle and
translates them so reference lands on the pose point. This corresponds to
the geometric part of SVG’s refX and refY marker reference point.
pub fn subpath_poses(
subpath: svg_path.Subpath,
orient orient: MarkerOrient,
) -> Result(List(MarkerPose), Error)
Return marker poses for one subpath.
MarkerStart is placed at the first segment start, MarkerEnd at the last
segment end, and MarkerMid at each join between adjacent segments. For
Auto, open-subpath start and end markers use the outgoing and incoming
segment directions respectively. Mid markers and closed-subpath start/end
markers use the angle bisector of the incoming and outgoing directions. If
that bisector is degenerate because the two directions are exactly opposite,
the incoming direction is used.
pub fn transform(
point point: svg_path.Point,
angle angle: Float,
) -> transform.Matrix
Return a transform that places marker-local coordinates at point.
The returned matrix rotates marker-local coordinates by angle, then
translates marker-local (0, 0) to point.
pub fn transform_with_reference(
point point: svg_path.Point,
angle angle: Float,
reference reference: svg_path.Point,
) -> transform.Matrix
Return a transform that places a marker-local reference point at point.