com.azalient.api.a.position
Interface IBezier


public interface IBezier

An object that implements a curved band, where the centre line is defined by a 4-point (cubic) bezier curve, and there are two edges which may be at a uniform width or may change linearly from the start width to the end width.

The four control points are labelled p[0], p[1], p[2] and p[3]. The curve has an implied direction, going from p[0] to p[3], but it can be used as the centreline for network objects allowing two-way travel.

The Bezier curve is drawn using a variable number, N, of intermediate points, and these in turn define N-1 straight line segments. N increases with the "curviness" of the line. There is a global parameter for maximum curve resolution which can be reduced to restrict the memory used to store intermediate bezier points.

The control points define the centre line, and two IEdge objects defining the outer edges. The distance of the edges from the centre line is defined by two width values, one at the start, and one at the end. If the widths are different, the width will change at a uniform rate along the length of the curve. This can lead to some unexpected outcomes for curvy curves.


Field Summary
static double DRAW_ALL
          Use this as the partFill parameter to fill(IDrawing, int, double) to draw the whole length of the curve
 
Method Summary
 void addRecalcListener(IRecalcListener rc)
          Add a listener who will be notified when the shape of the bezier changes - when any of the control points move
 IAngle angleEnd()
          Returns the bearing angle, relative to North, from point p[2] to point p[3]
 IAngle angleStart()
          Returns the bearing angle, relative to North, from point p[0] towards p[1]
 IBezierAssociate associate()
          A reference to the network object that uses this bezier.
 IAngle bearing(int pi, int pj)
          Returns the bearing angle (relative to North) of control point J from control point I.
 ICentre centre()
          The centre point, valid only if this bezier is an arc
 boolean closerThan(IBezier that, double gap)
          Returns true if beziers pass closer than given gap (for turn conflicts etc)
 boolean crosses(IBezier that)
          Returns true if this Bezier crosses that one
 void draw(IDrawing drw, boolean force, double dz, double width, int rgbSpecial, int arrowDirection, boolean drawDashed, boolean hideHandles, boolean drawBarred)
          Draw this bezier, with a range of parameters to control the line style, colour, arrows etc.
 IXyz edgePt(int ti, double sign)
          Returns a point on the edge, given the internal point index and a -1 or +1 for left or right respectively
 void fill(IDrawing drw, int rgb, double partFill)
          Draw this bezier curve, filling the area from edge to edge.
 double halfWidth(double distance)
          Returns the half-width at the given distance
 double halfWidthE()
          Returns the half-width at the End of the curve
 double halfWidthS()
          Returns the half-width at the Start of the curve
 boolean isArc()
          Returns true if this bezier is currently a circular arc, with an associated ICentre point
 boolean isArcLeft()
          Returns true if this arced bezier turns to the left going from p[0] to p[3]
 boolean isFree()
          Returns true if the bezier is curved, i.e.
 boolean isStraight()
          Returns true if the bezier is currently straight, and control points p[1] and p[2] are not shown
 double length()
          Returns the length of the centreline, calculated as the sum of all the internal straight line segment distances.
 IUndoable moveP(int pi, IXyz move)
          Move the given point [0..3] BY the given move vector
 int n()
          The number of points in the curve
 IXyz nearest(IXyz point)
          Returns the nearest point on the bezier to the given point
 double nearest(IXyz pointP, IXyz resultQ, boolean fromStart)
          Find the nearest point, Q, on the curve to a given point P, which can be anywhere, and return that point and the distance of that point along the bezier.
 void outline(IDrawing drw, int rgb, double lineWidth)
          Draw the outline of the bezier, in the given colour and width
 IXyz p(int i)
          Return a control point where i = 0..3
 void p(int i, IXyz pnew)
          Move one of the control points [0..3] to the new position
 IPathway pathway(boolean forward)
          Returns the IPathway object associated with the given direction on this bezier.
 IPosition position(double distanceFromStart)
          Returns a newly-created object containing {point, bearing, gradient} at the given distance along the bezier curve
 IXyz pt(int i)
          A point in the curve, use n() for number of points
 void recalc()
          Force the internal points to be recalculated
 boolean selected()
          Returns true if the bezier is currently selected in the GUI
 void sideShift(IUndoStack us, double d)
          Move the bezier to the side away from the median by distance 'd'.
 void smooth()
          Smooth the curve to attempt to make it tangential to any connected curves or straight lines
 void stretch(IUndoStack us, boolean atP3, double stretchBy)
          Stretch the bezier by the given length.
 double width(double distance)
          Returns the width at the given distance
 double widthE()
          Returns the width at the End of the curve
 double widthS()
          Returns the width at the Start of the curve
 

Field Detail

DRAW_ALL

static final double DRAW_ALL
Use this as the partFill parameter to fill(IDrawing, int, double) to draw the whole length of the curve

See Also:
Constant Field Values
Method Detail

p

IXyz p(int i)
Return a control point where i = 0..3


p

void p(int i,
       IXyz pnew)
Move one of the control points [0..3] to the new position


n

int n()
The number of points in the curve


pt

IXyz pt(int i)
A point in the curve, use n() for number of points


moveP

IUndoable moveP(int pi,
                IXyz move)
Move the given point [0..3] BY the given move vector


sideShift

void sideShift(IUndoStack us,
               double d)
