annotorious / annotorious-v2-selector-pack

Additional selection tools for Annotorious and the Annotorious OpenSeadragon plugin
BSD 3-Clause "New" or "Revised" License
14 stars 20 forks source link

Pin circle's starting point and prevent overflow #12

Closed yyhhkk12 closed 3 years ago

yyhhkk12 commented 3 years ago

I pinned the starting point of circle and prevented shape overflowing.

Additionally, I tried to prevent shape overflow while drawing circle by calculating cx, cy, r from formula but failed(Prevented overflow successfully on the Y axis, but not X-axis).

// many codes...
    } else if (cy + r > naturalHeight) {
      // radius = naturalHeight - cy
      const a = 1, b = -2*((A**2+1)*this.anchor[1]-A**2*naturalHeight), c = (A**2+1)*this.anchor[1]**2-A**2*naturalHeight**2;
      cy = getRoot(this.anchor[1], oppositeY, getRootCandidates(a, b, c));
      console.log("case 4: ", getRootCandidates(a, b, c))
      cx = (A===0) ? this.anchor[0] + naturalHeight - cy : (cy-B)/A;
      r = naturalHeight - cy;
    }

So, I just prevented number of cases with return.

RubberbandCircle.js - line:57

if ((cx-r < 0 || cx + r > naturalWidth) || (cy-r < 0 || cy + r > naturalHeight)) return;

I don't know whether it's normal behavior or not. So, if it is abnormal procedure, I'd appreciate it if you could let me know.

rsimon commented 3 years ago

That's excellent, many thanks!