Beispiel #1
0
  /**
   * compare this to another Drawable3D with picking
   *
   * @param d the other Drawable3D
   * @param checkPickOrder say if the comparison has to look to pick order
   * @return 1 if this is in front, 0 if equality, -1 either
   */
  public int comparePickingTo(Drawable3D d, boolean checkPickOrder) {

    // check if one is transparent and the other not
    if ((!this.isTransparent()) && (d.isTransparent())) return -1;
    if ((this.isTransparent()) && (!d.isTransparent())) return 1;

    // check if the two objects are "mixed"
    if ((this.zPickMin - d.zPickMin) * (this.zPickMax - d.zPickMax) < EPSILON_Z) {

      if (DEBUG) {
        DecimalFormat df = new DecimalFormat("0.000000000");
        Application.debug(
            "mixed :\n"
                + "zMin= "
                + df.format(this.zPickMin)
                + " | zMax= "
                + df.format(this.zPickMax)
                + " ("
                + this.getGeoElement().getLabel()
                + ")\n"
                + "zMin= "
                + df.format(d.zPickMin)
                + " | zMax= "
                + df.format(d.zPickMax)
                + " ("
                + d.getGeoElement().getLabel()
                + ")\n");
      }

      if (checkPickOrder) {
        if (this.getPickOrder() < d.getPickOrder()) return -1;
        if (this.getPickOrder() > d.getPickOrder()) return 1;
      }

      // if both are points, check if one is on a path and the other not
      if (this.getGeoElement().isGeoPoint() && d.getGeoElement().isGeoPoint()) {
        if ((((GeoPointND) this.getGeoElement()).hasPath())
            && (!((GeoPointND) d.getGeoElement()).hasPath())) return -1;
        if ((!((GeoPointND) this.getGeoElement()).hasPath())
            && (((GeoPointND) d.getGeoElement()).hasPath())) return 1;
      }

      // smaller object is more likely to be picked
      // Note: all objects that are not yet have defined a measure have a default measure = 0
      // so that they are not affected by this comparison.
      if (Kernel.isGreater(d.getGeoElement().getMeasure(), this.getGeoElement().getMeasure()))
        return -1;
      if (Kernel.isGreater(this.getGeoElement().getMeasure(), d.getGeoElement().getMeasure()))
        return 1;

      // check if one is the child of the other
      if (this.getGeoElement().isChildOf(d.getGeoElement())) return -1;
      if (d.getGeoElement().isChildOf(d.getGeoElement())) return 1;
    }

    // finally check if one is before the other
    if (this.zPickMin < d.zPickMin) return -1;
    if (this.zPickMin > d.zPickMin) return 1;

    // says that the two objects are equal for the comparator
    if (DEBUG) {
      DecimalFormat df = new DecimalFormat("0.000000000");
      Application.debug(
          "equality :\n"
              + "zMin= "
              + df.format(this.zPickMin)
              + " | zMax= "
              + df.format(this.zPickMax)
              + " ("
              + this.getGeoElement().getLabel()
              + ")\n"
              + "zMin= "
              + df.format(d.zPickMin)
              + " | zMax= "
              + df.format(d.zPickMax)
              + " ("
              + d.getGeoElement().getLabel()
              + ")\n");
    }
    return 0;
  }