Class EdgeRoute

java.lang.Object
it.univr.di.cstnu.graph.EdgeRoute

public final class EdgeRoute extends Object
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):

  • t is the fraction along the chord from the source center to the destination center (0 < t < 1);
  • offset is 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 by EdgeGeometry.
Rendering: 0 points = automatic behavior (straight line or whatever 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
  • Method Details

    • empty

      @Nonnull public static EdgeRoute empty()
      Returns:
      the empty route (no control points, i.e. automatic)
    • of

      @Nonnull public static EdgeRoute of(@Nonnull EdgeRoute.Point point)
      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 null
      second - 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 connection
      destinationAngle - 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 connection
      destinationAngle1 - the destination connection angle in radians, or null for automatic connection
      Returns:
      the route
    • sourceAngle

      @Nullable public Double sourceAngle()
      Returns:
      the source connection angle in radians, or null for automatic connection
    • destinationAngle

      @Nullable public Double 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

      @Nonnull public EdgeRoute.Point point(int index)
      Parameters:
      index - 0 or 1
      Returns:
      the index-th control point
      Throws:
      IndexOutOfBoundsException - if no such control point exists
    • points

      @Nonnull public List<EdgeRoute.Point> points()
      Returns:
      an unmodifiable view of the control points, in order
    • format

      @Nonnull public String format()
      Formats this route as compact, locale-independent text. Existing routes retain the historical t,offset[;t,offset] representation. Routes with endpoint overrides use e:sourceAngle,destinationAngle|t,offset[;t,offset]; the endpoint prefix is optional per side (for example e:,1.2|0.5,0).
      Returns:
      the formatted route
    • parse

      @Nullable public static EdgeRoute parse(@Nonnull String text)
      Parses the compact text produced by format(). A blank string yields null (no route). More than two control points, or a malformed t,offset pair, are rejected.
      Parameters:
      text - the text to parse
      Returns:
      the parsed route, or null when text is blank
      Throws:
      IllegalArgumentException - if the text does not describe a valid route