Example #1
0
 private static Points createSamplePoint(int number) {
   Points p = new Points();
   p.name = "VeryVeryLongName: " + number;
   p.address = "VeryVeryLongLongAddress: " + number;
   p.coord1 = 123;
   p.coord2 = 456;
   return p;
 }
Example #2
0
 /*
  * check if vertex i forms an ear: triangle (i-1, i, i+1) inside pol
  * ccw is true iff polygon is in counter-clockwise order
  */
 private static boolean ear(Point[] pol, int i) {
   int n = pol.length;
   int j = (i - 1 + n) % n;
   int k = (i + 1 + n) % n;
   // if ccw then points must also be ccw
   if (Points.cw(pol[j], pol[i], pol[k])) return false;
   for (int m = 0; m < n; m++) {
     if (m != i && m != j && m != k && Points.inTriangle(pol[m], pol[j], pol[i], pol[k])) {
       return false;
     }
   }
   return true;
 }
Example #3
0
 // assumes p is not on P
 public static double winding(ArrayList<Point> P, Point p) {
   // make a translation so p = (0, 0)
   Point[] Q = Points.translation(P, -p.x, -p.y);
   double w = 0;
   for (int i = 0; i < Q.length; i++) {
     int j = (i + 1) % Q.length;
     if (Q[i].y * Q[j].y <= 0) {
       // segment crosses the x-axis
       double r = (Q[i].y - Q[j].y) * Q[i].x + Q[i].y * (Q[j].x - Q[i].x);
       // check for intersection with the positive x-axis
       if ((Q[i].y - Q[j].y > 0 && r > 0) || (Q[i].y - Q[j].y < 0 && r < 0)) {
         // segment fully crosses the x-axis
         // - to + add 1, + to - subtract 1
         w += Q[i].y < 0 ? 1 : -1;
       } else if (Q[i].y == 0 && Q[i].x > 0) {
         // the segment starts at t - 1he x-axis
         // 0 to + add 0.5, 0 to - subtract 0.5
         w += Q[j].y > 0 ? 0.5 : -0.5;
       } else if (Q[j].y == 0 && Q[i + 1].x > 0) {
         // the segment ends at the x-axis
         // - to 0 add 0.5, + to 0 subtract 0.5
         w += Q[i].y < 0 ? 0.5 : -0.5;
       }
     }
   }
   return w;
 }
 public void calcurate(String say) {
   for (int i = 0; i < words.length; i++) {
     if (say.indexOf(words[i]) != -1) {
       point.addpoints();
     }
   }
 }
Example #5
0
 public static ArrayList<Point> cut(ArrayList<Point> pol, Point p, Point q, Point x) {
   ArrayList<Point> res = new ArrayList<>();
   int orient = Points.orient(p, q, x);
   Line L = new Line(p, q);
   for (int i = 0; i < pol.size(); i++) {
     int j = (i + 1) % pol.size();
     if (Points.orient(p, q, pol.get(i)) == orient) {
       res.add(pol.get(i));
     }
     Point inter = L.intersection(new Line(pol.get(i), pol.get(j)));
     if (inter != null && Points.onSegment(pol.get(i), pol.get(j), inter)) {
       res.add(inter);
     }
   }
   return res;
 }
Example #6
0
 public static boolean onBoundary(Point[] pol, Point p) {
   int n = pol.length;
   for (int i = 0; i < n; i++) {
     int j = (i + 1) % n;
     if (Points.onSegment(pol[i], pol[j], p)) return true;
   }
   return false;
 }
Example #7
0
 public static boolean onBoundary(ArrayList<Point> pol, Point p) {
   int n = pol.size();
   for (int i = 0; i < n; i++) {
     int j = (i + 1) % n;
     if (Points.onSegment(pol.get(i), pol.get(j), p)) return true;
   }
   return false;
 }
