예제 #1
0
 /**
  * Returns true if the x and y coordinates of two points are closer than epsilon
  *
  * @param point the point to compare to
  * @param epsilon the acceptable error
  */
 public bool isCloseTo(Point point, double epsilon)
 {
     if (point == null)
     {
         return(false);
     }
     return(CoordinateCalculator.hasDifferenceLessThan(this.X, point.X, epsilon) &&
            CoordinateCalculator.hasDifferenceLessThan(this.Y, point.Y, epsilon));
 }
예제 #2
0
 /**
  * Returns true if the angles and distances of the two directions are within epsilon of each other.
  *
  * @param point the point to compare to
  * @param epsilon the acceptable error
  */
 public bool isCloseTo(Direction direction, double epsilon)
 {
     if (direction == null)
     {
         return(false);
     }
     return(CoordinateCalculator.hasDifferenceLessThan((float)this.angle, (float)direction.angle, epsilon) &&
            CoordinateCalculator.hasDifferenceLessThan((float)this.distance, (float)direction.distance, epsilon));
 }
예제 #3
0
        /**
         * Returns true if the crossing points of two nodes are closer than epsilon
         *
         * @param node the node to compare to
         * @param epsilon the acceptable error
         */
        public bool isCloseTo(Edge e, double epsilon)
        {
            if (e == null)
            {
                return(false);
            }
            bool closeEndpoints = (this.N1.isCloseTo(e.N1, epsilon)) && (this.N2.isCloseTo(e.N2, epsilon)) || (this.N2.isCloseTo(e.N1, epsilon)) && (this.N1.isCloseTo(e.N2, epsilon));
            bool closeWeight    = CoordinateCalculator.hasDifferenceLessThan((float)this.Weight, (float)e.Weight, epsilon);

            return(closeEndpoints && closeWeight);
        }
예제 #4
0
        /*
         * Returns the crossing point is the line crosses the other line, null if the lines do not cross
         * (!) lines are assued to be finite, starting at the start point, and ending at the end point
         * @param line the other line
         * @param epsilon the amount of error that is permittable for two points to be considered equal
         * (two points that are closer than epsilon will be considered equal)
         */
        public Point crosses(Line line, double epsilon)
        {
            if (CoordinateCalculator.hasDifferenceLessThan(end_pt.X, start_pt.X, epsilon) &&
                !CoordinateCalculator.hasDifferenceLessThan(line.end_pt.X, line.start_pt.X, epsilon))
            {
                float crosing_x   = end_pt.X;
                float crossing_y  = line.getSlope() * crosing_x + line.getConstant();
                Point crossing_pt = new Point(crosing_x, crossing_y);
                if (this.containsInVector(crossing_pt, epsilon) && line.containsInVector(crossing_pt, epsilon))
                {
                    return(crossing_pt);
                }
            }
            else if (!CoordinateCalculator.hasDifferenceLessThan(end_pt.X, start_pt.X, epsilon) &&
                     CoordinateCalculator.hasDifferenceLessThan(line.end_pt.X, line.start_pt.X, epsilon))
            {
                float crosing_x   = line.end_pt.X;
                float crossing_y  = getSlope() * crosing_x + getConstant();
                Point crossing_pt = new Point(crosing_x, crossing_y);
                if (this.containsInVector(crossing_pt, epsilon) && line.containsInVector(crossing_pt, epsilon))
                {
                    return(crossing_pt);
                }
            }
            else if ((CoordinateCalculator.hasDifferenceLessThan(end_pt.X, start_pt.X, epsilon) &&
                      CoordinateCalculator.hasDifferenceLessThan(line.end_pt.X, line.start_pt.X, epsilon)) ||
                     (this.getSlope() == line.getSlope()))
            {
                if (start_pt.isCloseTo(line.getStartPoint(), epsilon) ||
                    start_pt.isCloseTo(line.getEndPoint(), epsilon))
                {
                    return(start_pt);
                }
                else if (end_pt.isCloseTo(line.getEndPoint(), epsilon) ||
                         end_pt.isCloseTo(line.getStartPoint(), epsilon))
                {
                    return(end_pt);
                }
            }
            else
            {
                float crosing_x   = (line.getConstant() - this.getConstant()) / (this.getSlope() - line.getSlope());
                float crossing_y  = this.getSlope() * crosing_x + this.getConstant();
                Point crossing_pt = new Point(crosing_x, crossing_y);
                if (this.containsInVector(crossing_pt, epsilon) && line.containsInVector(crossing_pt, epsilon))
                {
                    return(crossing_pt);
                }
            }

            return(null);
        }
예제 #5
0
 /*
  * Returns true if the point is on a geometric infinite line is in the interval set by the given vector (finite "line" with endpoints)
  * @point point
  * @param epsilon the amount of error that is permittable for two points to be considered equal
  * (two points that are closer than epsilon will be considered equal)
  */
 public bool contains(Point point, double epsilon)
 {
     if (CoordinateCalculator.hasDifferenceLessThan(end_pt.X, start_pt.X, epsilon))
     {
         return(CoordinateCalculator.hasDifferenceLessThan(point.X, start_pt.X, epsilon) &&
                containsInVector(point, epsilon));
     }
     else
     {
         float testY = getSlope() * point.X + getConstant();
         return(CoordinateCalculator.hasDifferenceLessThan(point.Y, testY, epsilon) &&
                containsInVector(point, epsilon));
     }
 }
예제 #6
0
 /*
  * Returns true if coord_a <= coord <= coord_b or  coord_a >= coord >= coord_b
  * Two coordinates are assumed to be equal if they are closer than epsilon to each other
  *
  * @param coord coordinate that is either between two other or not
  * @param coord_a first coordinate
  * @param coord_b second coordinate
  * @param epsilon maximal difference between two coordinates to be considered equal
  */
 public static bool isBetween(float coord, float coord_a, float coord_b, double epsilon)
 {
     return((coord > coord_a || CoordinateCalculator.hasDifferenceLessThan(coord, coord_a, epsilon)) &&
            (coord < coord_b || CoordinateCalculator.hasDifferenceLessThan(coord, coord_b, epsilon)));
 }