edu.mit.sketch.ddg
Class Util

java.lang.Object
  extended by edu.mit.sketch.ddg.Util

public class Util
extends java.lang.Object

This class implements several static methods useful for the package.

Util.java Created: Tue Apr 5 19:47:00 2002

Author:
Olya Veselova

Field Summary
static boolean DEBUG_MODE
          Determines whether the system is in debug mode
static double MAX_ANGULAR_OFFSET
          The maximum angle that can be considered negligible
static double MAX_OFFSET
          The maximum offset after which the distance between two points cannot be considered negligible
static double OBSTRUCTION_SENSITIVITY
          Determines how sensitive constraints are to obstruction
static double SIZE_TO_OFFSET_RATIO
          How much larger the object should be than the distance from this object to some other point so that that the confidence distance is just considered negligible
 
Constructor Summary
Util()
           
 
Method Summary
static boolean aboveLine(Point p, Line l)
          Returns true if the given point is in the upper hyperplane as defined by the line
static double angleNegligible(double angle)
          The confidence that the given angle (in radians) can be considered negligible.
static boolean belowLine(Point p, Line l)
          Returns true if the given point is in the lower hyperplane as defined by the line
static Polygon closedContour(DrawnObject object, ConnectsConstraint connectsConstraint, IntersectsConstraint intersectsConstraint)
          If the given object is a closed contour return a polygon that is the boundary.
static Point closestPoint(Ellipse e, Point p)
          Returns the closest point on the ellipse to the given point
static Point closestPoint(Line line, Point p)
          Returns the closest point on the line to a given point
static int closestPointType(Ellipse e, Point p)
          Returns the closest qualitative point type on the ellipse to the given point
static void debug(java.lang.String txt)
          Prints out debugging information if in debugging mode
static double distanceNegligible(double distance, double objectSize)
          The confidence that the given distance can be considered negligible.
static Line[] eightLineEllipseApproximation(Ellipse e)
          Approximate the ellipse with 8 lines and return the list
static GeometricObjectList ellipseApproximation(Ellipse e)
          Approximate the ellipse with a list of lines and return the list
static boolean isHorizontal(Line line)
           
static boolean isVertical(Line line)
           
static boolean leftOfLine(Point p, Line l)
          Returns true if the given point is in the left hyperplane as defined by the line
static double minDistance(GeometricObject o1, GeometricObject o2)
          Calculte the minimum distance between two primitives.
static double minLineDistance(Line l1, Line l2)
          Calculate the minimun distance between two line segments
static boolean onSameAxis(Line l1, Line l2)
           
static double parallelity(Line l1, Line l2)
          Returns the degree of parallelity from 0 to 1;
static Line parallelSegment(Line l, Ellipse e)
          Find the closest of the two ellipse segments that are most parallel to the given line
static boolean rightOfLine(Point p, Line l)
          Returns true if the given point is in the right hyperplane as defined by the line
static double roundToPrecision(double value, int precision)
          Round a double to a given number of decimal places
static boolean sameSide(Line line, Point p1, Point p2)
          Takes in a line, that defines a hyperplane, and returns true is the second point is in the same hyperplane as the first point.
static double sigmoid(double a, double x, double b)
          Returns the value of the function 1 / (1 + exp{-a*(x - b)})
static double size(GeometricObject object)
          Calculate the size of the geometric object
static double twoSlopeRoofFunction(double value, double smallWidth, double largeWidth, double maxX, double medY)
          Two-slope-roof-like function returning value in the interval [0;1].
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIZE_TO_OFFSET_RATIO

public static double SIZE_TO_OFFSET_RATIO
How much larger the object should be than the distance from this object to some other point so that that the confidence distance is just considered negligible


MAX_OFFSET

public static double MAX_OFFSET
The maximum offset after which the distance between two points cannot be considered negligible


MAX_ANGULAR_OFFSET

public static double MAX_ANGULAR_OFFSET
The maximum angle that can be considered negligible


OBSTRUCTION_SENSITIVITY

public static double OBSTRUCTION_SENSITIVITY
Determines how sensitive constraints are to obstruction


DEBUG_MODE

public static boolean DEBUG_MODE
Determines whether the system is in debug mode

Constructor Detail

Util

public Util()
Method Detail

angleNegligible

public static double angleNegligible(double angle)

