/** * The interval value of a box (analagous to point) * * @param b * @return value of a box */ public RrInterval value(RrRectangle b) { RrInterval result; switch (op) { case LEAF: result = hp.value(b); break; case NULL: result = new RrInterval(1, 1.01); // Is this clever? Or dumb? break; case UNIVERSE: result = new RrInterval(-1.01, -1); // Ditto. break; case UNION: result = RrInterval.min(c1.value(b), c2.value(b)); break; case INTERSECTION: result = RrInterval.max(c1.value(b), c2.value(b)); break; default: Debug.e("value(RrBox): invalid operator."); result = new RrInterval(); } return result; }
/** * Prune the set to a box * * @param b * @return pruned box as new CSG object */ public RrCSG prune(RrRectangle b) { RrCSG result = this; switch (op) { case LEAF: RrInterval i = hp.value(b); if (i.empty()) Debug.e("RrCSG.prune(RrBox): empty interval!"); else if (i.neg()) result = universe(); else if (i.pos()) result = nothing(); break; case NULL: case UNIVERSE: break; case UNION: result = union(c1.prune(b), c2.prune(b)); break; case INTERSECTION: result = intersection(c1.prune(b), c2.prune(b)); break; default: Debug.e("RrCSG.prune(RrBox): dud op value!"); } return result; }
/** * "Potential" value of a point; i.e. a membership test -ve means inside; 0 means on the surface; * +ve means outside * * @param p * @return potential value of a point */ public double value(Rr2Point p) { double result = 1; // RrCSG c = leaf(p); switch (op) { case LEAF: result = hp.value(p); break; case NULL: result = 1; break; case UNIVERSE: result = -1; break; case UNION: result = Math.min(c1.value(p), c2.value(p)); break; case INTERSECTION: result = Math.max(c1.value(p), c2.value(p)); break; default: Debug.e("RrCSG.value(): dud operator."); } return result; }