Hi Hakan,
I guess looping through all objects would be a way to do it. You could optimize this by dividing the document up into an imaginary grid and then only check for items within each column within the grid parts that intersect with the circle's bounds..
I made a quick example for you, but its quite untested.. I'm also unsure how much faster it is then simply checking each item for intersections..
tool.eventInterval = 5;
var grid = [];
var rows = 10;
var columns = 5;
var radius, path;
function onMouseDown(event) {
var colSize = document.size / new Size(columns, rows);
for(var i = 0; i < rows; i++) {
for(var j = 0; j < columns; j++) {
var location = new Point(j, i);
var gridPart = {
items: [],
rectangle: new Rectangle(location * colSize, location * colSize + colSize)
};
grid.push(gridPart);
}
}
var items = document.getItems({
type: Item
});
for(var i = 0; i < items.length; i++) {
var item = items[i];
for(var j = 0; j < grid.length; j++) {
var column = grid[j];
if(column.rectangle.intersects(item.bounds)) {
column.items.push(item);
}
}
}
radius = 5;
hit = false;
path = null;
}
var hit;
function onMouseDrag(event) {
if(!hit && path) {
for(var i = 0; i < grid.length; i++) {
var column = grid[i];
if(column.rectangle.intersects(path.bounds)) {
var items = column.items;
for(var j = 0; j < items.length; j++) {
var item = items[j];
if(item.bounds.intersects(path.bounds) && item.intersects(path)) {
hit = true;
j = items.length;
i = grid.length;
}
}
}
}
}
if(!hit) {
if(path)
path.remove();
radius += 2;
path = new Path.Circle(event.downPoint, radius);
}
}