From bfc734ef41cb1c9c5fababeb4abcb97129c36ff8 Mon Sep 17 00:00:00 2001
From: Laurent Knoll <laurent.knoll@orange.com>
Date: Fri, 23 Sep 2022 20:24:58 +0200
Subject: [PATCH] =?UTF-8?q?Ajout=20de=20poign=C3=A9es=20suppl=C3=A9mentair?=
 =?UTF-8?q?es=20sur=20le=20trac=C3=A9=20de=20la=20bo=C3=AEte=20de=20petri.?=
 =?UTF-8?q?=20Closes=20#1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/instruments/petriDish.ts | 38 ++++++++++++++++++++++++++++++++----
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/instruments/petriDish.ts b/src/instruments/petriDish.ts
index 8095574..a52c37b 100644
--- a/src/instruments/petriDish.ts
+++ b/src/instruments/petriDish.ts
@@ -1,6 +1,5 @@
 import * as paper from "paper";
 import {AbstractInstrument, Handle, Instrument} from "./instrument";
-import {CircleCoords} from "../data/coords/circleCoords";
 import {Lab} from "../lab";
 import {EllipseCoords} from "../data/coords/ellipseCoords";
 
@@ -14,6 +13,8 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
             new Handle("rightHandle", true),
             new Handle("bottomHandle", true),
             new Handle("centerHandle", true),
+            new Handle("topHandle", true),
+            new Handle("leftHandle", true),
         ])
     }
 
@@ -23,11 +24,12 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
 
     onHandleMove(coords: EllipseCoords, handle: Handle, point: paper.Point, delta: paper.Point): void {
         switch (handle.name) {
-            case "centerHandle" :
+            case "centerHandle" : {
                 coords.center = coords.center.add(delta);
                 break;
+            }
 
-            case "rightHandle":
+            case "rightHandle": {
                 let newRadiusX = point.x - coords.center.x;
                 let deltaRadiusX = newRadiusX - coords.radiusX;
                 if(newRadiusX > 10) {
@@ -35,8 +37,19 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
                     coords.center = coords.center.add(new paper.Point(deltaRadiusX / 2, 0));
                 }
                 break;
+            }
 
-            case "bottomHandle":
+            case "leftHandle": {
+                let newRadiusX = coords.center.x - point.x;
+                let deltaRadiusX = newRadiusX - coords.radiusX;
+                if(newRadiusX > 10) {
+                    coords.radiusX = coords.radiusX + deltaRadiusX / 2;
+                    coords.center = coords.center.subtract(new paper.Point(deltaRadiusX / 2, 0));
+                }
+                break;
+            }
+
+            case "bottomHandle": {
                 let newRadiusY = point.y - coords.center.y;
                 let deltaRadiusY = newRadiusY - coords.radiusY;
                 if(newRadiusY > 10) {
@@ -44,6 +57,17 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
                     coords.center = coords.center.add(new paper.Point(0, deltaRadiusY / 2));
                 }
                 break;
+            }
+
+            case "topHandle": {
+                let newRadiusY = coords.center.y - point.y;
+                let deltaRadiusY = newRadiusY - coords.radiusY;
+                if(newRadiusY > 10) {
+                    coords.radiusY = coords.radiusY + deltaRadiusY / 2;
+                    coords.center = coords.center.subtract(new paper.Point(0, deltaRadiusY / 2));
+                }
+                break;
+            }
         }
     }
 
@@ -55,9 +79,15 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
             case "rightHandle":
                 return coords.center.add(new paper.Point(coords.radiusX, 0));
 
+            case "leftHandle":
+                return coords.center.subtract(new paper.Point(coords.radiusX, 0));
+
             case "bottomHandle":
                 return coords.center.add(new paper.Point(0, coords.radiusY));
 
+            case "topHandle":
+                return coords.center.subtract(new paper.Point(0, coords.radiusY));
+
             default:
                 throw new Error("Unknown handle");
         }
-- 
GitLab