/** * Scale this convex polygon about its centroid. * <p> * The polygon centroid remains unchanged. * </p> * * @param scaleFactor the scale factor to apply to this polygon. A value of {@code 1.0} does * nothing. * @throws OutdatedPolygonException if {@link #update()} has not been called since last time this * polygon's vertices were edited. * @throws EmptyPolygonException if this polygon is empty when calling this method. */ default void scale(double scaleFactor) { scale(getCentroid(), scaleFactor); }
/** * Scale this convex polygon about {@code pointToScaleAbout}. * * @param pointToScaleAbout the center of the scale transformation. Not modified. * * @param scaleFactor the scale factor to apply to this polygon. A value of {@code 1.0} does * nothing. * @throws ReferenceFrameMismatchException if {@code pointToScaleAbout} and {@code this} are not * expressed in the same reference frame. * @see #scale(Point2DReadOnly, double) */ default void scale(FramePoint2DReadOnly pointToScaleAbout, double scaleFactor) { checkReferenceFrameMatch(pointToScaleAbout); ConvexPolygon2DBasics.super.scale(pointToScaleAbout, scaleFactor); }
@Test public void testScale() { double scaleFactor = 2.0; double[][] verticesArray = {{-1.0, 1.0}, {1.0, 1.0}, {1.0, -1.0}, {-1.0, -1.0}}; T polygon = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesArray)); polygon.scale(scaleFactor); Point2DReadOnly oneNext = polygon.getNextVertexCCW(0); //(2.0, -2.0) Point2DReadOnly twoNext = polygon.getNextVertexCCW(1); //(2.0, 2.0) Point2DReadOnly threeNext = polygon.getNextVertexCCW(2); //(-2.0, 2.0) Point2DReadOnly fourNext = polygon.getNextVertexCCW(3); //(-2.0, -2.0) Point2D one = new Point2D(2.0, -2.0); Point2D two = new Point2D(2.0, 2.0); Point2D three = new Point2D(-2.0, 2.0); Point2D four = new Point2D(-2.0, -2.0); EuclidCoreTestTools.assertTuple2DEquals("These should be equal", oneNext, one, EPSILON); EuclidCoreTestTools.assertTuple2DEquals("These should be equal", twoNext, two, EPSILON); EuclidCoreTestTools.assertTuple2DEquals("These should be equal", threeNext, three, EPSILON); EuclidCoreTestTools.assertTuple2DEquals("These should be equal", fourNext, four, EPSILON); }