Building Parsers with Java

sjm.examples.sling
Class Scale

java.lang.Object
  |
  +--sjm.examples.sling.SlingFunction
        |
        +--sjm.examples.sling.Scale

public class Scale
extends SlingFunction

A scale represents the relationship of two temporal variables that vary linearly with each other. In Sling, the most common example of a scale is the relationship of user coordinates to panel coordinates. For example, in plotting a unit circle, a square that bounds the circle has its minimum point at (-1, -1), and its maximum at (1, 1). The minimum is at the lower left corner, where the panel coordinate might be (52.0, 262.0). The maximum is at the upper right, where the panel coordinate might be (314.0, 0.0). If c is a circle function in user coordinates, then the following definition will create s as a function that returns the panel coordinate as a function of time:

 
     Scale s = 
         new Scale(min, c, max, lowerLeft, upperRight); 
 
The function s maps every point on the user's circle to a point on the panel.


Fields inherited from class sjm.examples.sling.SlingFunction
source
 
Constructor Summary
Scale()
          Constructs a scale with the right number of arguments, which is useful for a prototypical scale.
Scale(SlingFunction bFrom, SlingFunction bTo)
          Constructs scale((0, 0), t, (1, 1), bFrom, bTo) .
Scale(SlingFunction aFrom, SlingFunction a, SlingFunction aTo, SlingFunction bFrom, SlingFunction bTo)
          Constructs scale(aFrom, a, aTo, bFrom, bTo).
 
Method Summary
 Point f(double t)
          Given the source functions aFrom, a, aTo, bFrom and bTo, this function varies from bFrom to bTo as "a" varies from aFrom to aTo.
protected  double linear(double aFrom, double a, double aTo, double bFrom, double bTo)
           
 java.lang.String toString()
          Return a string representation of this function.
 
Methods inherited from class sjm.examples.sling.SlingFunction
eval, extrema, fresh
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Scale

public Scale()
Constructs a scale with the right number of arguments, which is useful for a prototypical scale.

Scale

public Scale(SlingFunction bFrom,
             SlingFunction bTo)
Constructs scale((0, 0), t, (1, 1), bFrom, bTo) .
Parameters:
bFrom - a SlingFunction (usually a Point) that establishes the "from" bound for some variable b, which this scale represents
bTo - a SlingFunction (also usually a Point) that establishes the "to" bound for the variable.

Scale

public Scale(SlingFunction aFrom,
             SlingFunction a,
             SlingFunction aTo,
             SlingFunction bFrom,
             SlingFunction bTo)
Constructs scale(aFrom, a, aTo, bFrom, bTo). The returned scale varies from bFrom to bTo as "a" varies from aFrom to aTo. The "from" and "to" functions are usually points, so that the returned scale maps between two sets of coordinates.
Method Detail

f

public Point f(double t)
Given the source functions aFrom, a, aTo, bFrom and bTo, this function varies from bFrom to bTo as "a" varies from aFrom to aTo.
Overrides:
f in class SlingFunction
Parameters:
t - a number that represents how far along a plot is, and thus tells which point to return
Returns:
a new point b, that maps a.f(t) into the scale for b

linear

protected double linear(double aFrom,
                        double a,
                        double aTo,
                        double bFrom,
                        double bTo)

toString

public java.lang.String toString()
Return a string representation of this function.
Overrides:
toString in class java.lang.Object

by Steve Metsker