Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DirectedPath arrow-offset #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions src/gov/nasa/worldwindx/examples/util/DirectedPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@
*/
public class DirectedPath extends Path
{
/** Default arrow offset (value between 0 and 1). */
public static final double DEFAULT_ARROW_OFFSET = 0.5;
/** Default arrow length, in meters. */
public static final double DEFAULT_ARROW_LENGTH = 300;
/** Default arrow angle. */
public static final Angle DEFAULT_ARROW_ANGLE = Angle.fromDegrees(45.0);
/** Default maximum screen size of the arrowheads, in pixels. */
public static final double DEFAULT_MAX_SCREEN_SIZE = 20.0;

/** The offset that determines where the arrow is positioned. */
protected double arrowOffset = DEFAULT_ARROW_OFFSET;
/** The length, in meters, of the arrowhead, from tip to base. */
protected double arrowLength = DEFAULT_ARROW_LENGTH;
/** The angle of the arrowhead tip. */
Expand Down Expand Up @@ -93,6 +97,33 @@ public DirectedPath(Position posA, Position posB)
{
super(posA, posB);
}

/**
* Indicates the offset (as a ratio) of the arrowhead from base (0.0) to tip (1.0).
*
* @return The offset of the direction arrowheads.
*/
public double getArrowOffset()
{
return this.arrowOffset;
}

/**
* Specifies the offset of the direction arrowheads, from base (0.0) to tip (1.0).
*
* @param arrowOffset offset of the direction arrowheads. The offset must be a value between 0.0 and 1.0.
*/
public void setArrowOffset(double arrowOffset)
{
if (arrowOffset < 0 || arrowOffset > 1.0)
{
String message = Logging.getMessage("generic.ArgumentOutOfRange", arrowOffset);
Logging.logger().severe(message);
throw new IllegalArgumentException(message);
}

this.arrowOffset = arrowOffset;
}

/**
* Indicates the length, in meters, of the direction arrowheads, from base to tip.
Expand Down Expand Up @@ -284,7 +315,7 @@ protected void computeDirectionArrows(DrawContext dc, PathData pathData)
Vec4 polePtB = this.computePoint(dc, terrain, tessellatedPositions.get(poleB));

this.computeArrowheadGeometry(dc, poleA, poleB, polePtA, polePtB, buffer, pathData);

poleA = poleB;
polePtA = polePtB;
}
Expand Down Expand Up @@ -327,7 +358,7 @@ protected void computeArrowheadGeometry(DrawContext dc, int poleA, int poleB, Ve
double poleDistance = polePtA.distanceTo3(polePtB);

// Find the segment that is midway between the two poles.
int midIndex = (poleA + poleB) / 2;
int midIndex = (int)Math.floor(this.arrowOffset * (poleA + poleB));
List<Position> tessellatedPositions = pathData.getTessellatedPositions();
Position posA = tessellatedPositions.get(midIndex);
Position posB = tessellatedPositions.get(midIndex + 1);
Expand Down