Geometry Memory Representation

Will 2 geometries that are identical in geometrical definition but having different Guids have the same byte representation in memory when serialized via its ISerializable interface (using the following code)?

    public byte[] GetSerializedGeometry(GeometryBase geom)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            BinaryFormatter formatter = new BinaryFormatter();
            formatter.Serialize(ms, geom);
            ms.Flush();
            return (ms.ToArray());
        }
    }

I am trying to compare geometries and am aware of the GeometryEquals[http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_GeometryBase_GeometryEquals.htm], but I am trying to do it in Rhino 5.

Hi @Amit_Nambiar,

Objects that inherit from GeometryBase do not have GUIDs.

Note, it is difficult to compare geometry because of float-point rounding issues.

– Dale

I see the difficulty arising due rounding point issue. :frowning:

Just to make sure your tip regarding the GUIDs for GeometryBases is not relevant to my case…
I am trying to compare geometries in two files and GUIDs don’t really matter for my comparison.
If I have a box of 3x3x3 at with center at (4,4,4) in one file and another box of 3x3x3 at (4,4,4) in another file and they have different GUIDs, for my use they should be same. I also don’t need to worry about any UserData, Materials or anything else.

I serialize/compare using the following piece of code…

// this method is same as above
public byte[] GetSerializedGeometry(GeometryBase geom)  
{  
    using (MemoryStream ms = new MemoryStream())  
    {  
        BinaryFormatter formatter = new BinaryFormatter();  
        formatter.Serialize(ms, geom);  
        ms.Flush();  
        return (ms.ToArray());  
    }  
}  
foreach (RhinoObject r in doc.Objects) {  
    byte[] byteData = GetSerializedGeometry(r.Geometry);  
    // save it to a file to be read later and compared with other geometries from other file  
}  

`

For the floating point issue, if there’s no other better way, my next step would be to write my own way of serializing all objects.
For each object I would get all points on the object, round it upto 5 decimal places(enough for my use) and write it to a csv.
But I would need to write custom serialization methods for each type of GeometryBase descendent.

Any suggestions on a better approach?
Appreciate the help.
Thank you.