net.kolls.railworld
Class Distance

java.lang.Object
  extended by net.kolls.railworld.Distance

public class Distance
extends java.lang.Object

The Distance class maintains the current scale and zoom information globally, as well as managing individual distance conversion (feet to pixels). Distances should be created as feet and then rendered as pixels; the pixel value will change according to the scale and the zoom. As the user may alter the zoom at any time, the pixel values should not be cached.

To help with the display issues, we provide static point and line scaling routines.

Author:
Steve Kollmansberger

Nested Class Summary
static class Distance.Measure
          The numeric value of each distance may be stored as either pixels or feet.
 
Field Summary
static double feetPerPixels
          This value must be changed prior to constructing any segments, as the segments convert pixels into feet, depending on a correct scale.
 
Constructor Summary
Distance(double val, Distance.Measure measure)
          Create a new distance measurement based on either feet or pixels.
 
Method Summary
 double feet()
          The feet length of this distance.
static double getDefaultZoom()
          The default zoom for new maps or partial displays not subject to user zooming.
 int iPixels()
          The length, in pixels.
 double pixels()
          Compute the pixel length.
static double toFeet(double pixels)
          Convert a given length in pixels into feet/
static double toPixels(double feet)
          Convert a given length in feet into pixels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

feetPerPixels

public static double feetPerPixels
This value must be changed prior to constructing any segments, as the segments convert pixels into feet, depending on a correct scale.

Constructor Detail

Distance

public Distance(double val,
                Distance.Measure measure)
Create a new distance measurement based on either feet or pixels. Creating a value based on pixels will be converted internally to feet immediately based on the current scaling. Thus, if you are creating a value when the scaling is not yet known, you must absolutely use feet.

Parameters:
val - The length.
measure - The unit of the length, as given in Distance.Measure.
Method Detail

getDefaultZoom

public static double getDefaultZoom()
The default zoom for new maps or partial displays not subject to user zooming.

Returns:
A zoom factor based on the current feetPerPixels.

pixels

public double pixels()
Compute the pixel length.

Returns:
A double indicating the length in pixels. For integer values, do not round this one, as it may come to zero. Use iPixels instead.

feet

public double feet()
The feet length of this distance.

Returns:
A double indicating the length in feet.

iPixels

public int iPixels()
The length, in pixels. For any length greater than 0 feet, this value is guaranteed to be at least 1, regardless of scale.

Returns:
An int, containing the pixel length.

toPixels

public static double toPixels(double feet)
Convert a given length in feet into pixels.

Parameters:
feet - The length in feet
Returns:
The length in pixels based on the current feetPerPixels

toFeet

public static double toFeet(double pixels)
Convert a given length in pixels into feet/

Parameters:
pixels - The length in pixels
Returns:
The length in feet based on the current feetPerPixels