Commit be7136e7 authored by Christian Winter's avatar Christian Winter

cleaup. removed legacy code. rotation and scale now using centerOfBB instead...

cleaup. removed legacy code. rotation and scale now using centerOfBB instead of centerOfMass for center if nothing is provided
parent 4c2fd71a
Pipeline #4766111 passed with stage
in 1 minute and 16 seconds
......@@ -26,7 +26,7 @@ class LineManipulator {
if (Preferences.usePivot)
rotationCenter = pivot;
else
rotationCenter = Utilities.calculateCenterOfMass(Selection.getAllPositions());
rotationCenter = Utilities.calculateBBCenter(Selection.getAllPositions());
}
for (let p of selAsPoints)
......@@ -57,60 +57,7 @@ class LineManipulator {
return newPos;
}
static rotate(clockwise) {
let minX = Infinity;
let minY = Infinity;
let selLines = Selection.data.lines;
for (let i = 0; i < selLines.length; ++i) {
minX = Math.min(minX, selLines[i].start.position.x);
minY = Math.min(minY, selLines[i].start.position.y);
minX = Math.min(minX, selLines[i].end.position.x);
minY = Math.min(minY, selLines[i].end.position.y);
}
for (let i = 0; i < selLines.length; ++i) {
let tmp = selLines[i].start.position.x;
selLines[i].start.position.x = selLines[i].start.position.y;
selLines[i].start.position.y = tmp;
if (clockwise)
selLines[i].start.position.x = -selLines[i].start.position.x
else
selLines[i].start.position.y = -selLines[i].start.position.y
tmp = selLines[i].end.position.x;
selLines[i].end.position.x = selLines[i].end.position.y;
selLines[i].end.position.y = tmp;
if (clockwise)
selLines[i].end.position.x = -selLines[i].end.position.x
else
selLines[i].end.position.y = -selLines[i].end.position.y
}
let newMinX = Infinity;
let newMinY = Infinity;
for (let i = 0; i < selLines.length; ++i) {
newMinX = Math.min(newMinX, selLines[i].start.position.x);
newMinY = Math.min(newMinY, selLines[i].start.position.y);
newMinX = Math.min(newMinX, selLines[i].end.position.x);
newMinY = Math.min(newMinY, selLines[i].end.position.y);
}
for (let i = 0; i < selLines.length; ++i) {
selLines[i].start.position.x += minX - newMinX;
selLines[i].start.position.y += minY - newMinY;
selLines[i].end.position.x += minX - newMinX;
selLines[i].end.position.y += minY - newMinY;
}
Renderer.redraw();
}
static scaleSelection(scaleVector) {
// numeric values
if (!isNaN(scaleVector))
......@@ -121,7 +68,7 @@ class LineManipulator {
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
center = Utilities.calculateBBCenter(Selection.getAllPositions());
let selectionAsPoints = Utilities.linesToLineEndings(Selection.data.lines).concat(Selection.data.points);
for (let p of selectionAsPoints)
......
......@@ -36,25 +36,10 @@ class Utilities {
}
}
// TODO lines needed? i could always use points, maybe...
static calculateBBCenter(lines, points) {
static calculateBBCenter(points) {
let min = new Vector2(Infinity, Infinity);
let max = new Vector2(-Infinity, -Infinity);
if (lines != null) {
for (let line of lines) {
min.x = Math.min(min.x, line.start.position.x);
min.y = Math.min(min.y, line.start.position.y);
max.x = Math.max(max.x, line.start.position.x);
max.y = Math.max(max.y, line.start.position.y);
min.x = Math.min(min.x, line.end.position.x);
min.y = Math.min(min.y, line.end.position.y);
max.x = Math.max(max.x, line.end.position.x);
max.y = Math.max(max.y, line.end.position.y);
}
}
for (let point of points) {
min.x = Math.min(min.x, point.position.x);
min.y = Math.min(min.y, point.position.y);
......@@ -207,7 +192,7 @@ class Utilities {
static mergeSelectedPoints() {
let endings = Selection.getAllSelectedPoints();
let center = this.calculateBBCenter(null, endings);
let center = this.calculateBBCenter(endings);
for (let ending of endings)
ending.position = center.copy();
......
......@@ -19,9 +19,9 @@
break;
case Key.R:
if (Input.isKeyDown(Key.Shift))
LineManipulator.rotate(false);
LineManipulator.rotateSelectionBy(90);
else if (Input.isKeyDown(Key.Control))
LineManipulator.rotate(true);
LineManipulator.rotateSelectionBy(-90);
else if (!Input.isKeyDown(Key.Shift) && !Input.isKeyDown(Key.Control))
if (!Selection.noSelection())
Logic.setState(new RotateState());
......
......@@ -790,7 +790,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
center = Utilities.calculateBBCenter(Selection.getAllPositions());
// selected lines
for (let line of Selection.data.lines)
......@@ -820,7 +820,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
center = Utilities.calculateBBCenter(Selection.getAllPositions());
// selected lines
for (let line of Selection.data.lines)
......
......@@ -35,7 +35,7 @@
if (Preferences.usePivot)
rotationCenter = pivot;
else
rotationCenter = Utilities.calculateCenterOfMass(Selection.getAllPositions());
rotationCenter = Utilities.calculateBBCenter(Selection.getAllPositions());
let p1 = Logic.currentState.startPos.subtractVector(rotationCenter);
let p2 = Logic.currentState.currentPos.subtractVector(rotationCenter);
......
......@@ -39,7 +39,7 @@
if (Preferences.usePivot)
center = pivot;
else
center = Utilities.calculateCenterOfMass(Selection.getAllPositions());
center = Utilities.calculateBBCenter(Selection.getAllPositions());
let p1 = Logic.currentState.startPos.subtractVector(center);
let p2 = Logic.currentState.currentPos.subtractVector(center);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment