Exemplo n.º 1
0
 //    int x1, x2, y;
 private void drawLine(int currentY, int index) {
   // добавление рассматриваемых плоскостей
   for (; index < setBorders.size() && setBorders.get(index) >= currentY; index++) {
     changeDrawnSurfacesList(currentY, true);
   }
   // поиск всех точек, пересекающих эту плоскость, и составление из них отрезков
   // поиск точек пересечения между этими отрезками
   findAllIntersections(currentY);
   // сортировка
   pointsList =
       (ArrayList<Point>)
           pointsList
               .stream()
               .sorted((a, b) -> Double.compare(a.getX(), b.getX()))
               .collect(Collectors.toList());
   // отрисовка
   Point last = new Point(0, currentY, 0);
   for (Point p : pointsList) {
     ArrayList<PointEvent> events = listPointsEvent.getEvent((int) p.getX());
     for (PointEvent event : events) {
       if (event.event == PointEventsList.START) {
         drawnSegments.add(event.point.getParent());
       }
     }
     if (drawnSegments.size() > 0) {
       double maxZ = -Double.MAX_VALUE;
       Segment chosen = null;
       for (Segment seg : drawnSegments) {
         double z = seg.getZOnX(p.getX());
         if (z > maxZ) {
           maxZ = z;
           chosen = seg;
         }
       }
       if (chosen != null && maxZ > -Double.MAX_VALUE) {
         context.setStroke(chosen.getSurfaceColor());
         double x1 = canvas.getWidth() / 4 + last.getX() * 2,
             x2 = canvas.getWidth() / 4 + p.getX() * 2,
             y = canvas.getHeight() / 2 + currentY;
         context.strokeLine(x1, y, x2, y);
       }
     }
     // актуализация отрезков
     for (PointEvent event : events) {
       if (event.event == PointEventsList.FINISH) {
         drawnSegments.remove(event.point.getParent());
       }
     }
     last = p;
   }
 }
Exemplo n.º 2
0
  public void initTimer(int currentY, int index) {

    for (; index < setBorders.size() && setBorders.get(index) >= currentY; index++) {
      changeDrawnSurfacesList(currentY, true);
    }
    findAllIntersections(currentY);
    pointsList =
        (ArrayList<Point>)
            pointsList
                .stream()
                .sorted((a, b) -> Double.compare(a.getX(), b.getX()))
                .collect(Collectors.toList());
    Point last = new Point(0, currentY, 0);
    for (Point p : pointsList) {
      ArrayList<PointEvent> events = listPointsEvent.getEvent((int) p.getX());
      for (PointEvent event : events) {
        if (event.event == PointEventsList.START) {
          drawnSegments.add(event.point.getParent());
        }
      }
      if (drawnSegments.size() > 0) {
        double maxZ = -Double.MAX_VALUE;
        Segment chosen = null;
        for (Segment seg : drawnSegments) {
          double z = seg.getZOnX(p.getX());
          if (z > maxZ) {
            maxZ = z;
            chosen = seg;
          }
        }
        if (chosen != null && maxZ > -Double.MAX_VALUE) {
          //                    context.setStroke(chosen.getSurfaceColor());
          double x1 = canvas.getWidth() / 4 + last.getX() * 2,
              x2 = canvas.getWidth() / 4 + p.getX() * 2,
              y = canvas.getHeight() / 2 + currentY;
          Segment segment =
              new Segment(new Point(x1, y, 0), new Point(x2, y, 0), chosen.getSurfaceColor());
          result.add(segment);
          //                    context.strokeLine(x1, y, x2, y);
        }
      }
      // актуализация отрезков
      for (PointEvent event : events) {
        if (event.event == PointEventsList.FINISH) {
          drawnSegments.remove(event.point.getParent());
        }
      }
      last = p;
    }

    AnimationTimer timer =
        new AnimationTimer() {
          @Override
          public void handle(long now) {
            if (indexResult == result.size() - 1) {
              stop();
              return;
            }
            segmentResult = result.get(indexResult++);
            context.setStroke(segmentResult.getSurfaceColor());
            context.strokeLine(
                segmentResult.getStart().getX(),
                segmentResult.getStart().getY(),
                segmentResult.getFinish().getX(),
                segmentResult.getFinish().getY());
          }
        };
    timer.start();
  }