rbush icon indicating copy to clipboard operation
rbush copied to clipboard

How to search when usiong the extended class for points

Open rwillett opened this issue 3 years ago • 0 comments

Hi,

We have your rtree code working well and wanted to use the simple extension for points in the docs.

We can create the point tree (or we think we can), but no matter what we search on, we never get a result back.

export class RpointService extends RBush {
    toBBox([x, y]) { return {minX: x, minY: y, maxX: x, maxY: y}; }
    compareMinX(a, b) { return a.x - b.x; }
    compareMinY(a, b) { return a.y - b.y; }

    constructor() {
        super();
        var debug = true;

	if (debug)
            console.log("RpointService constructor called");
    }

    insert(v) {
        console.log("Insert called");
        return super.insert(v);
    }

    all() {
        return super.all();
    }

    search(v) {
        return super.search(v);
    }
}

We can add points using

        var pTree = new RpointService();

        for (var i = 0 ; i < cutLines.length ; i++)
        {
            console.log("CalculateJoinLines: Adding " + JSON.stringify(cutLines[i] , null , 2));

            pTree.insert([ cutLines[i].p1.X , cutLines[i].p1.Y]);
        }

and can see something using

        console.log("ptree = " + JSON.stringify(pTree.all() , null , 2));

ptree = [
  [
    2500,
    9999
  ],
  [
    2500,
    14999
  ]
]

but we cannot find the right format to pass to search to get something returned (anything!),

We've tried

        result = rTree.search({
            minX: 40,
            minY: 20,
            maxX: 80,
            maxY: 70
	});
``
and
    result = rTree.search([20,20]);

and a few other formats, but nothing seems to work. 

Any help or advice welcomed.

Thanks

Rob

rwillett avatar Jul 14 '21 20:07 rwillett