Beispiel #1
0
          public Value eval(RCvalue args) throws EvalException {
            if ((args.size() < 0) || (3 < args.size()))
              throw new EvalException("usage: reduce(polygon, [errtol,[edgeReducible] ] ])");
            if (!(args.value(0) instanceof PolygonValue))
              throw new EvalException("reduce: first operand must be a polygon");

            double errtol = defaultErrtol;
            if (args.size() >= 2) { // get error tolerance
              if (!(args.value(1) instanceof DoubleValue))
                throw new EvalException("reduce: second operand must be an integer");
              errtol = ((DoubleValue) (args.value(1))).value();
            }
            boolean edgeReducible = true;
            if (args.size() >= 3) {
              double temp = ((DoubleValue) (args.value(2))).value();
              edgeReducible = (temp > 0); // temp = 1, edge reducible, otherwise, not
            }

            Polygon.EndCondition ec = new Polygon.CostEndCondition(errtol);
            if (errtol >= 3) {
              int maxV = (int) Math.round(errtol);
              ec = new Polygon.DegreeEndCondition(maxV);
            }
            PolygonValue p = (PolygonValue) (args.value(0));
            Polygon poly = p.polygon();
            if (poly instanceof ConvexPolygon) { // NOTE: connection for reduce
              if (edgeReducible) return new PolygonValue(((ConvexPolygon) poly).reduce(ec));
              else return p; // can't reduce because convex polygon can only reduce edge
            } else {
              return new PolygonValue(poly.reduce(ec, true, edgeReducible));
            }
          }