Sha256: 137833e980eb6b9fb3435faf8654f3b0a0ccaeadddb7540952dc80093473a7ea
Contents?: true
Size: 1.76 KB
Versions: 11
Compression:
Stored size: 1.76 KB
Contents
package toxi.geom; import java.util.ArrayList; import java.util.List; import toxi.math.ScaleMap; /** * A concrete implementation of the abstract {@link GridTesselator} using a grid * in polygon-local coordinate space for generating additional points within a * polygon. The resolution setting of this class defines number of desired grid * points in X & Y direction. E.g. a resolution of 10 means up to 10x10 grid * points are created a within the polygon bounding rect. For smaller polygons, * the resulting triangles will simply be smaller too. This resolution is used * independently on polygon size. Use the {@link GlobalGridTesselator} for an * alternative behavior, resulting in more uniformly sized triangles. * * @see GridTesselator * @see GlobalGridTesselator * @see PolygonTesselator */ public class LocalGridTesselator extends GridTesselator { /** * * @param res */ public LocalGridTesselator(int res) { super(res); } /** * * @param poly * @param bounds * @return */ @Override protected List<Vec2D> createInsidePoints(Polygon2D poly, Rect bounds) { List<Vec2D> points = new ArrayList<>(); int ires = (int) res; ScaleMap xmap = new ScaleMap(0, ires, bounds.getLeft(), bounds.getRight()); ScaleMap ymap = new ScaleMap(0, ires, bounds.getTop(), bounds.getBottom()); for (int y = 0; y < ires; y++) { float yy = (float) ymap.getMappedValueFor(y); for (int x = 0; x < ires; x++) { Vec2D p = new Vec2D((float) xmap.getMappedValueFor(x), yy); if (poly.containsPoint(p)) { points.add(p); } } } return points; } }
Version data entries
11 entries across 11 versions & 1 rubygems