Written Brep not considered geometrically equal to read Brep

Hi there,

Just ran into some odd behaviour with BinaryArchiveWriter/Reader and GeometryBase.GeometryEquals(...).

Namely, if I write Brep to the archive, read it, then use GeometryBase.GeometryEquals(...) to compare what I read with what I wrote, the two brep’s aren’t seen as equal. Here’s some NUnit source code that illustrates it–I’m using the Rhino.Testing framework:

[RhinoTestFixture]
public class SerializationTests
{

    [Test]
    public void ReadWriteBrep()
    {
        var writtenBrep = Brep.CreateFromSphere(new Sphere(Point3d.Origin, 1.0));
        const string testFileName = $"{nameof(ReadWriteBrep)}.bin";
        {
            File.Delete(testFileName);
            using var outputFile = new BinaryArchiveFile(testFileName, BinaryArchiveMode.Write);
            outputFile.Open();
            outputFile.Writer.WriteGeometry(writtenBrep);
            outputFile.Close();
        }


        using var inputFile = new BinaryArchiveFile(testFileName, BinaryArchiveMode.Read);
        inputFile.Open();
        var readBrep = (Brep)inputFile.Reader.ReadGeometry();
        inputFile.Close();

        Assert.IsTrue(GeometryBase.GeometryEquals(readBrep, writtenBrep));  // This fails
    }
}

Any help would be much appreciated!

Kind regards,
Dustin

Hi @Dustin_Condon,

Try doing this:

var writtenBrep = Brep.CreateFromSphere(new Sphere(Point3d.Origin, 1.0));
writtenBrep.MakeValidForV2();

Since you’re using BinaryArchiveFile and not File3dm, the Brep object assumes, when writing, it must convert non-NURBS types to NURBS in order to support older readers.

– Dale