Example #8
0
 /** Check if a polygon is convex. O(n) */
 public static boolean convex(Point[] pol) {
   int n = pol.length;
   int orient1 = 0;
   // find a vertex with non-zero orientation
   for (int i = 0; i < n; i++) {
     int prev = (i - 1 + n) % n;
     int next = (i + 1) % n;
     orient1 = Points.orient(pol[prev], pol[i], pol[next]);
     if (orient1 != 0) break;
   }
   // check if all vertices have either zero orientation or orient1
   for (int i = 0; i < n; i++) {
     int prev = (i - 1 + n) % n;
     int next = (i + 1) % n;
     int orient2 = Points.orient(pol[prev], pol[i], pol[next]);
     if (orient2 != 0 && orient2 != orient1) return false;
   }
   return true;
 }
  /**
   * Create a single {@link com.rackspacecloud.blueflood.service.SingleRollupWriteContext} from the
   * given {@link com.rackspacecloud.blueflood.types.IMetric} and Granularity.
   *
   * @param destGran
   * @param metric
   * @return
   * @throws IOException
   */
  protected SingleRollupWriteContext createSingleRollupWriteContext(
      Granularity destGran, IMetric metric) throws IOException {

    Locator locator = metric.getLocator();

    Points<SimpleNumber> points = new Points<SimpleNumber>();
    points.add(
        new Points.Point<SimpleNumber>(
            metric.getCollectionTime(), new SimpleNumber(metric.getMetricValue())));

    BasicRollup rollup = BasicRollup.buildRollupFromRawSamples(points);

    return new SingleRollupWriteContext(
        rollup,
        locator,
        destGran,
        CassandraModel.getBasicColumnFamily(destGran),
        metric.getCollectionTime());
  }
Example #10
0
  public List<LatLng> getListPoints() {
    List<LatLng> list = new ArrayList<LatLng>();

    if (points == null || points.size() == 0) {
      return null;
    }
    Iterator<Points> it = points.iterator();

    while (it.hasNext()) {
      Points pois = (Points) it.next();

      List<Double> location = pois.getLocation();
      if (Math.abs(location.get(0) - 0.0) < 0.01 && Math.abs(location.get(1) - 0.0) < 0.01) {
        continue;
      } else {
        LatLng latLng = new LatLng(location.get(1), location.get(0));
        list.add(latLng);
      }
    }
    return list;
  }
Example #11
0
 /*
  * Cut a polygon by the line pq
  */
 @SuppressWarnings("rawtypes")
 public static ArrayList[] cut(ArrayList<Point> pol, Point p, Point q) {
   ArrayList<Point> polWithInter = new ArrayList<>();
   Line L = new Line(p, q);
   for (int i = 0; i < pol.size(); i++) {
     polWithInter.add(pol.get(i));
     int j = (i + 1) % pol.size();
     Point inter = L.intersection(new Line(pol.get(i), pol.get(j)));
     if (inter != null
         && Points.onSegment(pol.get(i), pol.get(j), inter)
         && !Points.eq(pol.get(i), inter)
         && !Points.eq(pol.get(j), inter)) {
       polWithInter.add(inter);
     }
   }
   ArrayList<Point> pol1 = new ArrayList<Point>();
   ArrayList<Point> pol2 = new ArrayList<Point>();
   for (Point x : polWithInter) {
     int orient = Points.orient(x, p, q);
     if (orient <= 0) pol1.add(x);
     if (orient >= 0) pol2.add(x);
   }
   return new ArrayList[] {pol1, pol2};
 }
Example #12
0
 public static boolean inPolygon2(ArrayList<Point> pol, Point p) {
   double xmin = Double.POSITIVE_INFINITY;
   for (Point q : pol) {
     xmin = Math.min(xmin, q.x);
   }
   int n = pol.size();
   int inter = 0;
   Point q = new Point(xmin - 1, p.y);
   for (int i = 0; i < n; i++) {
     int j = (i + 1) % n;
     if (Points.intersects(pol.get(i), pol.get(j), p, q)) {
       inter++;
     }
   }
   return inter % 2 == 1;
 }
