Cannot add points?


Is this a bug?

x =[0, 1, 0])
(0mm, 25.4mm, 0mm)
x + x
Error: #<ArgumentError: Cannot convert argument to Sketchup::Vector3d>
<main>:in `+'
<main>:in `<main>'
SketchUp:1:in `eval'

According to the docs, this should be doable, and should return a point:

Point3d addition operator

The API is wrong, and it has been reported somewhen as bug. It allows only:
point + vector = another point

Although there are many occasions where we would want to interprete a point as the corresponding vector from origin, we have to ab-use arrays which SketchUp has patched to work as point or vector.

(But Ruby arrays outside SketchUp won’t work that way, and type validation is also more complicated: Is the method parameter a vector or an Array that has three numerical values).


The API has an unfortunate combination of purist attitude on some aspects and programmer-friendly type substitution on others.

From a purist geometric point of view, a Point3d is a location in model space. It makes no sense to add two points: what does it mean to add locations? Also in the purist view, a Vector3d is a quantity with direction and magnitude, but no location. When you add a Vector3d to a Point3d the meaning is “create a new Point3d offset by this Vector3d from the original”. You can also add Vector3d’s to each other because geometry defines a triangle-rule meaning for this operation.

But from a programmer-friendly perspective, SketchUp overloads the Array class so that almost any method that accepts a Point3d or a Vector3d will happily accept a 3-element Array as well. This leads programmers to want the Point3d+Point3d operation because the semantic boundary between Point3d and Vector3d and Array has become blurry.