This commit is contained in:
maverickstuder 2024-03-04 15:18:13 +01:00
parent 72202f63dc
commit f90cb20156
5 changed files with 67 additions and 10 deletions

View File

@ -155,5 +155,13 @@ public class Line extends BoundingBox {
this.setBBox(new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY));
}
public String toString() {
StringBuilder sb = new StringBuilder();
words.forEach(word -> sb.append(word.toString()).append(" "));
return sb.toString().trim();
}
}

View File

@ -39,4 +39,12 @@ public class Zone extends BoundingBox {
this.setBBox(new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY));
}
public String toString() {
StringBuilder sb = new StringBuilder();
lines.forEach(line -> sb.append(line.toString()).append("\n"));
return sb.toString().trim();
}
}

View File

@ -224,20 +224,63 @@ public class ReadingOrderService {
double y1 = Math.max(obj1.getY() + obj1.getHeight(), obj2.getY() + obj2.getHeight());
double dist = ((x1 - x0) * (y1 - y0) - obj1.getArea() - obj2.getArea());
double factor = ((x1 - x0)/x1) / ((y1 - y0)/y1);
double obj1X = obj1.getX();
double obj1CenterX = obj1.getX() + obj1.getWidth() / 2;
double obj1CenterY = obj1.getY() + obj1.getHeight() / 2;
double obj1Y_2 = obj1.getBBox().getMaxY();
double obj1X_2 = obj1.getBBox().getMaxX();
double obj1CenterX = obj1.getBBox().getCenterX();
double obj1CenterY = obj1.getBBox().getCenterY();
double obj2X = obj2.getX();
double obj2CenterX = obj2.getX() + obj2.getWidth() / 2;
double obj2CenterY = obj2.getY() + obj2.getHeight() / 2;
double obj2Y_2 = obj2.getBBox().getMaxY();
double obj2X_2 = obj2.getBBox().getMaxX();
double obj2CenterX = obj2.getBBox().getCenterX();
double obj2CenterY = obj2.getBBox().getCenterY();
double obj1obj2VectorCosineAbsLeft = Math.abs((obj2X - obj1X) / Math.sqrt((obj2X - obj1X) * (obj2X - obj1X) + (obj2CenterY - obj1CenterY) * (obj2CenterY - obj1CenterY)));
double obj1obj2VectorCosineAbsRight = Math.abs((obj2X_2 - obj1X_2) / Math.sqrt((obj2X_2 - obj1X_2) * (obj2X_2 - obj1X_2) + (obj2CenterY - obj1CenterY) * (obj2CenterY - obj1CenterY)));
double obj1obj2VectorCosineAbsCenter = Math.abs((obj2CenterX - obj1CenterX) / Math.sqrt((obj2CenterX - obj1CenterX) * (obj2CenterX - obj1CenterX) + (obj2CenterY - obj1CenterY) * (obj2CenterY - obj1CenterY)));
double cosine = Math.min(obj1obj2VectorCosineAbsLeft, obj1obj2VectorCosineAbsCenter);
double cosine = Math.min(obj1obj2VectorCosineAbsLeft, Math.min(obj1obj2VectorCosineAbsRight, obj1obj2VectorCosineAbsCenter));
final double MAGIC_COEFF = 0.5;
return dist * (MAGIC_COEFF + cosine);
final double MAGIC_COEFF = 0.85;
//return dist * (MAGIC_COEFF + cosine);
return Math.sqrt(Math.pow((obj1X - obj2X), 2) + Math.pow((obj1Y_2 - obj2Y_2) * MAGIC_COEFF, 2));
/**if (Math.abs(obj1CenterX - obj2CenterX) >= Math.abs(obj1CenterY - obj2CenterY)) {
return dist * 2;
} else {
return dist;
}**/
}
private double distanceNew(BoundingBox obj1, BoundingBox obj2) {
if(obj1.getBBox().intersects(obj2.getBBox()))
return -1;
double minX0 = Math.min(obj1.getX(), obj2.getX());
double maxX0 = Math.max(obj1.getX(), obj2.getX());
double minY0 = Math.min(obj1.getY(), obj2.getY());
double maxY0 = Math.max(obj1.getY(), obj2.getY());
double minX1 = Math.min(obj1.getX() + obj1.getWidth(), obj2.getX() + obj2.getWidth());
double maxX1 = Math.max(obj1.getX() + obj1.getWidth(), obj2.getX() + obj2.getWidth());
double minY1 = Math.min(obj1.getY() + obj1.getHeight(), obj2.getY() + obj2.getHeight());
double maxY1 = Math.max(obj1.getY() + obj1.getHeight(), obj2.getY() + obj2.getHeight());
List<Double> xValues = new ArrayList<>(List.of(minX0, maxX0, minX1, maxX1));
Collections.sort(xValues);
List<Double> yValues = new ArrayList<>(List.of(minY0, maxY0, minY1, maxY1));
Collections.sort(yValues);
double yArea = (xValues.get(2) - xValues.get(1)) * (yValues.get(3) - yValues.get(0));
double xArea = (yValues.get(2) - yValues.get(1)) * (xValues.get(3) - xValues.get(0));
return Math.min(10*yArea, xArea);
}
}

View File

@ -25,8 +25,6 @@ public class ViewerDocumentTest extends BuildDocumentTest {
@SneakyThrows
public void testViewerDocument() {
System.out.println("<<<<<<<<<<" + Math.sin(-0) + "aaa " + Math.cos(0) + Math.tan(0));
String fileName = "files/Plenarprotokoll 1 (keine Druchsache!) (1).pdf";
String tmpFileName = "/tmp/" + Path.of(fileName).getFileName() + "_VIEWER.pdf";

View File

@ -48,7 +48,7 @@ class GapAcrossLinesDetectionServiceTest {
@Test
@Disabled
//@Disabled
@SneakyThrows
public void testColumnDetection() {