summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/ugraphic/UPolygon.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/sourceforge/plantuml/ugraphic/UPolygon.java')
-rw-r--r--src/net/sourceforge/plantuml/ugraphic/UPolygon.java130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/net/sourceforge/plantuml/ugraphic/UPolygon.java b/src/net/sourceforge/plantuml/ugraphic/UPolygon.java
new file mode 100644
index 0000000..2cfdf0d
--- /dev/null
+++ b/src/net/sourceforge/plantuml/ugraphic/UPolygon.java
@@ -0,0 +1,130 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.ugraphic;
+
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.List;
+
+public class UPolygon extends AbstractShadowable {
+
+ private final List<Point2D.Double> all = new ArrayList<Point2D.Double>();
+
+ private MinMax minmax = MinMax.getEmpty(false);
+
+ public UPolygon() {
+ }
+
+ public UPolygon(List<Point2D.Double> points) {
+ all.addAll(points);
+ for (Point2D.Double pt : all) {
+ manageMinMax(pt.getX(), pt.getY());
+ }
+ }
+
+ public void addPoint(double x, double y) {
+ all.add(new Point2D.Double(x, y));
+ manageMinMax(x, y);
+ }
+
+ private void manageMinMax(double x, double y) {
+ minmax = minmax.addPoint(x, y);
+ }
+
+ public List<Point2D.Double> getPoints() {
+ return all;
+ }
+
+ public UPolygon translate(double dx, double dy) {
+ final UPolygon result = new UPolygon();
+ for (Point2D.Double pt : all) {
+ result.addPoint(pt.x + dx, pt.y + dy);
+ }
+ return result;
+ }
+
+ public void rotate(double theta) {
+ final AffineTransform rotate = AffineTransform.getRotateInstance(theta);
+ for (Point2D.Double pt : all) {
+ rotate.transform(pt, pt);
+ }
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() + " " + all;
+ }
+
+ public double getHeight() {
+ return minmax.getHeight();
+ }
+
+ public double getWidth() {
+ return minmax.getWidth();
+ }
+
+ public double getMinX() {
+ return minmax.getMinX();
+ }
+
+ public double getMinY() {
+ return minmax.getMinY();
+ }
+
+ public double getMaxX() {
+ return minmax.getMaxX();
+
+ }
+
+ public double getMaxY() {
+ return minmax.getMaxY();
+ }
+
+ public MinMax getMinMax() {
+ return minmax;
+ }
+
+ public double[] getPointArray(double x, double y) {
+ final double points[] = new double[getPoints().size() * 2];
+ int i = 0;
+
+ for (Point2D pt : getPoints()) {
+ points[i++] = pt.getX() + x;
+ points[i++] = pt.getY() + y;
+ }
+ return points;
+ }
+}