ptolemy.vergil.toolbox
Class SnapConstraint

java.lang.Object
  extended by ptolemy.vergil.toolbox.SnapConstraint
All Implemented Interfaces:
PointConstraint

public class SnapConstraint
extends java.lang.Object
implements PointConstraint

This constraint ensures that a point is a multiple of a constant that defaults to 5.0.

Since:
Ptolemy II 2.0
Version:
$Id: SnapConstraint.java 41641 2006-04-01 01:45:45Z eal $
Author:
Edward A. Lee
Accepted Rating:
Red (johnr)
Proposed Rating:
Red (eal)

Field Summary
private static double _defaultResolution
          The default resolution globally.
private  double _resolution
          The resolution for this instance.
 
Constructor Summary
SnapConstraint()
          Construct a new instance of a snap constraint.
 
Method Summary
 double[] constrain(double[] point)
          Modify the specified point to snap to grid using the local resolution.
 double[] constrain(double x, double y)
          Modify the specified point to snap to grid using the local resolution.
 void constrain(java.awt.geom.Point2D point)
          Modify the specified point to snap to grid using the local resolution.
static double[] constrainPoint(double[] point)
          Modify the specified point to snap to grid using the global default resolution.
static double[] constrainPoint(double x, double y)
          Modify the specified point to snap to grid using the global default resolution.
static java.awt.geom.Point2D constrainPoint(java.awt.geom.Point2D point)
          Modify the specified point to snap to grid using the global default resolution.
 void setResolution(double resolution)
          Set the resolution for this instance.
 boolean snapped()
          Return true to indicate that this does snap to grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_defaultResolution

private static double _defaultResolution
The default resolution globally.


_resolution

private double _resolution
The resolution for this instance.

Constructor Detail

SnapConstraint

public SnapConstraint()
Construct a new instance of a snap constraint.

Method Detail

constrain

public void constrain(java.awt.geom.Point2D point)
Modify the specified point to snap to grid using the local resolution.

Specified by:
constrain in interface PointConstraint
Parameters:
point - The point to modify.

constrain

public double[] constrain(double[] point)
Modify the specified point to snap to grid using the local resolution.

Parameters:
point - The point to modify (a dimension 2 array).
Returns:
The constrained point.

constrain

public double[] constrain(double x,
                          double y)
Modify the specified point to snap to grid using the local resolution.

Parameters:
x - The x dimension of the point to modify.
y - The y dimension of the point to modify.
Returns:
The constrained point.

constrainPoint

public static java.awt.geom.Point2D constrainPoint(java.awt.geom.Point2D point)
Modify the specified point to snap to grid using the global default resolution.

Parameters:
point - The point to modify.
Returns:
The constrained point.

constrainPoint

public static double[] constrainPoint(double[] point)
Modify the specified point to snap to grid using the global default resolution.

Parameters:
point - The point to modify (a dimension 2 array).
Returns:
The constrained point.

constrainPoint

public static double[] constrainPoint(double x,
                                      double y)
Modify the specified point to snap to grid using the global default resolution.

Parameters:
x - The x dimension of the point to modify.
y - The y dimension of the point to modify.
Returns:
The constrained point.

snapped

public boolean snapped()
Return true to indicate that this does snap to grid.

Specified by:
snapped in interface PointConstraint
Returns:
True.

setResolution

public void setResolution(double resolution)
Set the resolution for this instance.

Parameters:
resolution - The new resolution.