Polygon implements Shape { public boolean calculateIsConvex() { int size = points.size(); for (int i = 0; i < size; i++) { Vector3 point1 = getPoint(i % size); Vector3 point2 = getPoint((i + 1) % size); Vector3 point3 = getPoint((i + 2) % size); int relCCW = point2.relCCW(point1, point3); if ((counterClockWise && relCCW > 0) || (!counterClockWise && relCCW < 0)) { convex = false; return convex; } } convex = true; return convex; } Polygon(int index, List<Vector3> points, int[] vectorIndexs);  Polygon(int index, List<Vector3> points, int[] vectorIndexs,boolean initCalculate);  Polygon(int index, Vector3... point);  Polygon(List<Vector3> points); void calculateCenter(); void calculateRadius(); void calculateArea(); float getAndCalcSignedArea(); boolean calculateIsConvex(); float getArea(); int getIndex(); Vector3 getPoint(int i); boolean isInnerPoint(Vector3 point); boolean isOnEdge(Vector3 point); boolean contains(Polygon polygon); boolean contains(Vector3 p); boolean intersectsEdge(Polygon polygon); @Override String toString(); @Override Rectangle getBounds(); @Override Rectangle2D getBounds2D(); @Override boolean contains(double x, double z); @Override boolean contains(Point2D p); @Override boolean intersects(double x, double y, double w, double h); @Override boolean intersects(Rectangle2D r); @Override boolean contains(double x, double y, double w, double h); @Override boolean contains(Rectangle2D r); @Override PathIterator getPathIterator(AffineTransform at); @Override PathIterator getPathIterator(AffineTransform at, double flatness); String print(); public int index; public List<Vector3> points; public float y; public Vector3 center; public float area; public boolean counterClockWise; public boolean convex; public float radius; public float radiusSq; public int[] vectorIndexs; transient List<Connection<Polygon>> connections; public List<Vector3> randomPoints; }
@Test public void testIsConvexPolygon() { Polygon polygon = new Polygon(1, new Vector3(0, 0), new Vector3(0, 1), new Vector3(1, 0)); Assert.assertTrue(polygon.calculateIsConvex()); Polygon polygon2 = new Polygon(1, new Vector3(0, 0), new Vector3(0, 1), new Vector3(1, 1), new Vector3(1, 0), new Vector3(0.5f, 0.5f)); Assert.assertFalse(polygon2.calculateIsConvex()); Polygon polygon3 = new Polygon(1, new Vector3(0, 0), new Vector3(0, 1), new Vector3(1, 1), new Vector3(1, 0)); Assert.assertTrue(polygon3.calculateIsConvex()); }