11package com .mindee .parsing .custom .lineitems ;
22
3+ import com .mindee .geometry .MinMax ;
34import com .mindee .geometry .PolygonUtils ;
45import com .mindee .parsing .custom .ListField ;
56import com .mindee .parsing .custom .ListFieldValue ;
@@ -20,42 +21,41 @@ private LineItemsGenerator() {
2021 /**
2122 * WARNING: This feature is experimental!
2223 * Results may not always work as intended.
23- * Don't use unless you know what you're doing ;-)
2424 */
2525 public static LineItems generate (
2626 List <String > fieldNames ,
2727 Map <String , ListField > fields ,
2828 Anchor anchor
2929 ) {
30-
3130 Map <String , ListField > fieldsToTransformIntoLines = fields .entrySet ()
3231 .stream ()
3332 .filter (field -> fieldNames .contains (field .getKey ()))
3433 .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
3534
3635 List <Line > lines = populateLines (
3736 fieldsToTransformIntoLines ,
38- new ArrayList <>(LineGenerator .prepareLines (fieldsToTransformIntoLines , anchor ))
37+ new ArrayList <>(LineGenerator .prepareLines (fieldsToTransformIntoLines , anchor )),
38+ anchor .getTolerance ()
3939 );
4040
4141 return new LineItems (lines );
4242 }
4343
4444 private static List <Line > populateLines (
4545 Map <String , ListField > fields ,
46- List <Line > lines
46+ List <Line > lines ,
47+ double heightLineTolerance
4748 ) {
48-
4949 List <Line > populatedLines = new ArrayList <>();
5050
5151 for (Line currentLine : lines ) {
5252 for (Map .Entry <String , ListField > field : fields .entrySet ()) {
5353 for (ListFieldValue listFieldValue : field .getValue ().getValues ()) {
54- double minYCurrentValue = PolygonUtils .getMinYCoordinate (listFieldValue .getPolygon ());
54+ MinMax minMaxY = PolygonUtils .getMinMaxY (listFieldValue .getPolygon (). getCoordinates ());
5555
5656 if (
57- minYCurrentValue < currentLine .getBbox ().getMaxY ()
58- && minYCurrentValue >= currentLine .getBbox ().getMinY ()
57+ Math . abs ( minMaxY . getMax () - currentLine .getBbox ().getMaxY ()) <= heightLineTolerance
58+ && Math . abs ( minMaxY . getMin () - currentLine .getBbox ().getMinY ()) <= heightLineTolerance
5959 ) {
6060 currentLine .addField (field .getKey (), listFieldValue );
6161 }
0 commit comments