Skip to content
Snippets Groups Projects
Commit a2a683ea authored by Laurent Knoll's avatar Laurent Knoll
Browse files

Correction de l'ellipse "fitted"

parent 7b8bc5d9
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ enum Orientation { ...@@ -8,7 +8,7 @@ enum Orientation {
} }
/** /**
* Génère une coque convexe * Génère un contour convexe
* Jarvis’s Algorithm or Wrapping * Jarvis’s Algorithm or Wrapping
* @see https://www.geeksforgeeks.org/convex-hull-set-1-jarviss-algorithm-or-wrapping/ * @see https://www.geeksforgeeks.org/convex-hull-set-1-jarviss-algorithm-or-wrapping/
*/ */
......
...@@ -113,7 +113,7 @@ export class ToEllipseFitter implements Transformation<PathCoords, Coords>{ ...@@ -113,7 +113,7 @@ export class ToEllipseFitter implements Transformation<PathCoords, Coords>{
xCenter = this.left + xoffset + 0.5; xCenter = this.left + xoffset + 0.5;
yCenter = this.top + yoffset + 0.5; yCenter = this.top + yoffset + 0.5;
return new EllipseCoords(new paper.Point(xCenter, yCenter), major / 2, minor / 2, angle); return new EllipseCoords(new paper.Point(xCenter, yCenter), major / 2, minor / 2, -angle);
} }
private computeSums (path : paper.Path) : void { private computeSums (path : paper.Path) : void {
...@@ -148,20 +148,19 @@ export class ToEllipseFitter implements Transformation<PathCoords, Coords>{ ...@@ -148,20 +148,19 @@ export class ToEllipseFitter implements Transformation<PathCoords, Coords>{
for (let y = 0; y < this.height; y++) { for (let y = 0; y < this.height; y++) {
bitcountOfLine = 0; bitcountOfLine = 0;
xSumOfLine = 0; xSumOfLine = 0;
let offset = Math.round(y * pixelRatio) * this.width * 4; let offset = Math.round(y * pixelRatio) * raster.width * 4;
for (let x=0; x < this.width; x++) { for (let x=0; x < this.width; x++) {
// let point = new paper.Point(x + this.left, y + this.top) // let point = new paper.Point(x + this.left, y + this.top)
// if (point.getDistance(center) < minCenterDist // if (point.getDistance(center) < minCenterDist
// || path.contains(point)) { // || path.contains(point)) {
if(data[offset + Math.round(x * pixelRatio) * 4] > 0 ) { if(data[data.byteOffset + offset + Math.round(x * pixelRatio) * 4] > 0 ) {
bitcountOfLine++; bitcountOfLine++;
xSumOfLine += x; xSumOfLine += x;
this.x2sum += x * x; this.x2sum += x * x;
} }
} }
this.xsum += xSumOfLine; this.xsum += xSumOfLine;
this.ysum += bitcountOfLine * y; this.ysum += bitcountOfLine * y;
ye = y; ye = y;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment