Skip to content

Commit e054c7a

Browse files
committed
Add width and height calculation
DEVSIX-8365
1 parent 7bf6f0d commit e054c7a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/canvas/parser/clipper/ClipperBridge.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ public static boolean addPolylineSubjectToClipper(IClipper clipper, com.itextpdf
261261
return clipper.addPath(new Path(convertToLongPoints(new ArrayList<>(Arrays.asList(lineVertices)))), IClipper.PolyType.SUBJECT, false);
262262
}
263263

264+
/**
265+
* Calculates the width of the rectangle represented by the {@link LongRect} object.
266+
* @param rect the {@link LongRect} object representing the rectangle.
267+
*
268+
* @return the width of the rectangle.
269+
*/
270+
public static float longRectCalculateWidth(LongRect rect) {
271+
return (float) (Math.abs(rect.left - rect.right) / ClipperBridge.floatMultiplier);
272+
}
273+
274+
/**
275+
* Calculates the height of the rectangle represented by the {@link LongRect} object.
276+
* @param rect the {@link LongRect} object representing the rectangle.
277+
*
278+
* @return the height of the rectangle.
279+
*/
280+
public static float longRectCalculateHeight(LongRect rect) {
281+
return (float) (Math.abs(rect.top - rect.bottom) / ClipperBridge.floatMultiplier);
282+
}
283+
264284
static void addContour(com.itextpdf.kernel.geom.Path path, List<Point.LongPoint> contour, boolean close) {
265285
List<com.itextpdf.kernel.geom.Point> floatContour = convertToFloatPoints(contour);
266286
com.itextpdf.kernel.geom.Point point = floatContour.get(0);

kernel/src/test/java/com/itextpdf/kernel/pdf/canvas/parser/clipper/ClipperBridgeTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,19 @@ public void getEndTypeTest() {
106106
Assert.assertEquals(EndType.OPEN_ROUND, ClipperBridge.getEndType(LineCapStyle.ROUND));
107107
}
108108

109+
@Test
110+
public void longRectWidthTest() {
111+
LongRect longRect = new LongRect(14900000000000000L, 21275000000000000L, 71065802001953128L, 71075000000000000L);
112+
Assert.assertEquals(561.658, ClipperBridge.longRectCalculateWidth(longRect), 0.001f);
113+
}
114+
115+
116+
@Test
117+
public void longRectHeightTest() {
118+
LongRect longRect = new LongRect(14900000000000000L, 21275000000000000L, 71065802001953128L, 71075000000000000L);
119+
Assert.assertEquals(498, ClipperBridge.longRectCalculateHeight(longRect), 0.001f);
120+
}
121+
109122
private boolean areShapesEqual(IShape expected, IShape actual) {
110123
if (expected == actual) {
111124
return true;

0 commit comments

Comments
 (0)