Bug in rs.coerce3dpoint(point)?

Hi @pascal or @stevebaer , I see that if I coerce3dpoint a point and then adjust the new point then the new old point is also adjusted. Is that as expected? I thought coercing a point just got the data from the parent and generated a new entity.

Here is a simple example that makes a point that is at the closest 100x100 coordinate:

import rhinoscriptsyntax as rs

def runScript():
    point = rs.GetPoint("Get point")
    if not point:
        return
    
    pt = rs.coerce3dpoint(point)
    pt.X = round(pt.X/100,0)*100
    pt.Y = round(pt.Y/100,0)*100
    
    rs.AddPoint(pt)
    rs.AddPoint(point)

runScript()

Obviously I can use

pt = rs.coerce3dpoint( (point.X, point.Y, point.Z) )

but in my mind that seems like an unnecessary coding step.

Since 3dPoint is a struct in .NET (and Python integration works through .NET) yes, that is expected.

You need to create a deep copy of the point before doing anything with it. The suggestion you make is exactly what you’re supposed to do.

OK, thank you.

FWIW, one can also use the Point3d copy constructor, which certain RhinoCommon structs provide, while others do not:

2 Likes