I am sorry if this question has an obvious answer, which I just fail to see. Anyway, if anyone can enlighten me, I would be grateful.

Writing a tool for a specific purpose, I needed to calculate whether something obstructed the view from the object to the camera eye (of the observer of the view). I use the API *raytest* function for this purpose, something which technically works absolutely correct.

However, calculating using *raytest* in a loop for every vertex in a grid with N vertices, I expected the loop to require approximately the same time per vertex. To my surprise, when testing with the three grids shown in the picture, I get these numbers:

Original array has 961 points

Processing done after: 0.389203 for 961 pts (0.0004049979188345474 sec/pt): nohits=961

Original array has 121 points

Processing done after: 0.006125 for 121 pts (5.061983471074381e-05 sec/pt): nohits=121

Original array has 441 points

Processing done after: 0.085612 for 441 pts (0.0001941315192743764 sec/pt): nohits=441

My test routine is fairly simple:

```
#
def self.check_if_vertices_unobstructed_x(vtx_ary, eye)
num_nohit = 0
num = vtx_ary.size
puts "Original array has #{num} points"
start_time = Time.now
if (vtx_ary.size > 0)
for i in 0..num-1
pos = vtx_ary[i].position
hit = Sketchup.active_model.raytest([pos, Geom::Vector3d.new(eye - pos)], true)
if (hit == nil)
num_nohit += 1
end
end
end
end_time = Time.now
diff_time = end_time - start_time
puts "Processing done after: #{diff_time} for #{num} pts (#{diff_time/num} sec/pt): nohits=#{num_nohit}"
return num, num_nohit
end
# From faces and edges, get all vertices
def self.get_vertex_ary(fac_ary, edg_ary)
vtx_ary = []
if (fac_ary != nil) && (fac_ary.size > 0)
fac_ary.each { |f|
f.edges.each { |e|
vtx_ary << e.start
vtx_ary << e.end
}
}
end
if (edg_ary != nil) && (edg_ary.size > 0)
edg_ary.each { |e|
vtx_ary << e.start
vtx_ary << e.end
}
end
vtx_ary.uniq!
return vtx_ary
end
# Get all active vertices
def self.get_active_vertex_ary()
# Get all active faces
fac_ary = Sketchup.active_model.active_entities.grep(Sketchup::Face)
# Get all vertices
vtx_ary = get_vertex_ary(fac_ary, nil)
return vtx_ary
end
# Default code, use or delete...
mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
puts ""
# Get active vertices in context
@vtx_ary_all = self.get_active_vertex_ary()
# Return array with only visible (non_obstructed) vertices
num, num_nohit = check_if_vertices_unobstructed_x(@vtx_ary_all, Sketchup.active_model.active_view.camera.eye)
```

Is there a straigthforward reason for the loop not behave linearly in time?

Doing this test in a loop is probably a bad idea if there existed a bulk *raytest* alternative. I am, however not aware of one?