Move the bezier to the side away from the median by distance 'd'. internally, this is used for lanes, but can be used for any bezier, but the direction of the shift is determined by the driving side. Distance d can be negative.


stretch

void stretch(IUndoStack us,
             boolean atP3,
             double stretchBy)
Stretch the bezier by the given length.

Parameters:
atP3 - if true, the bezier is stretched at the end, at p[3] otherwise it is stretched at the start, at p[0]

isFree

boolean isFree()
Returns true if the bezier is curved, i.e. free-form


isStraight

boolean isStraight()
Returns true if the bezier is currently straight, and control points p[1] and p[2] are not shown


isArc

boolean isArc()
Returns true if this bezier is currently a circular arc, with an associated ICentre point


isArcLeft

boolean isArcLeft()
Returns true if this arced bezier turns to the left going from p[0] to p[3]


selected

boolean selected()
Returns true if the bezier is currently selected in the GUI


addRecalcListener

void addRecalcListener(IRecalcListener rc)
Add a listener who will be notified when the shape of the bezier changes - when any of the control points move


centre

ICentre centre()
The centre point, valid only if this bezier is an arc


associate

IBezierAssociate associate()
A reference to the network object that uses this bezier. This may be an ILane or IWalkway, or something else.


position

IPosition position(double distanceFromStart)
Returns a newly-created object containing {point, bearing, gradient} at the given distance along the bezier curve


recalc

void recalc()
Force the internal points to be recalculated


smooth

void smooth()
Smooth the curve to attempt to make it tangential to any connected curves or straight lines


nearest

IXyz nearest(IXyz point)
Returns the nearest point on the bezier to the given point


closerThan

boolean closerThan(IBezier that,
                   double gap)
Returns true if beziers pass closer than given gap (for turn conflicts etc)


crosses

boolean crosses(IBezier that)
Returns true if this Bezier crosses that one


nearest

double nearest(IXyz pointP,
               IXyz resultQ,
               boolean fromStart)
Find the nearest point, Q, on the curve to a given point P, which can be anywhere, and return that point and the distance of that point along the bezier. If Q is beyond the end of the bezier, then the end-point will be returned.

Parameters:
pointP - [IN] a given point, P, not on the curve
resultQ - [OUT] another point Q, the nearest point on the curve to P
fromStart - set to true if the return distance is from the start of the curve, false if the distance is from the end

pathway

IPathway pathway(boolean forward)
Returns the IPathway object associated with the given direction on this bezier. There are two pathway objects, one in each direction.


bearing

IAngle bearing(int pi,
               int pj)
Returns the bearing angle (relative to North) of control point J from control point I. J can be higher or lower than I, but they should not be equal, and both must be in the range [0..3]


length

double length()
Returns the length of the centreline, calculated as the sum of all the internal straight line segment distances.


halfWidthS

double halfWidthS()
Returns the half-width at the Start of the curve


halfWidthE

double halfWidthE()
Returns the half-width at the End of the curve


halfWidth

double halfWidth(double distance)
Returns the half-width at the given distance


widthS

double widthS()
Returns the width at the Start of the curve


widthE

double widthE()
Returns the width at the End of the curve


width

double width(double distance)
Returns the width at the given distance


angleStart

IAngle angleStart()
Returns the bearing angle, relative to North, from point p[0] towards p[1]


angleEnd

IAngle angleEnd()
Returns the bearing angle, relative to North, from point p[2] to point p[3]


edgePt

IXyz edgePt(int ti,
            double sign)
Returns a point on the edge, given the internal point index and a -1 or +1 for left or right respectively

Parameters:
ti - the index of the point, [0..N-1]
sign - either -1 for the "kerb" edge or +1 for the "median" edge. This side parameter also applies to walkways, but means the same side as for a lane. That is, if it were used for a footpath, to the left of a road, where traffic drives on the left, then it could be argued that the kerb side was the right side, but this is not the case in Commuter.

draw

void draw(IDrawing drw,
          boolean force,
          double dz,
          double width,
          int rgbSpecial,
          int arrowDirection,
          boolean drawDashed,
          boolean hideHandles,
          boolean drawBarred)
Draw this bezier, with a range of parameters to control the line style, colour, arrows etc.

Parameters:
drw - The Drawing handle
force - Force this line to be drawn, regardless of any related Viewable/Aspect states
dz - Translate the line by "dz" in the z-axis. This is a convenience to "lift" the line above the corresponding surface
width - the line width
rgbSpecial - an RGB colour to override the colour from the associated Viewable/Aspect
arrowDirection - -1 or +1 to draw an arrow, as for turns/ signals. zero means no arrow
drawDashed - The dash length is pre-defined and cannot be changed here
hideHandles -
drawBarred - Draws a "T" as in for example when a traffic signal is at red.

fill

void fill(IDrawing drw,
          int rgb,
          double partFill)
Draw this bezier curve, filling the area from edge to edge.

Parameters:
drw - The drawing handle
rgb - THE RGB colour code to use
partFill - set partFill to DRAW_ALL (1.0) to draw entire length of curve
or set it to positive P% to draw from the start to P
or set it to negative P% to draw from P to end.

outline

void outline(IDrawing drw,
             int rgb,
             double lineWidth)
Draw the outline of the bezier, in the given colour and width