PRImA-Research-Lab / prima-core-libs

Core libraries by the PRImA Research Lab
Apache License 2.0
16 stars 15 forks source link

Calculation of a rectangles height and width #2

Closed maxnth closed 4 years ago

maxnth commented 4 years ago

I stumbled upon the following code regarding the calculation of height and width for rectangle:

https://github.com/PRImA-Research-Lab/prima-core-libs/blob/d95dc0b6bcc446b38249b844c44031308c0a1e28/java/PrimaMaths/src/org/primaresearch/maths/geometry/Rect.java#L49-L54

Is there any specific reason for adding the constant factor of 1 to the calculated height/width? When converting (for example) PAGEXML to ALTO the calculated width/height of TextBlocks is always one pixel too big because of this.

chris1010010 commented 4 years ago

The interpretation of a rectangle in PAGE is that both the left and right border belong to the rectangle (same with top and bottom of course). That means if a rectangle spans from left=5 to right=8, for example, then you have: 5,6,7,8 = 4 pixels. This equals 8-5+1

bertsky commented 4 years ago

Related: https://github.com/PRImA-Research-Lab/PAGE-XML/issues/23#issuecomment-627170818