Exemple #1
0
 /**
  * Simple polygon intersection test.
  *
  * <p>FIXME: while this is found on some web pages as "solution" and satisfies or needs, it
  * clearly is not correct; not even for convex polygons: Consider a cross where the two bars are
  * made out of four vertices each. No vertex is inside the other polygon, yet they intersect.
  *
  * <p>I knew this before writing this code, but this O(n) code was the simplest thing to come up
  * with, and it would work for our current data sets. A way to fix this is to augment it with the
  * obvious O(n*n) segment intersection test. (Note that you will still need to test for point
  * containment, since the whole polygon could be contained in the other!)
  *
  * @param other Other polygon
  * @return True when the polygons intersect
  */
 public boolean intersects2DIncomplete(Polygon other) {
   assert (this.getDimensionality() == 2);
   assert (other.getDimensionality() == 2);
   for (Vector v : this.points) {
     if (other.containsPoint2D(v)) {
       return true;
     }
   }
   for (Vector v : other.points) {
     if (this.containsPoint2D(v)) {
       return true;
     }
   }
   return false;
 }
    @Override
    public void fullRedraw() {
      setupCanvas();
      final StyleLibrary style = context.getStyleLibrary();
      CSSClass css = new CSSClass(svgp, POLYS);
      // TODO: separate fill and line colors?
      css.setStatement(
          SVGConstants.CSS_STROKE_WIDTH_PROPERTY, style.getLineWidth(StyleLibrary.POLYGONS));
      css.setStatement(SVGConstants.CSS_STROKE_PROPERTY, style.getColor(StyleLibrary.POLYGONS));
      css.setStatement(SVGConstants.CSS_FILL_PROPERTY, SVGConstants.CSS_NONE_VALUE);
      svgp.addCSSClassOrLogError(css);
      svgp.updateStyleElement();

      // draw data
      for (DBIDIter iditer = rep.iterDBIDs(); iditer.valid(); iditer.advance()) {
        try {
          PolygonsObject poly = rep.get(iditer);
          if (poly == null) {
            continue;
          }
          SVGPath path = new SVGPath();
          for (Polygon ppoly : poly.getPolygons()) {
            Vector first = ppoly.get(0);
            double[] f = proj.fastProjectDataToRenderSpace(first.getArrayRef());
            path.moveTo(f[0], f[1]);
            for (ArrayListIter<Vector> it = ppoly.iter(); it.valid(); it.advance()) {
              if (it.getOffset() == 0) {
                continue;
              }
              double[] p = proj.fastProjectDataToRenderSpace(it.get().getArrayRef());
              path.drawTo(p[0], p[1]);
            }
            // close path.
            path.drawTo(f[0], f[1]);
          }
          Element e = path.makeElement(svgp);
          SVGUtil.addCSSClass(e, POLYS);
          layer.appendChild(e);
        } catch (ObjectNotFoundException e) {
          // ignore.
        }
      }
    }