Package com.storedobject.svg
Class Path
java.lang.Object
com.storedobject.svg.Node
com.storedobject.svg.Element
com.storedobject.svg.Path
Represents an SVG path element allowing the creation and manipulation
of the "d" attribute, which defines a sequence of commands to draw
complex shapes and paths.
- Author:
- Syam
-
Nested Class Summary
Nested classes/interfaces inherited from class com.storedobject.svg.Node
Node.Anchor, Node.Margin, Node.Mover, Node.Scale, Node.ScaleTo -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidbuild()Build the content.voidclear()Clears the current state of the path by resetting the "d" attribute to an empty string and marking the instance as not built.command(char command, double... args) Adds a command to the SVG path's "d" attribute.function(Function<Double, Double> function, double xStart, double xEnd, int steps, boolean smooth, double yOffset) Generates a Path representation for a given mathematical function over a specified range and resolution.function(Function<Double, Double> function, double xStart, double xEnd, int steps, boolean smooth, double yOffset, double scale) Generates and appends SVG path operations based on the specified function and parameters.function(Function<Double, Double> function, double xStart, double xEnd, int steps, boolean smooth, double yOffset, double xScale, double yScale) Generates and appends SVG path operations based on the specified function and parameters.Generates a Path object by evaluating the provided mathematical function within a specified range and number of steps.function(Function<Double, Double> function, double xStart, double xEnd, int steps, double yOffset, double scale) Generates and appends SVG path operations based on the specified function and parameters.function(Function<Double, Double> function, double xStart, double xEnd, int steps, double yOffset, double xScale, double yScale) Generates and appends SVG path operations based on the specified function and parameters.Methods inherited from class com.storedobject.svg.Element
getStyles, getTag, isBuilt, styleEnd, styleStartMethods inherited from class com.storedobject.svg.Node
add, add, add, createDocument, duplicate, equals, escapeXml, flipHorizontally, flipVertically, getCoordinates, getHeight, getId, getSvg, getWidth, getX1, getX2, getY1, getY2, hashCode, ID, IDValue, margin, margin, margin, moveTo, moveTo, scale, scale, scaleTo, scaleToHeight, scaleToWidth, toString, toString
-
Constructor Details
-
Path
public Path()Constructs a new Path instance. This represents an SVG "path" element that facilitates drawing complex shapes through a sequence of commands defined in the "d" attribute. The constructed element starts with the base "path" tag.
-
-
Method Details
-
command
Adds a command to the SVG path's "d" attribute. The command defines an SVG path operation (e.g., move, line, curve, etc.) with the specified arguments.- Parameters:
command- The SVG path command character (e.g., 'M', 'L', 'C', etc.).The valid commands include: - 'M', 'm': Move to a point (expecting 2 arguments: x, y). - 'L', 'l': Draw a line to a point (expecting 2 arguments: x, y). - 'H', 'h': Draw a horizontal line (expecting 1 argument: x). - 'V', 'v': Draw a vertical line (expecting 1 argument: y). - 'C', 'c': Draw a cubic Bézier curve (expecting 6 arguments: x1, y1, x2, y2, x, y). - 'S', 's': Smooth cubic Bézier curve (expecting 4 arguments: x2, y2, x, y). - 'Q', 'q': Draw a quadratic Bézier curve (expecting 4 arguments: x1, y1, x, y). - 'T', 't': Smooth quadratic Bézier curve (expecting 2 arguments: x, y). - 'A', 'a': Draw an arc curve (expecting 7 arguments). - 'Z', 'z': Close the path (expecting no arguments).args- The arguments required by the SVG path command. The number of arguments must match the requirements of the given command.- Returns:
- The current instance of
Path, allowing method chaining. - Throws:
IllegalArgumentException- If the command is invalid or the number of arguments does not match the expected count for the command.
-
clear
public void clear()Clears the current state of the path by resetting the "d" attribute to an empty string and marking the instance as not built.This method is typically used to start redefining the path commands from scratch, as all previously added commands are erased.
-
function
public Path function(Function<Double, Double> function, double xStart, double xEnd, int steps, double yOffset) Generates a Path object by evaluating the provided mathematical function within a specified range and number of steps.- Parameters:
function- the mathematical function to evaluate, represented as a Function that takes a Double and returns a DoublexStart- the starting value of the x range for evaluationxEnd- the ending value of the x range for evaluationsteps- the number of steps to divide the range into for evaluationyOffset- the vertical offset to apply to the function values- Returns:
- a Path object representing the evaluated function over the specified range and steps
-
function
public Path function(Function<Double, Double> function, double xStart, double xEnd, int steps, boolean smooth, double yOffset) Generates a Path representation for a given mathematical function over a specified range and resolution.- Parameters:
function- The mathematical function to be represented, mapping a Double input to a Double output.xStart- The starting value of the x-axis for the function's domain.xEnd- The ending value of the x-axis for the function's domain.steps- The number of steps or subdivisions for discretizing the range from xStart to xEnd.smooth- Determines if the generated Path should be smoothed.yOffset- A vertical offset to be added to the function's output values.- Returns:
- A Path object representing the graph of the given function within the defined range and parameters.
-
function
public Path function(Function<Double, Double> function, double xStart, double xEnd, int steps, double yOffset, double xScale, double yScale) Generates and appends SVG path operations based on the specified function and parameters. The function is evaluated at evenly spaced intervals between the given start and end of the x-range to build the path. This method delegates the path generation to another overloaded method, allowing additional configuration for smoothness, scaling, and offsets.- Parameters:
function- A mathematical function that takes a double as input (x-coordinate) and returns a double (y-coordinate) for each evaluation.xStart- The starting value of the x-coordinate range.xEnd- The ending value of the x-coordinate range.steps- The number of steps to divide the x-range into. If zero, a default value of one is used.yOffset- The vertical offset from the SVG coordinate system's origin (the y-axis is inverted).xScale- The scaling factor applied to the x-coordinates.yScale- The scaling factor applied to the y-coordinates.- Returns:
- The current instance of
Path, allowing method chaining.
-
function
public Path function(Function<Double, Double> function, double xStart, double xEnd, int steps, double yOffset, double scale) Generates and appends SVG path operations based on the specified function and parameters. The function is evaluated at evenly spaced intervals between the given start and end of the x-range to build the path. This method delegates the path generation to another overloaded method with specific x-scale and y-scale values.- Parameters:
function- A mathematical function that takes a double as input (x-coordinate) and returns a double (y-coordinate) for each evaluation.xStart- The starting value of the x-coordinate range.xEnd- The ending value of the x-coordinate range.steps- The number of steps to divide the x-range into. If zero, a default value of one is used.yOffset- The vertical offset from the SVG coordinate system's origin (the y-axis is inverted).scale- A scaling factor applied uniformly to both the x- and y-coordinates.- Returns:
- The current instance of
Path, allowing method chaining.
-
function
public Path function(Function<Double, Double> function, double xStart, double xEnd, int steps, boolean smooth, double yOffset, double scale) Generates and appends SVG path operations based on the specified function and parameters. The function is evaluated at evenly spaced intervals between the given start and end of the x-range to build the path. This method delegates the path generation to another overloaded method with specific x-scale and y-scale values.- Parameters:
function- A mathematical function that takes a double as input (x-coordinate) and returns a double (y-coordinate) for each evaluation.xStart- The starting value of the x-coordinate range.xEnd- The ending value of the x-coordinate range.steps- The number of steps to divide the x-range into. If zero, a default value of one is used.smooth- A boolean flag indicating whether to generate a smooth path using cubic Bézier curves. If true, the path will be smoothed. Otherwise, straight lines will connect the points.yOffset- The vertical offset from the SVG coordinate system's origin (the y-axis is inverted).scale- A scaling factor applied uniformly to both the x- and y-coordinates.- Returns:
- The current instance of
Path, allowing method chaining.
-
function
public Path function(Function<Double, Double> function, double xStart, double xEnd, int steps, boolean smooth, double yOffset, double xScale, double yScale) Generates and appends SVG path operations based on the specified function and parameters. The function is evaluated at evenly spaced intervals between the given start and end of the x-range to build the path.- Parameters:
function- A mathematical function that takes a double as input (x-coordinate) and returns a double (y-coordinate) for each evaluation.xStart- The starting value of the x-coordinate range.xEnd- The ending value of the x-coordinate range.steps- The number of steps to divide the x-range into. If zero, a default value of one is used.smooth- A boolean flag indicating whether to generate a smooth path using cubic Bézier curves. If true, the path will be smoothed. Otherwise, straight lines will connect the points.yOffset- The vertical offset from the SVG coordinate system's origin (the y-axis is inverted).xScale- The scaling factor applied to the x-coordinates.yScale- The scaling factor applied to the y-coordinates.- Returns:
- The current instance of
Path, allowing method chaining.
-
build
-