Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ACadSharp.Image.Tests/EntityRenderDispatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,24 @@ public void PatternHatchDrawsClippedLines()
Assert.All(surface.Styles, s => Assert.Null(s.DashPattern));
}

[Fact]
public void PredefinedPatternHatchDrawsItsPatternRatherThanAFill()
{
// DXF group 76 (Hatch.PatternType) is 0 = user-defined, 1 = predefined, 2 = custom. ACadSharp names the value
// 1 "SolidFill", but a hatch read from a file with a predefined pattern such as ANSI31 carries exactly that
// value with IsSolid (group 70) false. Group 70 alone says whether a hatch is a solid fill.
RecordingDrawingSurface surface = new();
ImageConfiguration configuration = new();
EntityRenderDispatcher dispatcher = new(configuration);
Hatch hatch = SquareHatch(solid: false);
hatch.PatternType = HatchPatternType.SolidFill;

dispatcher.Draw(CreateContext(surface, configuration), hatch);

Assert.DoesNotContain(surface.Calls, c => c.StartsWith("FillPath", StringComparison.Ordinal));
Assert.InRange(surface.Calls.Count(c => c.StartsWith("DrawLine", StringComparison.Ordinal)), 5, 9);
}

[Fact]
public void PatternHatchIsCappedWithWarning()
{
Expand Down
5 changes: 4 additions & 1 deletion ACadSharp.Image/Rendering/EntityRenderDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,10 @@ private void DrawHatch(ImageRenderContext context, ImageStyle style, Hatch hatch
OcsTransform? toWorld = IsWorldPlane(hatch.Normal) ? null : OcsTransform.For(hatch.Normal);
SurfacePoint ToSurface(XYZ point) => context.ToSurfacePoint(InsertPlacement.MapOcsPoint(placement, toWorld, hatch.Elevation, point));

if (hatch.IsSolid || hatch.PatternType == HatchPatternType.SolidFill)
// Only the solid-fill flag (DXF group 70) says a hatch is a fill. Hatch.PatternType is DXF group 76, whose value
// 1 means "predefined pattern" even though ACadSharp names it SolidFill: every hatch read from a file with a
// stock pattern such as ANSI31 carries it, and testing for it here filled all of those solid.
if (hatch.IsSolid)
{
List<IReadOnlyList<SurfacePoint>> rings = new();
foreach (Hatch.BoundaryPath path in hatch.Paths)
Expand Down
Loading