Elements icon indicating copy to clipboard operation
Elements copied to clipboard

OffsetOnSide throws exceptions if the first or last leg is shorter than offset

Open andrewheumann opened this issue 4 years ago • 0 comments

here is a failing test, demonstrating a range of problem conditions:

[Fact]
public void Polyline_OffsetOnSide_CloseVertices()
{
    Name = nameof(Polyline_OffsetOnSide_CloseVertices);
    var obtuseL = new Polyline(
        (0, 5),
        (0, 0),
        (1, -0.8)
    );
    var straightL = new Polyline(
        (0, 5),
        (0, 0),
        (1, 0)
    ).TransformedPolyline(new Transform((0, 9)));
    var acuteL = new Polyline(
        (0, 5),
        (0, 0),
        (1, 0.5)
    ).TransformedPolyline(new Transform((0, 18)));
    var obtuseZ = new Polyline(
        (0, 5),
        (0, 0),
        (1, -0.5),
        (1, -3)
    ).TransformedPolyline(new Transform((6, 0)));
    var straightZ = new Polyline(
                (0, 5),
                (0, 0),
                (1, 0),
                (1, -3)
            ).TransformedPolyline(new Transform((6, 9)));
    var acuteZ = new Polyline(
                (0, 5),
                (0, 0),
                (1, 0.5),
                (1, -3)
            ).TransformedPolyline(new Transform((6, 18)));

    var pls = new Polyline[] { obtuseL, straightL, acuteL, obtuseZ, straightZ, acuteZ };
    Model.AddElements(pls.Select(p => new ModelCurve(p, BuiltInMaterials.XAxis)));
    foreach (var pl in pls)
    {
        var offsetResult1 = pl.Reversed().OffsetOnSide(2, true);
        Model.AddElements(offsetResult1.Select(c => new ModelCurve(c, BuiltInMaterials.YAxis, new Transform(0, 0, -0.1))));
        var offsetResult2 = pl.Reversed().OffsetOnSide(2, false);
        Model.AddElements(offsetResult2.Select(c => new ModelCurve(c, BuiltInMaterials.ZAxis, new Transform(0, 0, -0.1))));
    }
}

There are a number of ways to think about the right behavior for this scenario. My preferred is the last column in the following diagram: image

andrewheumann avatar Jan 12 '22 22:01 andrewheumann