Class GreatArcPath.Builder
- java.lang.Object
-
- org.apache.commons.geometry.spherical.twod.GreatArcPath.Builder
-
- Enclosing class:
- GreatArcPath
public static final class GreatArcPath.Builder extends java.lang.Object
Class used to build arc paths.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<GreatArc>
appendedArcs
Arcs appended to the path.private Point2S
endVertex
The current point at the end of the path.private org.apache.commons.numbers.core.Precision.DoubleEquivalence
endVertexPrecision
The precision context used when performing comparisons involving the current end point.private org.apache.commons.numbers.core.Precision.DoubleEquivalence
precision
Precision context used when creating arcs directly from points.private java.util.List<GreatArc>
prependedArcs
Arcs prepended to the path.private Point2S
startVertex
The current point at the start of the path.
-
Constructor Summary
Constructors Modifier Constructor Description private
Builder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Construct a new instance configured with the given precision context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GreatArcPath.Builder
append(GreatArc arc)
Append an arc to the end of the path.GreatArcPath.Builder
append(Point2S vertex)
Add a vertex to the end of this path.private void
appendInternal(GreatArc arc)
Append the given, validated arc to the path.GreatArcPath.Builder
appendVertices(java.util.Collection<Point2S> vertices)
Convenience method for appending a collection of vertices to the path in a single method call.GreatArcPath.Builder
appendVertices(Point2S... vertices)
Convenience method for appending multiple vertices to the path at once.GreatArcPath
build()
Build aGreatArcPath
instance from the configured path.GreatArcPath
build(boolean close)
Build aGreatArcPath
instance from the configured path.GreatArcPath
close()
Close the current path and build a newGreatArcPath
instance.private void
closePath()
Close the path by adding an end point equivalent to the path start point.private org.apache.commons.numbers.core.Precision.DoubleEquivalence
getAddPointPrecision()
Get the precision context used when adding raw points to the path.GreatArc
getEndArc()
Get the arc at the end of the path or null if it does not exist.private GreatArc
getFirst(java.util.List<GreatArc> list)
Get the first element in the list or null if the list is null or empty.private GreatArc
getLast(java.util.List<GreatArc> list)
Get the last element in the list or null if the list is null or empty.GreatArc
getStartArc()
Get the arc at the start of the path or null if it does not exist.GreatArcPath.Builder
prepend(GreatArc arc)
Prepend an arc to the beginning of the path.GreatArcPath.Builder
prepend(Point2S vertex)
Add a vertex to the front of this path.private void
prependInternal(GreatArc arc)
Prepend the given, validated arc to the path.GreatArcPath.Builder
prependPoints(java.util.Collection<Point2S> vertices)
Convenience method for prepending a collection of vertices to the path in a single method call.GreatArcPath.Builder
prependPoints(Point2S... vertices)
Convenience method for prepending multiple vertices to the path in a single method call.GreatArcPath.Builder
setPrecision(org.apache.commons.numbers.core.Precision.DoubleEquivalence builderPrecision)
Set the precision context.private void
validateArcsConnected(GreatArc previous, GreatArc next)
Validate that the given arcs are connected, meaning that the end point ofprevious
is equivalent to the start point ofnext
.
-
-
-
Field Detail
-
appendedArcs
private java.util.List<GreatArc> appendedArcs
Arcs appended to the path.
-
prependedArcs
private java.util.List<GreatArc> prependedArcs
Arcs prepended to the path.
-
precision
private org.apache.commons.numbers.core.Precision.DoubleEquivalence precision
Precision context used when creating arcs directly from points.
-
startVertex
private Point2S startVertex
The current point at the start of the path.
-
endVertex
private Point2S endVertex
The current point at the end of the path.
-
endVertexPrecision
private org.apache.commons.numbers.core.Precision.DoubleEquivalence endVertexPrecision
The precision context used when performing comparisons involving the current end point.
-
-
Constructor Detail
-
Builder
private Builder(org.apache.commons.numbers.core.Precision.DoubleEquivalence precision)
Construct a new instance configured with the given precision context. The precision context is used when building arcs from points and may be omitted if raw points are not used.- Parameters:
precision
- precision context to use when creating arcs from points
-
-
Method Detail
-
setPrecision
public GreatArcPath.Builder setPrecision(org.apache.commons.numbers.core.Precision.DoubleEquivalence builderPrecision)
Set the precision context. This context is used only when creating arcs from appended or prepended points. It is not used when adding existingGreatArc
instances since those contain their own precision contexts.- Parameters:
builderPrecision
- precision context to use when creating arcs from points- Returns:
- this instance
-
getStartArc
public GreatArc getStartArc()
Get the arc at the start of the path or null if it does not exist.- Returns:
- the arc at the start of the path
-
getEndArc
public GreatArc getEndArc()
Get the arc at the end of the path or null if it does not exist.- Returns:
- the arc at the end of the path
-
append
public GreatArcPath.Builder append(GreatArc arc)
Append an arc to the end of the path.- Parameters:
arc
- arc to append to the path- Returns:
- the current builder instance
- Throws:
java.lang.IllegalStateException
- if the path contains a previous arc and the end point of the previous arc is not equivalent to the start point of the given arc
-
append
public GreatArcPath.Builder append(Point2S vertex)
Add a vertex to the end of this path. If the path already has an end vertex, then an arc is added between the previous end vertex and this vertex, using the configured precision context.- Parameters:
vertex
- the vertex to add- Returns:
- this instance
- See Also:
setPrecision(Precision.DoubleEquivalence)
-
appendVertices
public GreatArcPath.Builder appendVertices(java.util.Collection<Point2S> vertices)
Convenience method for appending a collection of vertices to the path in a single method call.- Parameters:
vertices
- the vertices to append- Returns:
- this instance
- See Also:
append(Point2S)
-
appendVertices
public GreatArcPath.Builder appendVertices(Point2S... vertices)
Convenience method for appending multiple vertices to the path at once.- Parameters:
vertices
- the points to append- Returns:
- this instance
- See Also:
append(Point2S)
-
prepend
public GreatArcPath.Builder prepend(GreatArc arc)
Prepend an arc to the beginning of the path.- Parameters:
arc
- arc to prepend to the path- Returns:
- the current builder instance
- Throws:
java.lang.IllegalStateException
- if the path contains a start arc and the end point of the given arc is not equivalent to the start point of the start arc
-
prepend
public GreatArcPath.Builder prepend(Point2S vertex)
Add a vertex to the front of this path. If the path already has a start vertex, then an arc is added between this vertex and the previous start vertex, using the configured precision context.- Parameters:
vertex
- the vertex to add- Returns:
- this instance
- See Also:
setPrecision(Precision.DoubleEquivalence)
-
prependPoints
public GreatArcPath.Builder prependPoints(java.util.Collection<Point2S> vertices)
Convenience method for prepending a collection of vertices to the path in a single method call. The vertices are logically prepended as a single group, meaning that the first vertex in the given collection appears as the first vertex in the path after this method call. Internally, this means that the vertices are actually passed to theprepend(Point2S)
method in reverse order.- Parameters:
vertices
- the points to prepend- Returns:
- this instance
- See Also:
prepend(Point2S)
-
prependPoints
public GreatArcPath.Builder prependPoints(Point2S... vertices)
Convenience method for prepending multiple vertices to the path in a single method call. The vertices are logically prepended as a single group, meaning that the first vertex in the given collection appears as the first vertex in the path after this method call. Internally, this means that the vertices are actually passed to theprepend(Point2S)
method in reverse order.- Parameters:
vertices
- the vertices to prepend- Returns:
- this instance
- See Also:
prepend(Point2S)
-
close
public GreatArcPath close()
Close the current path and build a newGreatArcPath
instance. This method is equivalent tobuilder.build(true)
.- Returns:
- new closed path instance
-
build
public GreatArcPath build()
Build aGreatArcPath
instance from the configured path. This method is equivalent tobuilder.build(false)
.- Returns:
- new path instance
-
build
public GreatArcPath build(boolean close)
Build aGreatArcPath
instance from the configured path.- Parameters:
close
- if true, the path will be closed by adding an end point equivalent to the start point- Returns:
- new path instance
-
closePath
private void closePath()
Close the path by adding an end point equivalent to the path start point.- Throws:
java.lang.IllegalStateException
- if the path cannot be closed
-
validateArcsConnected
private void validateArcsConnected(GreatArc previous, GreatArc next)
Validate that the given arcs are connected, meaning that the end point ofprevious
is equivalent to the start point ofnext
. The arcs are considered valid if either arc is null.- Parameters:
previous
- previous arcnext
- next arc- Throws:
java.lang.IllegalStateException
- if previous and next are not null and the end point of previous is not equivalent the start point of next
-
getAddPointPrecision
private org.apache.commons.numbers.core.Precision.DoubleEquivalence getAddPointPrecision()
Get the precision context used when adding raw points to the path. An exception is thrown if no precision has been specified.- Returns:
- the precision context used when working with raw points
- Throws:
java.lang.IllegalStateException
- if no precision context is configured
-
appendInternal
private void appendInternal(GreatArc arc)
Append the given, validated arc to the path.- Parameters:
arc
- validated arc to append
-
prependInternal
private void prependInternal(GreatArc arc)
Prepend the given, validated arc to the path.- Parameters:
arc
- validated arc to prepend
-
getFirst
private GreatArc getFirst(java.util.List<GreatArc> list)
Get the first element in the list or null if the list is null or empty.- Parameters:
list
- the list to return the first item from- Returns:
- the first item from the given list or null if it does not exist
-
-