uavsim.datatypes
Class Size

java.lang.Object
  extended by uavsim.datatypes.Size

public class Size
extends java.lang.Object

Defines a size as a height and width in arbitrary units.

Author:
Dan Tappan [23.06.11]

Field Summary
private  double _aspectRatio
          the fixed ratio between the width and height; set to NONPROPORTIONAL if this is disabled
private  double _height
          the height
private  double _width
          the width
private static double NONPROPORTIONAL
          the aspect ratio that disables proportional resizing
 
Constructor Summary
Size(double width)
          Creates a size descriptor for a square.
Size(double width, double height)
          Creates a size descriptor.
Size(double width, double height, boolean isProportional)
          Creates a size descriptor.
 
Method Summary
 double aspectRatio()
          Gets the fixed ratio between the width and height.
 CoordinateCartesianAbsolute convertToCoordinateAbsolute(CoordinateCartesianRelative coordinateRelative)
          Calculates an absolute coordinate within the bounds of this size based on a relative coordinate scaler from its center.
 CoordinateCartesianRelative convertToCoordinateAbsolute2XXX(CoordinateCartesianRelative coordinateRelative)
          Calculates a relative scaled coordinate on the interval [-1,+1] from the center of this size based on a relative additive coordinate from the center.
 CoordinateCartesianAbsolute getCenter()
          Gets the center position.
 double getHeight()
          Gets the height.
 double getHeightHalf()
          Gets half the height.
 int getHeightInt()
          Gets the height rounded to an integer.
 int getHeightIntFloor()
          Gets the height rounded to an integer no less than 1.
 double getWidth()
          Gets the width.
 double getWidthHalf()
          Gets half the width.
 int getWidthInt()
          Gets the width rounded to an integer.
 int getWidthIntFloor()
          Gets the width rounded to an integer no less than 1.
 boolean isProportional()
          Returns whether the size and width remain proportional if either changes.
 Size scale(Scaler scaler)
          Scales the size uniformly in both directions.
 Size scale(ScalerPair scaler)
          Scales the size independently in both directions.
private  void setHeight(double height)
          Sets the height and proportionally adjusts it width, if this size is proportional.
private  void setWidth(double width)
          Sets the width and proportionally adjusts it height, if this size is proportional.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_aspectRatio

private final double _aspectRatio
the fixed ratio between the width and height; set to NONPROPORTIONAL if this is disabled


_height

private double _height
the height


_width

private double _width
the width


NONPROPORTIONAL

private static final double NONPROPORTIONAL
the aspect ratio that disables proportional resizing

See Also:
Constant Field Values
Constructor Detail

Size

public Size(double width)
Creates a size descriptor for a square.

Parameters:
width - - the width and height

Size

public Size(double width,
            double height)
Creates a size descriptor.

Parameters:
width - - the width
height - - the height

Size

public Size(double width,
            double height,
            boolean isProportional)
Creates a size descriptor.

Parameters:
width - - the width
height - - the height
isProportional - - whether the size and width remain proportional if either changes
Method Detail

aspectRatio

public double aspectRatio()
Gets the fixed ratio between the width and height.

Returns:
the ratio, or NONPROPORTIONAL if this option is disabled

convertToCoordinateAbsolute

public CoordinateCartesianAbsolute convertToCoordinateAbsolute(CoordinateCartesianRelative coordinateRelative)
Calculates an absolute coordinate within the bounds of this size based on a relative coordinate scaler from its center. For example, for size (20,10), coordinateRelative (-1,+1) returns the bottom-left corner (0,10).

Parameters:
coordinateRelative - - the relative coordinate on the interval [-1,+1]
Returns:
the absolute coordinate

convertToCoordinateAbsolute2XXX

public CoordinateCartesianRelative convertToCoordinateAbsolute2XXX(CoordinateCartesianRelative coordinateRelative)
Calculates a relative scaled coordinate on the interval [-1,+1] from the center of this size based on a relative additive coordinate from the center. For example, for size (20,10), coordinateRelative (-10,+5) returns the bottom-left corner as (-1,+1), meaning 100% to the left and 100% down, both from center.

Parameters:
coordinateRelative - - the relative additive coordinate, which may exceed the size (and therefore produce a result beyond [-1,+1])
Returns:
the relative coordinate on the interval [-1,+1]

getCenter

public CoordinateCartesianAbsolute getCenter()
Gets the center position.

Returns:
the center

getHeight

public double getHeight()
Gets the height.

Returns:
the height

getHeightHalf

public double getHeightHalf()
Gets half the height.

Returns:
half the height

getHeightInt

public int getHeightInt()
Gets the height rounded to an integer.

Returns:
the height

getHeightIntFloor

public int getHeightIntFloor()
Gets the height rounded to an integer no less than 1.

Returns:
the height

getWidth

public double getWidth()
Gets the width.

Returns:
the width

getWidthHalf

public double getWidthHalf()
Gets half the width.

Returns:
half the width

getWidthInt

public int getWidthInt()
Gets the width rounded to an integer.

Returns:
the width

getWidthIntFloor

public int getWidthIntFloor()
Gets the width rounded to an integer no less than 1.

Returns:
the width

isProportional

public boolean isProportional()
Returns whether the size and width remain proportional if either changes.

Returns:
the state

scale

public Size scale(Scaler scaler)
Scales the size uniformly in both directions.

Parameters:
scaler - - the scaler
Returns:
the new size

scale

public Size scale(ScalerPair scaler)
Scales the size independently in both directions.

Parameters:
scaler - - the scaler pair, ordered by width then height
Returns:
the new size

setHeight

private void setHeight(double height)
Sets the height and proportionally adjusts it width, if this size is proportional.

Parameters:
height - - the height

setWidth

private void setWidth(double width)
Sets the width and proportionally adjusts it height, if this size is proportional.

Parameters:
width - - the width

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object