Skip to content

Commit e83df62

Browse files
SnipxiText-CI
authored andcommitted
Add convenience methods to increase and decrease widths of rectangle in chain
1 parent f895f39 commit e83df62

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

kernel/src/main/java/com/itextpdf/kernel/geom/Rectangle.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ This file is part of the iText (R) project.
5858
*/
5959
public class Rectangle implements Cloneable, Serializable {
6060

61-
private static final long serialVersionUID = 8025677415569233446L;
61+
static float EPS = 1e-4f;
6262

63-
private static float EPS = 1e-4f;
63+
private static final long serialVersionUID = 8025677415569233446L;
6464

6565
protected float x;
6666
protected float y;
@@ -415,6 +415,28 @@ public Rectangle decreaseHeight(float extra) {
415415
return this;
416416
}
417417

418+
/**
419+
* Increases the width of rectangle by the given value. May be used in chain.
420+
*
421+
* @param extra the value of the extra wudth to be added.
422+
* @return this {@link Rectangle} instance.
423+
*/
424+
public Rectangle increaseWidth(float extra) {
425+
this.width += extra;
426+
return this;
427+
}
428+
429+
/**
430+
* Decreases the width of rectangle by the given value. May be used in chain.
431+
*
432+
* @param extra the value of the extra width to be subtracted.
433+
* @return this {@link Rectangle} instance.
434+
*/
435+
public Rectangle decreaseWidth(float extra) {
436+
this.width -= extra;
437+
return this;
438+
}
439+
418440
/**
419441
* Gets the X coordinate of the left edge of the rectangle. Same as: {@code getX()}.
420442
*

kernel/src/test/java/com/itextpdf/kernel/geom/RectangleTest.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ This file is part of the iText (R) project.
4949
import com.itextpdf.kernel.pdf.PdfWriter;
5050
import com.itextpdf.test.ExtendedITextTest;
5151
import com.itextpdf.test.annotations.type.UnitTest;
52-
import org.junit.Assert;
53-
import org.junit.Test;
54-
import org.junit.experimental.categories.Category;
5552

5653
import java.io.ByteArrayOutputStream;
5754
import java.util.ArrayList;
5855
import java.util.Arrays;
5956
import java.util.List;
57+
import org.junit.Assert;
58+
import org.junit.Test;
59+
import org.junit.experimental.categories.Category;
6060

6161
@Category(UnitTest.class)
6262
public class RectangleTest extends ExtendedITextTest {
@@ -644,4 +644,18 @@ public void cloneTest() {
644644
Assert.assertEquals(PageSize.class, copyAsPageSize.getClass());
645645
Assert.assertEquals(PageSize.class, copyAsRectangle.getClass());
646646
}
647+
648+
@Test
649+
public void decreaseWidthTest() {
650+
Rectangle rectangle = new Rectangle(100, 200);
651+
rectangle.decreaseWidth(10);
652+
Assert.assertEquals(90, rectangle.getWidth(), Rectangle.EPS);
653+
}
654+
655+
@Test
656+
public void increaseWidthTest() {
657+
Rectangle rectangle = new Rectangle(100, 200);
658+
rectangle.increaseWidth(10);
659+
Assert.assertEquals(110, rectangle.getWidth(), Rectangle.EPS);
660+
}
647661
}

0 commit comments

Comments
 (0)