mozman / ezdxf

Python interface to DXF
https://ezdxf.mozman.at
MIT License
937 stars 191 forks source link

MIN_HATCH_LINE_DISTANCE too large for certain DXF files #929

Closed quipo closed 1 year ago

quipo commented 1 year ago

Describe the bug We encountered some DXF files that have a minimum hatching line distance that is smaller than the minimum allowed in the library. Unfortunately I can't share the DXF file, but I tried reading the file locally and it works fine with this patch against ezdxf 1.1.0:

--- render/hatching.py  2023-09-13 18:50:40.193582134 +0000
+++ render/hatching.py.2    2023-09-13 18:59:45.171383176 +0000
@@ -30,7 +30,7 @@
 if TYPE_CHECKING:
     from ezdxf.entities.polygon import DXFPolygon

-MIN_HATCH_LINE_DISTANCE = 1e-4  # ??? what's a good choice
+MIN_HATCH_LINE_DISTANCE = 1e-8  # ??? what's a good choice
 NONE_VEC2 = Vec2(math.nan, math.nan)
 KEY_NDIGITS = 4
 SORT_NDIGITS = 10

(alternatively, can it be configured via the API?)

We also had this other patch lying around, which used to fix another issue we had, in case it makes sense to apply it:

--- proxygraphic.py 2023-09-13 18:39:33.238367076 +0000
+++ proxygraphic.py.2   2023-09-13 18:47:23.549997247 +0000
@@ -562,6 +562,10 @@
         if flag & 512:  # todo: is this correct? not documented by the ODA DWG ref.
             is_closed = True
         num_points = bs.read_bit_long()
+
+        if num_points <= 0:
+            return;
+
         if flag & 16:
             num_bulges = bs.read_bit_long()
mozman commented 1 year ago

Hi!

Thanks for the fix of the proxy graphic issue, I added it manually.

I am not sure if your solution is a good solution because there is always someone who needs a narrower hatch lines. The problem is that very narrow hatch lines took a VERY long time to render, the drawing add-on has a 30 seconds timeout limit for that, but that's more like an emergency switch.

CAD applications can decide if the hatch lines are visible or not and can render a solid filling instead. The hatching.py module doesn't have this information.

I have no idea how to fix this yet, but it's more complicated than changing a constant.

mozman commented 1 year ago

The default behavior of the drawing add-on is to render a solid filling if the hatch line distance is too narrow.

The minimum hatch line distance of the drawing add-on can be overridden by the option Configuration.min_hatch_line_distance.

When using the hatching module directly, the function pattern_baselines() and the class HatchBaseLine have an additional argument min_hatch_line_distance to set a custom value.

The default value of MIN_HATCH_LINE_DISTANCE is still 1e-4.