@johnwmcc said:
If you are storing Point3d objects, would you need @contents.to_a first, before .max.y or min.y?
The min and max methods come from the Enumerable mixin module.
Enumerable is mixed into Array, but not Geom::Point3d, nor Geom::Vector3d.
To see what modules may be mixed into a class, use
*Classname*.ancestors
So to answer the question, yes, or if using your own collection class, you might mix in the Enumerable module into it.
@johnwmcc said:
It does, for me. It was intended to select out the y coordinate (a scalar) from the point coordinates.
ary = [pt1, pt2, pt3, pt4, ... ]
To select the point which has the minimum y value, from an array of points, do this:
miny_pt = ary.min {|a,b| a.y <=> b.y }
To select the point which has the maximum y value, from an array of points, do this:
maxy_pt = ary.max {|a,b| a.y <=> b.y }
... then get your thickness:
thickness = maxy_pt.y - miny_pt.y
To translate: [ruby:247d5h9w]ary.max {|a,b| a.y <=> b.y }[/ruby:247d5h9w], into plain English:
"iterate [ruby:247d5h9w]ary[/ruby:247d5h9w], each loop compare the current member ([ruby:247d5h9w]a[/ruby:247d5h9w])'s y value, against the next member ([ruby:247d5h9w]b[/ruby:247d5h9w])'s y value, and return the member that resolves to the maximum." The comparison is defined using Ruby's comparison operator, [ruby:247d5h9w]<=>[/ruby:247d5h9w].
Remember that the entire member is returned, so later you still need to ask for just the y value.
@johnwmcc said:
I wasn't sure if the [ruby:247d5h9w].x[/ruby:247d5h9w] and [ruby:247d5h9w].y[/ruby:247d5h9w] methods would work on arrays, but they seem to in my example code.
Because the SketchUp API adds those methods to the Ruby Array class. (It is part of making Ruby arrays compatible with API points and vectors.)
@johnwmcc said:
I'm unclear about the near-but-not-complete equivalence between SU [ruby:247d5h9w]Point3d(x, y, z)[/ruby:247d5h9w] and [ruby:247d5h9w]Array[x, y, z][/ruby:247d5h9w]- it seems I can use either a lot of the time, but not quite always!
Read the API regarding how it adds to Array class:
http://www.sketchup.com/intl/en/developer/docs/ourdoc/array