crop jigsawpiece points

This commit is contained in:
2022-08-13 18:52:57 +00:00
parent 704c1e8c2f
commit d3830a9bb7
2 changed files with 20 additions and 0 deletions

View File

@@ -71,16 +71,28 @@ class JigsawPiece{
if( sideData.west != null ) createHoriSide( lb, lt, bubbleSize, sideData.west, WEST );
points.push( lt );
var minX = Math.POSITIVE_INFINITY;
var minY = Math.POSITIVE_INFINITY;
var maxX = 0.0;
var maxY = 0.0;
for (point in points) {
if (point.x < minX)
minX = point.x;
if (point.y < minY)
minY = point.y;
if (point.x > maxX)
maxX = point.x;
if (point.y > maxY)
maxY = point.y;
}
wh = new Vec2(maxX, maxY);
// Crop the points so we don't make a bigger source rectangle than needed:
xy.add(minX, minY);
for (point in points.concat([wh])) {
point.subtract(minX, minY);
}
}
public function getPoints(): Array<Vec2> {
return points;
}

View File

@@ -9,6 +9,14 @@ class Vec2{
public function copy() {
return new Vec2(x, y);
}
public function add(dx:Float, dy:Float) {
x += dx;
y += dy;
}
public function subtract(dx:Float, dy:Float) {
x -= dx;
y -= dy;
}
public function toString() {
return '(${x}, ${y})';
}