예제 #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));
            }
          }
예제 #2
0
 public Value eval(RCvalue args) throws EvalException {
   if (args.size() != 1) throw new EvalException("usage: hull(polygon)");
   if (!(args.value(0) instanceof PolygonValue))
     throw new EvalException("hull: argument must be a polygon");
   PolygonValue pv = (PolygonValue) (args.value(0));
   Polygon poly = pv.polygon();
   return new PolygonValue(poly.convexHull()); // NOTE: connection for convex hull
 }
예제 #3
0
 public Value eval(RCvalue args) throws EvalException {
   Polygon[] polys = new Polygon[args.size() - 1];
   for (int i = 0; i < args.size() - 1; i++) {
     PolygonValue pv = (PolygonValue) args.value(i);
     polys[i] = pv.polygon();
   }
   PolygonValue pv = (PolygonValue) args.value(args.size() - 1); // the last polygon
   return new PolygonValue(pv.polygon().union(polys));
 }
예제 #4
0
 public Value eval(RCvalue args) throws EvalException {
   if (args.size() != 2) throw new EvalException("usage: reduce(polygon, errtol])");
   PolygonValue pv1 = (PolygonValue) args.value(0);
   PolygonValue pv2 = (PolygonValue) args.value(1);
   boolean isContain = pv1.polygon().contains(pv2.polygon());
   double contain = 0;
   if (isContain) {
     contain = 1; // we don't have a boolean factory now.
   }
   return ValueFactory.create(contain);
 }