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

Ajout de poignées supplémentaires sur le tracé de la boîte de petri. Closes #1

parent fad4f68e
No related branches found
No related tags found
No related merge requests found
import * as paper from "paper"; import * as paper from "paper";
import {AbstractInstrument, Handle, Instrument} from "./instrument"; import {AbstractInstrument, Handle, Instrument} from "./instrument";
import {CircleCoords} from "../data/coords/circleCoords";
import {Lab} from "../lab"; import {Lab} from "../lab";
import {EllipseCoords} from "../data/coords/ellipseCoords"; import {EllipseCoords} from "../data/coords/ellipseCoords";
...@@ -14,6 +13,8 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst ...@@ -14,6 +13,8 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
new Handle("rightHandle", true), new Handle("rightHandle", true),
new Handle("bottomHandle", true), new Handle("bottomHandle", true),
new Handle("centerHandle", 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 ...@@ -23,11 +24,12 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
onHandleMove(coords: EllipseCoords, handle: Handle, point: paper.Point, delta: paper.Point): void { onHandleMove(coords: EllipseCoords, handle: Handle, point: paper.Point, delta: paper.Point): void {
switch (handle.name) { switch (handle.name) {
case "centerHandle" : case "centerHandle" : {
coords.center = coords.center.add(delta); coords.center = coords.center.add(delta);
break; break;
}
case "rightHandle": case "rightHandle": {
let newRadiusX = point.x - coords.center.x; let newRadiusX = point.x - coords.center.x;
let deltaRadiusX = newRadiusX - coords.radiusX; let deltaRadiusX = newRadiusX - coords.radiusX;
if(newRadiusX > 10) { if(newRadiusX > 10) {
...@@ -35,8 +37,19 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst ...@@ -35,8 +37,19 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
coords.center = coords.center.add(new paper.Point(deltaRadiusX / 2, 0)); coords.center = coords.center.add(new paper.Point(deltaRadiusX / 2, 0));
} }
break; 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 newRadiusY = point.y - coords.center.y;
let deltaRadiusY = newRadiusY - coords.radiusY; let deltaRadiusY = newRadiusY - coords.radiusY;
if(newRadiusY > 10) { if(newRadiusY > 10) {
...@@ -45,6 +58,17 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst ...@@ -45,6 +58,17 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
} }
break; 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;
}
}
} }
locateHandle(coords: EllipseCoords, handle: Handle): paper.Point { locateHandle(coords: EllipseCoords, handle: Handle): paper.Point {
...@@ -55,9 +79,15 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst ...@@ -55,9 +79,15 @@ export class PetriDish extends AbstractInstrument<EllipseCoords> implements Inst
case "rightHandle": case "rightHandle":
return coords.center.add(new paper.Point(coords.radiusX, 0)); return coords.center.add(new paper.Point(coords.radiusX, 0));
case "leftHandle":
return coords.center.subtract(new paper.Point(coords.radiusX, 0));
case "bottomHandle": case "bottomHandle":
return coords.center.add(new paper.Point(0, coords.radiusY)); return coords.center.add(new paper.Point(0, coords.radiusY));
case "topHandle":
return coords.center.subtract(new paper.Point(0, coords.radiusY));
default: default:
throw new Error("Unknown handle"); throw new Error("Unknown handle");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment