@unknownuser said:
Pascal's averaged 8.4 versus 45.9 for Caul's
Heh, really ?? 8 seconds vs 45 for 5000 Points ?
edit:( My timings: Pascal ~ 10 sec, CAUL's module 1.11 sec )
Then CAUL's method add constructionpoints inside the timings, also.
I forgot to mention I tested under Su8. So maybe "distance squared" performs better under Ruby2 ? Might be worthwhile to do some profiling after all then.
(I don't know the accuracy of the test..)
mod = Sketchup.active_model
sel = mod.selection
ents = mod.entities
sel.clear
cps = []
saved = []
maxdist = 1000
mindist = 500
minSQ = mindist*mindist
tp = ents.add_cpoint( ORIGIN ) #testpoint Try offsets from 0,0,0 ?
tp = tp.position
for i in 0..5000
cp = ents.add_cpoint( Geom;;Point3d.new(rand*maxdist,rand*maxdist,rand*maxdist) )
cps << cp
end
t = Time.now
cps.each{|cp|
pt = cp.position
x = tp.x-pt.x
y = tp.y-pt.y
z = tp.z-pt.z
#next unless pt.distance(tp) <= mindist
next unless ( x*x + y*y + z*z ) <= minSQ
saved << cp
}
puts Time.now-t
sel.add( saved )
nil