[Bug?] BrepEdgeList.SplitEdgeAtParameters leaves brep in invalid state

@stevebaer @dalelear

If I execute the simple command below, the brep becomes invalid with the folllowing error (that in itself has a typo :wink: ):

brep.m_V[4] vertex is not valid.
	vertex.m_tolerace = -1.23432e+308 (should be >= 0.0)
ON_Brep.m_V[4] is invalid.

It looks like the vertex tolerance is not set on the new vertex after the BrepEdge has been split.
This can be fixed by calling brep.SetTolerancesBoxesAndFlags(false, true, false, false, false, false, false, false); to set vertex tolerances, but it would be nice if that wasn’t necessary.

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  PlaneSurface ps = PlaneSurface.CreateThroughBox(Plane.WorldXY, new BoundingBox(-1,-1,-1,1,1,1));
  Brep brep = ps.ToBrep();

  BrepEdge be0 = brep.Edges[0];
  brep.Edges.SplitEdgeAtParameters(0, new[] {be0.Domain.Mid});

  if (!brep.IsValidWithLog(out var error))
  {
    RhinoApp.WriteLine(error);
  }
  
  return Result.Success;
}

Hey @menno - I’ll have a look at this.

– Dale

Hi @menno,

As is generally the case when calling low-level Brep functions, there is more work to do to finish.

See if this makes sense;

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
  PlaneSurface ps = PlaneSurface.CreateThroughBox(Plane.WorldXY, new BoundingBox(-1, -1, -1, 1, 1, 1));
  Brep brep = ps.ToBrep();

  BrepEdge be0 = brep.Edges[0];
  int count = brep.Edges.SplitEdgeAtParameters(0, new[] { be0.Domain.Mid });
  if (count > 0)
  {
    brep.SetTolerancesBoxesAndFlags(true, true, false, false, false, false, false, false);
    brep.Compact();
  }

  if (!brep.IsValidWithLog(out var error))
  {
    RhinoApp.WriteLine(error);
  }

  return Result.Success;
}

– Dale

1 Like