net.charlesames.utility.contour
Class RationalSegment<T>

java.lang.Object
  extended by net.charlesames.utility.common.Disposable
      extended by net.charlesames.utility.entity.Entity
          extended by net.charlesames.utility.entity.WriteableEntity
              extended by net.charlesames.utility.contour.RationalSegment<T>
Type Parameters:
T - Range class (origins and goals)
All Implemented Interfaces:
EntityContainer
Direct Known Subclasses:
ContourTest.TestSegment, ScoreSegment

public abstract class RationalSegment<T>
extends WriteableEntity

Base class defining a segment of a ContourFromRational collection. For the RationalSegment class, the ordinates are Ratio instances.

Author:
Charles Ames

Constructor Summary
RationalSegment(ContourFromRational<T> contour)
          Constructor for RationalSegment instances
RationalSegment(ContourFromRational<T> contour, Ratio left, Ratio right, T origin, T goal)
          Constructor for RationalSegment instances
 
Method Summary
 boolean equals(RationalSegment<T> arg)
          Compare the content of one ContourFromRational segment with another.
 ContourFromRational<T> getContainer()
          Get the ContourFromRational containing this segment.
 T getGoal()
          Get the final value of the segment.
 double getInterpolationFactor(Ratio ordinate)
           
 Ratio getLeft()
          Get the ordinate at the beginning of the segment.
 T getOrigin()
          Get the initial value of the segment.
 int getPosition()
           
 Ratio getRight()
          Get the ordinate at the end of the segment.
 double getSplineFactor(Ratio ordinate)
          Calculate a spline value for the indicated ordinate.
 Ratio getWidth()
          Get the distance between the left and right ordinates.
 double interpolateValue(Ratio ordinate, double origin, double goal)
          Calculate the segment value as of a specified ordinate.
 T valueAt(Ratio ordinate)
          Interpolate between the origin and the goal, based on the position of the ordinate between the segment's left and right bounds.
 void wipe()
          Clear all data in this Entity instance.
 
Methods inherited from class net.charlesames.utility.entity.WriteableEntity
check, clearXmlSpecs, createXmlSpec, getTagName, getXmlData, getXmlSpec, getXmlSpec, initializeXsd, isPersistent, logError, logError, makeDirty, putXmlData, save, setID, setName, setPersistent, setStatus, toXmlNode
 
Methods inherited from class net.charlesames.utility.entity.Entity
decrementReferenceCount, dereferenceHandle, dispose, equals, getHandle, getID, getName, getPath, getReferenceCount, getStatus, getText, hasContainer, incrementReferenceCount, isModifiable, methodHasOverride, predecessor, resequenceEntities, setContainer, setModifiable, shiftEntitiesDown, shiftEntityDown, shiftEntityUp, successor, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RationalSegment

public RationalSegment(ContourFromRational<T> contour)
Constructor for RationalSegment instances

Parameters:
contour -

RationalSegment

public RationalSegment(ContourFromRational<T> contour,
                       Ratio left,
                       Ratio right,
                       T origin,
                       T goal)
Constructor for RationalSegment instances

Parameters:
contour - The ContourFromRational instance that holds this segment.
left - The starting ordinate.
right - The ending ordinate.
origin - The starting value.
goal - The ending value.
Method Detail

wipe

public void wipe()
Description copied from class: Entity
Clear all data in this Entity instance.

Overrides:
wipe in class Entity

getContainer

public ContourFromRational<T> getContainer()
Get the ContourFromRational containing this segment.

Overrides:
getContainer in class WriteableEntity
Returns:
The ContourFromRational containing this segment.

getPosition

public int getPosition()
Returns:
The position of this segment in its parent ContourFromRational.

getLeft

public Ratio getLeft()
Get the ordinate at the beginning of the segment.

Returns:
The ordinate at the beginning of the segment, expressed as a Ratio.

getRight

public Ratio getRight()
Get the ordinate at the end of the segment.

Returns:
The ordinate at the end of the segment, expressed as a Ratio.

getWidth

public Ratio getWidth()
Get the distance between the left and right ordinates.

Returns:
The distance between the left and right ordinates, expressed as a Ratio.

getInterpolationFactor

public double getInterpolationFactor(Ratio ordinate)
Parameters:
ordinate -
Returns:
The distance from the left ordinate to the indicated ordinate, scaled by the segment width.

getSplineFactor

public double getSplineFactor(Ratio ordinate)
Calculate a spline value for the indicated ordinate. The spline function is a 3rd-order polynomial g(x) where g'(left) = 0 and g'(right) = 0; Formula source: https://en.wikipedia.org/wiki/Spline_interpolation#Algorithm_to_find_the_interpolating_cubic_spline

Parameters:
ordinate - A value ranging from RealSegment.getLeft() to RealSegment.getRight().
Returns:
A spline value ranging from zero to unity.
Throws:
java.lang.IllegalArgumentException - when ordinate falls outside range from RealSegment.getLeft() to RealSegment.getRight().

getOrigin

public T getOrigin()
Get the initial value of the segment.

Returns:
The segment value when the ordinate is all the way to the left.

getGoal

public T getGoal()
Get the final value of the segment.

Returns:
The segment value when the ordinate is all the way to the right.

valueAt

public T valueAt(Ratio ordinate)
Interpolate between the origin and the goal, based on the position of the ordinate between the segment's left and right bounds.

Parameters:
ordinate - The input.
Returns:
The output.

interpolateValue

public double interpolateValue(Ratio ordinate,
                               double origin,
                               double goal)
Calculate the segment value as of a specified ordinate.

Parameters:
ordinate - The specified ordinate expressed as a Ratio.
origin - The beginning segment value.
goal - The ending segment value.
Returns:
The interpolated segment value.

equals

public boolean equals(RationalSegment<T> arg)
Compare the content of one ContourFromRational segment with another.

Parameters:
arg - The other ContourFromRational segment.
Returns:
True if the ContourFromRational segments have the same content; false otherwise.