net.charlesames.utility.contour
Class RealSegment<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.RealSegment<T>
Type Parameters:
T - Range class (origins and goals)
All Implemented Interfaces:
EntityContainer

public abstract class RealSegment<T>
extends WriteableEntity

Base class defining a segment of a ContourFromReal collection. For the RealSegment class, the ordinates are double-precision numbers.

Author:
Charles Ames

Constructor Summary
RealSegment(ContourFromReal<T> contour)
          Constructor for RealSegment instances
RealSegment(ContourFromReal<T> contour, double left, double right, T origin, T goal)
          Constructor for RealSegment instances
 
Method Summary
 boolean equals(RealSegment<T> arg)
          Compare the content of one ContourFromReal segment with another.
 ContourFromReal<T> getContainer()
          Get the ContourFromReal containing this segment.
 T getGoal()
           
 double getInterpolationFactor(double ordinate)
          Scale the distance from the left ordinate to the indicated ordinate by the segment width.
 double getLeft()
          Get the ordinate at the beginning of the segment.
 T getOrigin()
           
 int getPosition()
           
 double getRight()
          Get the ordinate at the end of the segment.
 double getSplineFactor(double ordinate)
          Calculate a spline value for the indicated ordinate.
 double getWidth()
          Get the distance between the left and right ordinates.
 double interpolateValue(double ordinate, double origin, double goal)
          Calculate the segment value as of a specified ordinate.
 T valueAt(double 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

RealSegment

public RealSegment(ContourFromReal<T> contour)
Constructor for RealSegment instances

Parameters:
contour -

RealSegment

public RealSegment(ContourFromReal<T> contour,
                   double left,
                   double right,
                   T origin,
                   T goal)
Constructor for RealSegment instances

Parameters:
contour -
left -
right -
origin -
goal -
Throws:
java.lang.IllegalArgumentException
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 ContourFromReal<T> getContainer()
Get the ContourFromReal containing this segment.

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

getPosition

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

getLeft

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

Returns:
The ordinate at the beginning of the segment, expressed as a double-precision number.

getRight

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

Returns:
The ordinate at the end of the segment, expressed as a double-precision number.

getWidth

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

Returns:
The distance between the left and right ordinates, expressed as a double-precision number.

getInterpolationFactor

public double getInterpolationFactor(double ordinate)
Scale the distance from the left ordinate to the indicated ordinate by the segment width.

Parameters:
ordinate - A value ranging from getLeft() to getRight().
Returns:
The distance from the left ordinate to the indicated ordinate, scaled by the segment width.
Throws:
java.lang.IllegalArgumentException - when ordinate falls outside range from getLeft() to getRight().

getSplineFactor

public double getSplineFactor(double 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 getLeft() to getRight().
Returns:
A spline value ranging from zero to unity.
Throws:
java.lang.IllegalArgumentException - when ordinate falls outside range from getLeft() to getRight().

getOrigin

public T getOrigin()
Returns:
The segment value when the ordinate is all the way to the left.

getGoal

public T getGoal()
Returns:
The segment value when the ordinate is all the way to the right.

valueAt

public T valueAt(double 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(double ordinate,
                               double origin,
                               double goal)
Calculate the segment value as of a specified ordinate.

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

equals

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

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