Class 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$
    Author:
    Edward A. Lee
    Pt.AcceptedRating:
    Red (johnr)
    Pt.ProposedRating:
    Red (eal)
    • Constructor Summary

      Constructors 
      Constructor Description
      SnapConstraint()
      Construct a new instance of a snap constraint.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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.
      static double getDefaultResolution()
      Return the default resolution.
      double getResolution()
      Return the resolution for this instance.
      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
    • 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.
      • getDefaultResolution

        public static double getDefaultResolution()
        Return the default resolution.
        Returns:
        The global default resolution.
      • getResolution

        public double getResolution()
        Return the resolution for this instance.
        Returns:
        The global default resolution.
        See Also:
        setResolution(double)
      • 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.
        See Also:
        getResolution()