Class EdgeRoute
java.lang.Object
it.univr.di.cstnu.graph.EdgeRoute
The explicit routing of an edge: a path from source to destination made of 0, 1 or 2
control points, expressed in coordinates relative to the source→destination chord. When a route is
present it replaces the automatic curvature of the edge (both the explicit curvature set with
GraphCanvas.setCurvature(E, double) and the implicit CurvaturePolicy):
the user has taken manual control of the path and the automatic policy contributes nothing.
Each control point is a EdgeRoute.Point (t, offset):
tis the fraction along the chord from the source center to the destination center (0 < t < 1);offsetis the perpendicular displacement, as a factor of the chord length, positive on the left (counter-clockwise) side of the source→destination direction and negative on the right — the same perpendicular convention used byEdgeGeometry.
CurvaturePolicy
decides), 1 point = quadratic Bézier, 2 points = cubic Bézier. The current curvature semantics is
the degenerate case of this model: a single point at t = 0.5 with offset equal to the
curvature factor displaces the control point exactly like the curvature mechanism does.
Coordinates are relative so that the fan follows the nodes when they are moved: moving the endpoints rescales the whole route.
Instances are immutable and safe to share between edges. null (or an empty route) means
"automatic", i.e. no explicit route.
- Author:
- posenato
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA single control point of the route. -
Method Summary
Modifier and TypeMethodDescriptionstatic EdgeRouteempty()format()Formats this route as compact, locale-independent text.booleanbooleanisEmpty()static EdgeRouteof(EdgeRoute.Point point) Creates a route with a single control point (quadratic Bézier).static EdgeRouteof(EdgeRoute.Point first, EdgeRoute.Point second) Creates a route with two control points (cubic Bézier).static EdgeRouteCreates a route containing only endpoint connection angles.static EdgeRouteParses the compact text produced byformat().point(int index) points()intsize()withEndpoints(Double sourceAngle1, Double destinationAngle1) Returns this route with the supplied endpoint connection angles.
-
Method Details
-
empty
- Returns:
- the empty route (no control points, i.e. automatic)
-
of
Creates a route with a single control point (quadratic Bézier).- Parameters:
point- the control point, not null- Returns:
- the route
-
of
@Nonnull public static EdgeRoute of(@Nonnull EdgeRoute.Point first, @Nonnull EdgeRoute.Point second) Creates a route with two control points (cubic Bézier).- Parameters:
first- the first control point, not nullsecond- the second control point, not null- Returns:
- the route
-
of
@Nonnull public static EdgeRoute of(@Nullable Double sourceAngle, @Nullable Double destinationAngle) Creates a route containing only endpoint connection angles.- Parameters:
sourceAngle- the source connection angle in radians, or null for automatic connectiondestinationAngle- the destination connection angle in radians, or null for automatic connection- Returns:
- the route
-
withEndpoints
@Nonnull public EdgeRoute withEndpoints(@Nullable Double sourceAngle1, @Nullable Double destinationAngle1) Returns this route with the supplied endpoint connection angles.- Parameters:
sourceAngle1- the source connection angle in radians, or null for automatic connectiondestinationAngle1- the destination connection angle in radians, or null for automatic connection- Returns:
- the route
-
sourceAngle
- Returns:
- the source connection angle in radians, or null for automatic connection
-
destinationAngle
- Returns:
- the destination connection angle in radians, or null for automatic connection
-
hasEndpointOverrides
public boolean hasEndpointOverrides()- Returns:
- true when at least one endpoint connection angle is explicitly set
-
size
public int size()- Returns:
- the number of control points (0, 1 or 2)
-
isEmpty
public boolean isEmpty()- Returns:
- true iff the route has no control points (automatic)
-
point
- Parameters:
index- 0 or 1- Returns:
- the
index-th control point - Throws:
IndexOutOfBoundsException- if no such control point exists
-
points
- Returns:
- an unmodifiable view of the control points, in order
-
format
Formats this route as compact, locale-independent text. Existing routes retain the historicalt,offset[;t,offset]representation. Routes with endpoint overrides usee:sourceAngle,destinationAngle|t,offset[;t,offset]; the endpoint prefix is optional per side (for examplee:,1.2|0.5,0).- Returns:
- the formatted route
-
parse
Parses the compact text produced byformat(). A blank string yieldsnull(no route). More than two control points, or a malformedt,offsetpair, are rejected.- Parameters:
text- the text to parse- Returns:
- the parsed route, or
nullwhentextis blank - Throws:
IllegalArgumentException- if the text does not describe a valid route
-