The confidence that the given angle (in radians) can be considered negligible. Returns a value in the interval [0;1]. The angle that is larger than MAX_ANGULAR_OFFSET cannont be negligible


distanceNegligible

public static double distanceNegligible(double distance,
                                        double objectSize)

The confidence that the given distance can be considered negligible. Returns a value in the interval [0;1]. The distance and object size should be passed in pixels devided by the line width on the screen. That is the distance is measured in the perceived pixels.
Ideally the confidence depends on two factors:
- object size - the larger, the more the confidence, given the same distance
- distance - the smaller, the more the confidence, given the same size
Here we approximate this function by size factor if distance is below MAX_OFFSET, and by distance factor if size-to-distance ratio is more than SIZE_TO_OFFSET_RATIO


closedContour

public static Polygon closedContour(DrawnObject object,
                                    ConnectsConstraint connectsConstraint,
                                    IntersectsConstraint intersectsConstraint)
If the given object is a closed contour return a polygon that is the boundary. Otherwise return null. A closed contour is a contour where each line connects to exactly two other lines on both sides and no lines intersect each other. Currently only handles closed contours consisting of lines.


twoSlopeRoofFunction

public static double twoSlopeRoofFunction(double value,
                                          double smallWidth,
                                          double largeWidth,
                                          double maxX,
                                          double medY)
                                   throws InvalidParameterException
Two-slope-roof-like function returning value in the interval [0;1]. The function reaches the maximum of 1 at maxX, falls off on both sides to a medY value that is at maxX +- smallWidth, and then falls off to 0 on both sides at maxX +- largeWidth. medY should be in [0;1] interval. If not throws an exception.

Throws:
InvalidParameterException

debug

public static void debug(java.lang.String txt)
Prints out debugging information if in debugging mode


roundToPrecision

public static double roundToPrecision(double value,
                                      int precision)
Round a double to a given number of decimal places


parallelity

public static double parallelity(Line l1,
                                 Line l2)
Returns the degree of parallelity from 0 to 1;


parallelSegment

public static Line parallelSegment(Line l,
                                   Ellipse e)
Find the closest of the two ellipse segments that are most parallel to the given line


eightLineEllipseApproximation

public static Line[] eightLineEllipseApproximation(Ellipse e)
Approximate the ellipse with 8 lines and return the list


ellipseApproximation

public static GeometricObjectList ellipseApproximation(Ellipse e)
Approximate the ellipse with a list of lines and return the list


minDistance

public static double minDistance(GeometricObject o1,
                                 GeometricObject o2)
Calculte the minimum distance between two primitives. Note: the distance between ellipses determined by the distance between their axes.


size

public static double size(GeometricObject object)
Calculate the size of the geometric object


minLineDistance

public static double minLineDistance(Line l1,
                                     Line l2)
Calculate the minimun distance between two line segments


aboveLine

public static boolean aboveLine(Point p,
                                Line l)
Returns true if the given point is in the upper hyperplane as defined by the line


belowLine

public static boolean belowLine(Point p,
                                Line l)
Returns true if the given point is in the lower hyperplane as defined by the line


rightOfLine

public static boolean rightOfLine(Point p,
                                  Line l)
Returns true if the given point is in the right hyperplane as defined by the line


leftOfLine

public static boolean leftOfLine(Point p,
                                 Line l)
Returns true if the given point is in the left hyperplane as defined by the line


sameSide

public static boolean sameSide(Line line,
                               Point p1,
                               Point p2)
Takes in a line, that defines a hyperplane, and returns true is the second point is in the same hyperplane as the first point. Assumes that both points are not on the infinite line defined by the line.


sigmoid

public static double sigmoid(double a,
                             double x,
                             double b)
Returns the value of the function 1 / (1 + exp{-a*(x - b)})


closestPoint

public static Point closestPoint(Ellipse e,
                                 Point p)
Returns the closest point on the ellipse to the given point


closestPointType

public static int closestPointType(Ellipse e,
                                   Point p)
Returns the closest qualitative point type on the ellipse to the given point


closestPoint

public static Point closestPoint(Line line,
                                 Point p)
Returns the closest point on the line to a given point


isVertical

public static boolean isVertical(Line line)

isHorizontal

public static boolean isHorizontal(Line line)

onSameAxis

public static boolean onSameAxis(Line l1,
                                 Line l2)