Example #13
0
 public static boolean inPolygon2(Point[] pol, Point p) {
   double xmin = Double.POSITIVE_INFINITY;
   for (Point q : pol) {
     xmin = Math.min(xmin, q.x);
   }
   int n = pol.length;
   int inter = 0;
   Point q = new Point(xmin - 1, p.y);
   for (int i = 0; i < n; i++) {
     int j = (i + 1) % n;
     if (Points.intersects(pol[i], pol[j], p, q)) {
       inter++;
     }
   }
   return inter % 2 == 1;
 }
  /**
   * Convert a list of {@link com.rackspacecloud.blueflood.types.Points} into a list of {@link
   * com.rackspacecloud.blueflood.service.SingleRollupWriteContext} for the given Granularity and
   * Locator.
   *
   * @param locator
   * @param points
   * @param gran
   * @return
   */
  protected List<SingleRollupWriteContext> toWriteContext(
      Locator locator, Points<Rollup> points, Granularity gran) {

    List<SingleRollupWriteContext> resultList = new ArrayList<SingleRollupWriteContext>();

    for (Map.Entry<Long, Points.Point<Rollup>> entry : points.getPoints().entrySet()) {

      resultList.add(
          new SingleRollupWriteContext(
              entry.getValue().getData(),
              locator,
              gran,
              CassandraModel.getBasicColumnFamily(gran),
              entry.getKey()));
    }

    return resultList;
  }
Example #15
0
 @Override // from ICircle
 public boolean intersects(ICircle c) {
   double maxDist = radius() + c.radius();
   return Points.distanceSq(x(), y(), c.x(), c.y()) < (maxDist * maxDist);
 }
Example #16
0
 @Override // from Object
 public String toString() {
   return Dimensions.dimenToString(width(), height()) + Points.pointToString(x(), y());
 }
 @Override // from IPoint
 public double distance(IPoint p) {
   return Points.distance(x(), y(), p.x(), p.y());
 }
 @Override // from IPoint
 public double distance(double px, double py) {
   return Points.distance(x(), y(), px, py);
 }
 @Override
 public String toString() {
   return Points.pointToString(x(), y());
 }
Example #20
0
 @Override // from IPoint
 public float distance(float px, float py) {
   return Points.distance(x(), y(), px, py);
 }
Example #21
0
 public boolean onBoundary(Point p) {
   return Cmp.eq(Points.sqDistance(p, center), rr());
 }
Example #22
0
 public int getPoint() {
   return point.getPoints();
 }
Example #23
0
 /**
  * Returns the first <code>Point</code> of this <code>LineString</code>.
  *
  * @return the first <code>Point</code> of this <code>LineString</code>.
  */
 public Point getStartPoint() {
   return isEmpty() ? Points.createEmpty() : getPointN(0);
 }
Example #24
0
 /**
  * Returns the last <code>Point</code> of this <code>LineString</code>.
  *
  * @return the last <code>Point</code> of this <code>LineString</code>.
  */
 public Point getEndPoint() {
   return isEmpty() ? Points.createEmpty() : getPointN(getNumPoints() - 1);
 }
Example #25
0
 @Override // from IPoint
 public float distanceSq(IPoint p) {
   return Points.distanceSq(x(), y(), p.x(), p.y());
 }
