ellipse intersectBBox very coarse approx

This commit is contained in:
Matthieu Baumann
2025-09-04 11:04:05 +02:00
parent 301e004afc
commit 91e1d70489
2 changed files with 25 additions and 4 deletions

View File

@@ -129,8 +129,6 @@ export class Selector {
// footprints
if (s.isFootprint() && s.tooSmallFootprint === false) {
if (s.footprint.intersectsBBox(bbox.x, bbox.y, bbox.w, bbox.h, view)) {
console.log("OOOOOO")
objListPerCatalog.push(s);
}

View File

@@ -291,6 +291,7 @@ export let Ellipse = (function() {
ctx.globalAlpha = this.opacity;
ctx.beginPath();
this.aPixels = px_per_deg * this.a;
ctx.ellipse(originScreen[0], originScreen[1], px_per_deg * this.a, px_per_deg * this.b, theta, 0, 2*Math.PI, false);
if (!noStroke) {
if (this.fillColor) {
@@ -344,9 +345,31 @@ export let Ellipse = (function() {
return ctx.isPointInStroke(x, y);
};
Ellipse.prototype.intersectsBBox = function(x, y, w, h) {
Ellipse.prototype.intersectsBBox = function(x, y, w, h, view) {
// TODO: currently the same as Circle where radius = a.
var centerXyview = view.aladin.world2pix(this.centerRaDec[0], this.centerRaDec[1]);
if (!centerXyview) {
return false;
}
return false;
// compute the absolute distance between the middle of the bbox
// and the center of the circle
const circleDistance = {
x: Math.abs(centerXyview[0] - (x + w/2)),
y: Math.abs(centerXyview[1] - (y + h/2))
};
if (circleDistance.x > (w/2 + this.aPixels)) { return false; }
if (circleDistance.y > (h/2 + this.aPixels)) { return false; }
if (circleDistance.x <= (w/2)) { return true; }
if (circleDistance.y <= (h/2)) { return true; }
const dx = circleDistance.x - w/2;
const dy = circleDistance.y - h/2;
const cornerDistanceSquared = dx*dx + dy*dy;
return (cornerDistanceSquared <= (this.aPixels*this.aPixels));
};
return Ellipse;