Point3d addition operator

According to Point3d class definition documentation the ‘+’ operator should be used to perform vector addition upon two Point3d objects. However, the interperator generates a run time error with the message that a Vector3d object is expected. This equates to

    p2 = p1 + v

which is the same as

   p2 = p1.offset(v)

This should be flagged as an error since the functionality is at odds with the class definition.

Vector addition of Point3d objects is useful for finding the average of a group of Point3d objects.

   avg = Geom::Point3d.new
   pts.each{|p| avg = avg + p}    # pts is an array of Point3d
   n = 1.0 / pts.count
   t = Geom::Transformation.scaling(n,n,n)

Already known and reported issue. (Basically the information in the docs were copied from another class’ method, and then not properly edited to remove operations that did not apply to this class.):

And BTW, you can simply do this:

p1 = Geom::Point3d::new(1,2,3)
#=> (1", 2", 3")
p2 = Geom::Point3d::new(1,2,3)
#=> (1", 2", 3")
p3 = p1 + p2.to_a
#=> (2", 4", 6")
1 Like