Example #26
0
  // This method will construct the best possible path by using the A* search algorithm
  private static List<String> AStarSearch(Polygon[] finalPolygons) {

    List<String> completedPath = new ArrayList<String>();
    String[] Ender = ePoint.split(",");

    // The final goal point
    double endx = Double.parseDouble(Ender[0]);
    double endy = Double.parseDouble(Ender[1]);

    //////////////////////////////////////////////////
    // Correct path from the example map:
    // (1,3)  (2,6)  (14,8)  (22,19)  (28,19)  (31,19)  (34,19)
    //////////////////////////////////////////////////

    // set of points to be evaluated, initially only containing start point
    List<Points> openset = new ArrayList<Points>();
    // set of points already evaluated
    List<Points> closedset = new ArrayList<Points>();

    // The initial starting point
    GStartx = Startx;
    GStarty = Starty;

    // G-score is the calculated cost from the start to the current point

    // Calculating F score, which is the distance between the current starting point and the final
    // end point
    double F_Cost = distance(Startx, Starty, endx, endy);

    // initializing variables for each point

    // current x and y location, current "came from" x and y location
    int currX, currY, currCamex, currCamey;

    // current G-Score and F-Score
    double currG, currF;

    double tentGscore, tentFscore;
    openset.add(new Points((int) Startx, (int) Starty, 0, 0, F_Cost, -1, -1));
    boolean dummy = true;

    // while the openset is not empty
    while (openset.size() != 0) {

      // get the next Point to be evaluated in the openset with the lowest f-score

      // filling variables with the information from the point being evaluated
      currX = openset.get(0).XPoint;
      currY = openset.get(0).YPoint;
      currF = openset.get(0).costF;
      currG = openset.get(0).costG;
      currCamex = openset.get(0).camefromx;
      currCamey = openset.get(0).camefromy;
      Startx = currX;
      Starty = currY;

      // If the current point equals the goal point, start constructing a path back to the start
      if (currX == endx && currY == endy) {
        // add the last point to the closed set
        closedset.add(new Points(currX, currY, 0, currG, currF, currCamex, currCamey));
        for (int r = closedset.size() - 1; r >= 0; r--) {

          // Loop from the end to the start of the closed set
          // From the end point, look at the point that was "travelled from" and add that point to
          // the path
          if ((currX == closedset.get(r).XPoint) && (currY == closedset.get(r).YPoint)) {

            completedPath.add(" (" + currX + "," + currY + ") ");

            currX = closedset.get(r).camefromx;
            currY = closedset.get(r).camefromy;
          }
        }

        // Reverse the order from start to finish and print the path
        Collections.reverse(completedPath);
        System.out.print("Best path: ");
        for (String omg : completedPath) {
          // Final, constructed path
          System.out.print(omg);
        }

        // End the algorithm
        break;
      }

      // Check which points can be seen and travelled to from the current point
      List<Points> Seeable = visible(finalPolygons);

      // Before evaluating the current point, remove it from the openset and add it to the closed
      // set
      openset.remove(0);
      closedset.add(new Points(currX, currY, 0, currG, currF, currCamex, currCamey));

      // loop through all of the seeable points from the current point
      for (Points neighbor : Seeable) {
        int wanz = 0;

        // Tentative F-Score = current G Score and the distance between current point and the
        // neighbor point
        tentGscore = currG + neighbor.lineLength;
        tentFscore = tentGscore + distance(neighbor.XPoint, neighbor.YPoint, endx, endy);

        for (int j = 0; j < closedset.size() - 1; j++) {
          // if neighbor point is in closedset and the tentative FScore is >= the neighbor's FScore
          if ((neighbor.XPoint == closedset.get(j).XPoint)
              && (neighbor.YPoint == closedset.get(j).YPoint)) {

            // give the neighbor the F and G score it already has in the closed set
            neighbor.costF = closedset.get(j).costF;
            neighbor.costG = closedset.get(j).costG;
          }
        }

        // if the neighbor point is not in the open set, or the tentative FScore of the current
        // point is less than the FScore of the neighbor point
        if ((!openset.contains(neighbor)) || tentFscore < neighbor.costF) {

          // assign the current point as the "travelled from" point for the neighbor point
          neighbor.camefromx = currX;
          neighbor.camefromy = currY;

          // give the F and G scores of the current point to the neighbor point
          neighbor.costG = tentGscore;
          neighbor.costF = tentFscore;

          // Check to see if the current neighbor is in the open set
          for (int i = 0; i < openset.size() - 1; i++) {
            if ((neighbor.XPoint == openset.get(i).XPoint)
                && (neighbor.YPoint == openset.get(i).YPoint)) {
              wanz++;
            }
          }

          // If not, add to the open set
          if (wanz == 0) {
            openset = addStuff(openset, neighbor);
          }
        }
      }
    }
    return completedPath;
  }
Example #27
0
 @Override // from ICircle
 public boolean contains(IPoint p) {
   double r = radius();
   return Points.distanceSq(x(), y(), p.x(), p.y()) < r * r;
 }
Example #28
0
 public boolean insideStrict(Point p) {
   return Cmp.leq(Points.sqDistance(p, center), rr());
 }
Example #29
0
 @Override // from ICircle
 public boolean contains(double x, double y) {
   double r = radius();
   return Points.distanceSq(x(), y(), x, y) < r * r;
 }
Example #30
0
  public PlayerSpring(Wall w) {
    this.wall = w;
    points = new Points();
    points.add(lh = new XYPoint(-0.5, 2.0));
    points.add(le = new XYPoint(-0.3, 1.7));
    points.add(ls = new XYPoint(-0.2, 1.58));

    points.add(rh = new XYPoint(0.5, 2.0));
    points.add(re = new XYPoint(0.3, 1.7));
    points.add(rs = new XYPoint(0.2, 1.58));

    points.add(n = new XYPoint(0.0, 1.58));
    points.add(p = new XYPoint(0.0, 1.0));

    points.add(rn = new XYPoint(0.2, 0.7));
    points.add(rf = new XYPoint(0.2, 0.2));

    points.add(ln = new XYPoint(-0.2, 0.7));
    points.add(lf = new XYPoint(-0.2, 0.2));

    double k = 0.4;

    springs = new ArrayList<Spring>();

    springs.add(lClav = new Spring(0.2, k, n, ls, points));
    springs.add(lHum = new Spring(0.3, k, ls, le, points));
    springs.add(lRad = new Spring(0.33, k, le, lh, points));

    springs.add(rClav = new Spring(0.2, k, n, rs, points));
    springs.add(rHum = new Spring(0.3, k, rs, re, points));
    springs.add(rRad = new Spring(0.33, k, re, rh, points));

    springs.add(Lum1 = new Spring(0.58, k, n, p, points));
    springs.add(Lum2 = new Spring(0.58, k, p, n, points));

    springs.add(lFem = new Spring(0.44, k, p, ln, points));
    springs.add(lTib = new Spring(0.5, k, ln, lf, points));

    springs.add(rFem = new Spring(0.44, k, p, rn, points));
    springs.add(rTib = new Spring(0.5, k, rn, rf, points));

    joints = new ArrayList<Joint>();
    joints.add(new Joint(Lum2, lClav, Math.PI / 2.0, Math.PI / 2.0));
    joints.add(new Joint(Lum2, rClav, -Math.PI / 2.0, -Math.PI / 2.0));

    joints.add(new Joint(rClav, rHum, -Math.PI / 2.0, Math.PI / 2.0));
    joints.add(new Joint(rHum, rRad, 0.0, Math.PI / 2.0));

    joints.add(new Joint(lClav, lHum, -Math.PI / 2.0, Math.PI / 2.0));
    joints.add(new Joint(lHum, lRad, -Math.PI / 2.0, 0.0));

    joints.add(new Joint(Lum1, rFem, 0.1, 0.4));
    joints.add(new Joint(rFem, rTib, -0.2, 0.1));

    joints.add(new Joint(Lum1, lFem, -0.4, -0.1));
    joints.add(new Joint(lFem, lTib, -0.1, 0.2));

    points.translate(new XYPoint(5.0, 1.0));

    forces = new Points(points.size());
    velocity = new Points(points.size());
    velocity.zero();

    lhf = new XYPoint(0.0, 0.0);
    rhf = new XYPoint(0.0, 0.0);
    lff = new XYPoint(0.0, 0.0);
    rff = new XYPoint(0.0, 0.0);
    bf = new XYPoint(0.0, 0.0);

    leftaction = false;

    for (Spring s : springs) {
      XYPoint p1 = points.get(s.p1index);
      XYPoint p2 = points.get(s.p2index);
      XYPoint dif1 = s.p1distance().scale(0.6);
      XYPoint dif2 = s.p1distance().scale(-0.3);
      p2.translate(dif1);
      p1.translate(dif2);
    }

    for (Joint j : joints) {
      XYPoint v1 = j.s1.vector();
      XYPoint v2 = j.s2.vector();

      double angle = v1.angle(v2);

      if (angle < j.mina) {
        XYPoint v2r = v2.rotate(-(angle - j.mina));
        points.get(j.s2.p2index).set(points.get(j.s2.p1index).add(v2r));
      } else if (angle > j.maxa) {
        XYPoint v2r = v2.rotate((j.maxa - angle));
        points.get(j.s2.p2index).set(points.get(j.s2.p1index).add(v2r));
      }
    }
  }