コンストラクタに頂点を与えて図形を作るPolygon2D
コンストラクタに頂点を与えて図形を作るPolygon2D
package com.tatesuke.physicsdraw.base; import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.GeneralPath; import java.awt.geom.PathIterator; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; public class Polygon2D implements Shape { private GeneralPath path = new GeneralPath(); public Polygon2D(Point2D... point) { path.moveTo(point[0].getX(), point[0].getY()); for (int i=1; i<point.length; i++) { path.lineTo(point[i].getX(), point[i].getY()); } path.lineTo(point[0].getX(), point[0].getY()); } @Override public boolean contains(Point2D p) { return path.contains(p); } @Override public boolean contains(Rectangle2D r) { return path.contains(r); } @Override public boolean contains(double x, double y) { return path.contains(x, y); } @Override public boolean contains(double arg0, double arg1, double arg2, double arg3) { return contains(arg0, arg1, arg2, arg3); } @Override public Rectangle getBounds() { return path.getBounds(); } @Override public Rectangle2D getBounds2D() { return path.getBounds2D(); } @Override public PathIterator getPathIterator(AffineTransform arg0) { return path.getPathIterator(arg0); } @Override public PathIterator getPathIterator(AffineTransform at, double flatness) { return path.getPathIterator(at, flatness); } @Override public boolean intersects(Rectangle2D r) { return path.intersects(r); } @Override public boolean intersects(double x, double y, double w, double h) { return path.intersects(x, y, w, h); } }