コード例 #1
0
ファイル: ConvexZone.java プロジェクト: zukov/Jpicedt
 /**
  * Renvoie une <code>String</code> décrivant <code>this</code> à des fin de débogage.
  *
  * @return une valeur <code>String</code> décrivant <code>this</code>.
  */
 public String toString() {
   StringBuffer ret = new StringBuffer();
   ret.append("[convexPolygonalZone=");
   ret.append(convexPolygonalZone.toString());
   ret.append("]");
   return ret.toString();
 }
コード例 #2
0
ファイル: ConvexZone.java プロジェクト: zukov/Jpicedt
 public boolean containsPoint(PicPoint pt) {
   return convexPolygonalZone.contains(pt);
 }
コード例 #3
0
ファイル: ConvexZone.java プロジェクト: zukov/Jpicedt
  /**
   * Le méthode <code>createShape</code> crée la forme qui sert à visualiser le contour de la zone
   * convexe.
   */
  public void createShape(Rectangle2D allocation) {
    if (boundaryPath0 != null) return;

    if (boundary == null) boundary = convexPolygonalZone.getBoundary();

    if (DEBUG)
      debug(
          "this = "
              + toString()
              + "\n\tboundary = "
              + boundary.toString()
              + "\n\tallocation="
              + allocation.toString());

    if (boundaryPath0 == null) boundaryPath0 = new GeneralPath();
    boundaryPath0.reset();
    if (boundary.subdivisionPoints.size() != 0) {
      // la frontière n'est pas une droite, mais comprend au moins un
      // point de sousdivision.
      boundaryPath1 = null;
      allocationIntersectionPath1 = null;

      PicPoint firstPointInInfinity = null;
      PicPoint secondPointInInfinity = null;
      PicPoint anglePoint = null;
      int i;
      if (boundary.isClosed()) {
        // pas de points à l'infini
        allocationIntersectionPath0 = null;
        allocationIntersectionPath1 = null;

        bounds.setFrameFromDiagonal(
            boundary.subdivisionPoints.get(0), boundary.subdivisionPoints.get(1));
        i = 0;
      } else {
        PointsInInfinity pointsInInfinity = new PointsInInfinity(allocation);
        firstPointInInfinity = pointsInInfinity.get(boundary.halfPlanes.getFirst(), +1);
        boundaryPath0.moveTo(firstPointInInfinity.getX(), firstPointInInfinity.getY());
        secondPointInInfinity = pointsInInfinity.get(boundary.halfPlanes.getLast(), -1);
        anglePoint = pointsInInfinity.getAnglePoint();
        bounds.setFrameFromDiagonal(firstPointInInfinity, secondPointInInfinity);
        i = 1;
      }
      for (PicPoint pt : boundary.subdivisionPoints) {
        if (i == 0) {
          boundaryPath0.moveTo(pt.getX(), pt.getY());
        } else {
          boundaryPath0.lineTo(pt.getX(), pt.getY());
          if (i > 1) bounds.add(pt);
        }
        ++i;
      }
      if (!boundary.isClosed()) {
        boundaryPath0.lineTo(secondPointInInfinity.getX(), secondPointInInfinity.getY());
        if (allocationIntersectionPath0 == null) allocationIntersectionPath0 = new GeneralPath();
        allocationIntersectionPath1 = null;
        allocationIntersectionPath0.reset();
        allocationIntersectionPath0.moveTo(
            firstPointInInfinity.getX(), firstPointInInfinity.getY());
        if (anglePoint != null)
          allocationIntersectionPath0.lineTo(anglePoint.getX(), anglePoint.getY());
        allocationIntersectionPath0.lineTo(
            secondPointInInfinity.getX(), secondPointInInfinity.getY());
      } else boundaryPath0.closePath();
      if (DEBUG) debug("boundaryPath0 = " + boundaryPath0.toString());
    } else if (boundary.halfPlanes.size() > 0) {
      // ici on n'a pas de point de sous-division, donc la zone convexe
      // est soit une bande, soit un demi-plan.
      PointsInInfinity pointsInInfinity0 = new PointsInInfinity(allocation);
      PicPoint firstPointInInfinity0 = pointsInInfinity0.get(boundary.halfPlanes.getFirst(), +1);
      PicPoint secondPointInInfinity0 = pointsInInfinity0.get(boundary.halfPlanes.getFirst(), -1);
      if (boundaryPath0 == null) boundaryPath0 = new GeneralPath();
      boundaryPath0.reset();
      boundaryPath0.moveTo(firstPointInInfinity0.getX(), firstPointInInfinity0.getY());
      boundaryPath0.lineTo(secondPointInInfinity0.getX(), secondPointInInfinity0.getY());

      if (boundary.halfPlanes.size() > 1) {
        // la zone convexe est une bande
        if (boundaryPath1 == null) boundaryPath1 = new GeneralPath();
        boundaryPath1.reset();
        boundaryPath1.moveTo(firstPointInInfinity0.getX(), firstPointInInfinity0.getY());
        PointsInInfinity pointsInInfinity1 = new PointsInInfinity(pointsInInfinity0);

        // Astuce : on prend le complémentaire de l'autre demi-plan de
        // sorte que les points d'angle tournent dans le même sens.
        ConvexPolygonalZone.HalfPlane complementLastHp =
            boundary.halfPlanes.getLast().dirCInverse();

        PicPoint firstPointInInfinity1 = pointsInInfinity1.get(complementLastHp, +1);
        PicPoint secondPointInInfinity1 = pointsInInfinity1.get(complementLastHp, -1);

        /*
         first0  first1	   (0) := boundaryPath0
          x	  (1) x	       (1) := allocationIntersectionPath0
          |		  |	   	   (2) := boundaryPath1
         	   (0)|>   	  |>   	   (3) :=  allocationIntersectionPath1
          |		  |(2)
          x	 (3)  x
        second0   second1

         */
        if (boundaryPath1 == null) boundaryPath1 = new GeneralPath();
        boundaryPath1.reset();
        // on fait trace de `second' vers `first' parce que on a pris
        // le demi plan complémentaire, donc l'ordre est inversé si on
        // veut continuer à tourner dans le même sens.
        boundaryPath1.moveTo(secondPointInInfinity1.getX(), secondPointInInfinity1.getY());
        boundaryPath1.lineTo(firstPointInInfinity1.getX(), firstPointInInfinity1.getY());

        if (allocationIntersectionPath0 == null) allocationIntersectionPath0 = new GeneralPath();
        allocationIntersectionPath0.reset();
        allocationIntersectionPath0.moveTo(
            firstPointInInfinity0.getX(), firstPointInInfinity0.getY());

        if (allocationIntersectionPath1 == null) allocationIntersectionPath1 = new GeneralPath();
        allocationIntersectionPath1.reset();
        // idem, ici il faut partir de `second' et non de `first'
        // toujours pourn la même raison qu'on a pris le demi-plan
        // complémentaire.
        allocationIntersectionPath1.moveTo(
            secondPointInInfinity1.getX(), secondPointInInfinity1.getY());

        PicPoint anglePoint0, anglePoint1;

        anglePoint1 = pointsInInfinity1.getAnglePoint();
        while ((anglePoint0 = pointsInInfinity0.getAnglePoint()) != null) {
          if (anglePoint1 != null && anglePoint0.equals(anglePoint1)) break;
          allocationIntersectionPath0.lineTo(anglePoint0.getX(), anglePoint0.getY());
        }
        allocationIntersectionPath0.lineTo(
            firstPointInInfinity1.getX(), firstPointInInfinity1.getY());

        if (anglePoint1 != null && anglePoint0 != null) {
          for (; ; ) {
            anglePoint0 = pointsInInfinity0.getAnglePoint();
            anglePoint1 = pointsInInfinity1.getAnglePoint();
            if (anglePoint1 == null) break;
            if (anglePoint0 == null) break;
            if (!anglePoint0.equals(anglePoint1)) break;
          }
          while (anglePoint0 != null) {
            allocationIntersectionPath1.lineTo(anglePoint0.getX(), anglePoint0.getY());
            anglePoint0 = pointsInInfinity0.getAnglePoint();
          }
        }

        allocationIntersectionPath1.lineTo(
            secondPointInInfinity0.getX(), secondPointInInfinity0.getY());
      } else {
        // la zone convexe est un demi-plan
        boundaryPath1 = null;
        allocationIntersectionPath1 = null;
        if (allocationIntersectionPath0 == null) allocationIntersectionPath0 = new GeneralPath();
        allocationIntersectionPath0.moveTo(
            firstPointInInfinity0.getX(), firstPointInInfinity0.getY());
        PicPoint anglePoint;
        while ((anglePoint = pointsInInfinity0.getAnglePoint()) != null) {
          allocationIntersectionPath0.lineTo(anglePoint.getX(), anglePoint.getY());
        }
        allocationIntersectionPath0.lineTo(
            secondPointInInfinity0.getX(), secondPointInInfinity0.getY());
      }
    }
  }
コード例 #4
0
ファイル: ConvexZone.java プロジェクト: zukov/Jpicedt
 public ConvexZone clone() {
   return new ConvexZone(convexPolygonalZone.clone(), canvas);
 }