From a2a683eac84ad18b247b3c3650643bbe12adcd90 Mon Sep 17 00:00:00 2001
From: Laurent Knoll <laurent.knoll@orange.com>
Date: Mon, 19 Sep 2022 07:18:09 +0200
Subject: [PATCH] Correction de l'ellipse "fitted"

---
 src/data/coords/transform/toConvexHull.ts    | 2 +-
 src/data/coords/transform/toEllipseFitter.ts | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/src/data/coords/transform/toConvexHull.ts b/src/data/coords/transform/toConvexHull.ts
index a3fc45a..b6a9d7e 100644
--- a/src/data/coords/transform/toConvexHull.ts
+++ b/src/data/coords/transform/toConvexHull.ts
@@ -8,7 +8,7 @@ enum Orientation {
 }
 
 /**
- * Génère une coque convexe
+ * Génère un contour convexe
  * Jarvis’s Algorithm or Wrapping
  * @see https://www.geeksforgeeks.org/convex-hull-set-1-jarviss-algorithm-or-wrapping/
  */
diff --git a/src/data/coords/transform/toEllipseFitter.ts b/src/data/coords/transform/toEllipseFitter.ts
index d3a683b..ce51ac8 100644
--- a/src/data/coords/transform/toEllipseFitter.ts
+++ b/src/data/coords/transform/toEllipseFitter.ts
@@ -113,7 +113,7 @@ export class ToEllipseFitter implements Transformation<PathCoords, Coords>{
         xCenter = this.left + xoffset + 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 {
@@ -148,20 +148,19 @@ export class ToEllipseFitter implements Transformation<PathCoords, Coords>{
         for (let y = 0; y < this.height; y++) {
             bitcountOfLine = 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++) {
 
                 // let point = new paper.Point(x + this.left, y + this.top)
                 // if (point.getDistance(center) < minCenterDist
                 //     || path.contains(point)) {
-                if(data[offset + Math.round(x * pixelRatio) * 4] > 0 ) {
+                if(data[data.byteOffset + offset + Math.round(x * pixelRatio) * 4] > 0 ) {
                     bitcountOfLine++;
                     xSumOfLine += x;
                     this.x2sum += x * x;
                 }
             }
 
-
             this.xsum += xSumOfLine;
             this.ysum += bitcountOfLine * y;
             ye = y;
-- 
GitLab