Ejemplo n.º 1
0
 /* Going to use Heron's Formula to for calculating the distance
  * first we calculate the distance of each of the sides,
  * and use that info to calcualate the height of the triangle, giving us back the
  * distance
  */
 private double calculateDistance(Line l, DoublePoint p) {
   double side1 = l.getStart().distance(l.getEnd());
   double side2 = l.getStart().distance(p);
   double side3 = l.getEnd().distance(p);
   double hS = (side1 + side2 + side3) / 2;
   double triangleArea = Math.sqrt(hS * (hS - side1) * (hS - side2) * (hS - side3));
   double distance = (2 * triangleArea) / side1;
   return distance;
 }
Ejemplo n.º 2
0
 private void moveLine(Line l, DoublePoint latestPoint) {
   DoublePoint origEndPoint = l.getEnd();
   DoublePoint origStartPoint = l.getStart();
   // repaintRegion(origStartPoint, origEndPoint);
   repaint();
   int dx = (int) (latestPoint.getX() - origPoint.getX());
   int dy = (int) (latestPoint.getY() - origPoint.getY());
   origPoint = latestPoint;
   l.moveBy(dx, dy);
   DoublePoint newStartPoint = l.getStart();
   DoublePoint newEndPoint = l.getEnd();
   repaintRegion(newStartPoint, newEndPoint);
   repaint();
 }
Ejemplo n.º 3
0
 public boolean equals(Object o) {
   // order does not matter, as with a vector
   if (o instanceof Line) {
     Line l = (Line) o;
     if (this.getStart().equals(l.getStart()) && this.getEnd().equals(l.getEnd())) {
       return true;
     } else if (this.getEnd().equals(l.getStart()) && this.getStart().equals(l.getEnd())) {
       return true;
     } else {
       return false;
     }
   } else {
     return false;
   }
 }
Ejemplo n.º 4
0
 @Test
 public void create() {
   final Point start = Point.valueOf(5, 6);
   final Point end = Point.valueOf(50, 60);
   final Line sut = Line.valueOf(start, end);
   assertEquals(start, sut.getStart());
   assertEquals(end, sut.getEnd());
 }
Ejemplo n.º 5
0
  public static double interpolateY(Line line, double xValue) {
    // if point1.x() == point2.x(), is a vertical line, will produce an infinity value
    XY point1 = line.getStart();
    XY point2 = line.getEnd();
    double x1 = point1.x();
    double x2 = point2.x();
    double y1 = point1.y();
    double y2 = point2.y();

    return (y2 - y1) / (x2 - x1) * (xValue - x1) + y1;
  }
Ejemplo n.º 6
0
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // If the game is paused we mask the game view
    if (hide) {
      setBackgroundColor(getResources().getColor(R.color.black));
    }
    // Otherwise if the game is pending
    else {

      setBackgroundResource(R.drawable.grid_background);
      // Fill the shapes
      if (mg != null && !mg.getShapes().isEmpty()) {

        for (Map.Entry<Rect, Integer> e : mg.getShapes().entrySet()) {
          fill.setColor(e.getValue());
          canvas.drawRect(e.getKey(), fill);
        }
      }
      // If you lose (there is at least one adjacent shape with the same color)
      if (adjacent != null && !adjacent.isEmpty()) {

        for (Rect rect : adjacent) {
          canvas.drawRect(rect, striped);
        }
      }
      // Stroke
      if (mg != null && !mg.getLines().isEmpty()) {

        for (Line line : mg.getLines()) {
          canvas.drawLine(
              line.getStart().x, line.getStart().y, line.getEnd().x, line.getEnd().y, stroke);
        }
      }
    }
  }
Ejemplo n.º 7
0
 private void addArcs(int divs) {
   double theta = calculateTheta(divs);
   for (int i = 0; i < circles.size() - 1; i++) {
     Line nextLine = circles.get((i + 1) % circles.size());
     DoublePoint start = circles.get(i).getEnd();
     Arc temp =
         new Arc(
             new DoublePoint(0, 0),
             new DoublePoint(getWidth(), getHeight()),
             -90 + (int) (i * theta),
             (int) theta + 5);
     Debug.println(
         start + ", " + nextLine.getEnd() + "start: " + (i * theta) + ", with sweep: " + theta);
     arcs.add(temp);
   }
 }
Ejemplo n.º 8
0
 private void repaintLine(Line l) {
   repaintRegion(l.getStart(), l.getEnd());
 }
Ejemplo n.º 9
0
 private void changeLine(Line l, DoublePoint latestPoint) {
   DoublePoint origEndPoint = l.getEnd();
   repaintRegion(l.getStart(), origEndPoint);
   l.setEndPoint(latestPoint);
   repaintRegion(origEndPoint, l.getEnd());
 }