SketchUp / api-issue-tracker

Public issue tracker for the SketchUp and LayOut's APIs
https://developer.sketchup.com/
39 stars 10 forks source link

`Sketchup::Axes#transformation` code example comment wording #789

Open DanRathbun opened 2 years ago

DanRathbun commented 2 years ago

SketchUp Ruby API Documentation Issue

Sketchup::Axes#transformation code example comment wording may be a bit misleading with respect to other descriptive text in the API documentation.

Currently, says:

# Transform the points so they are local to the model axes. Otherwise
# they would be local to the model origin.

EDIT: Actually my initial thinking (below) was wrong although the code comments are still a bit hard to understand.

The 1st sentence ends in the incorrect term: "model axes" (should be "drawing axes".)

The 2nd sentence ends in "model origin" (should be "root model axes".)

The main points that the example must convey:

  1. The points are given in coordinates local to the drawing axes.

  2. All the API geometry creation methods expect model coordinates.

  3. The transforming of those points is done so that they are now in coordinates local to the model axes.

Note that the Sketchup::Axes class introduction refers to the static "global" model axes as the "root model transformation". (IMO, the term "root" is better than using "global" or "world" as a building model is often later placed into the larger world within some UTM zone transform.)

The code example should probably read as ( _corrected_ ):

model = Sketchup.active_model
# Points for a rectangle in coordinates local to the drawing axes:
points = [
  Geom::Point3d.new( 0,  0, 0),
  Geom::Point3d.new(10,  0, 0),
  Geom::Point3d.new(10, 20, 0),
  Geom::Point3d.new( 0, 20, 0)
]
# The API creation factory methods only take point coordinates local to the model axes.
# Transform the drawing point coordinates so they are local to the root model axes:
tr = model.axes.transformation
points.each { |point| point.transform!(tr) }
# Now use the transformed points to create geometry:
model.active_entities.add_face(points)

Reference forum discussion: Global Axes Ruby plugin, post 3

DanRathbun commented 2 years ago

Updated and posted full corrected code snippet.