fix(front): definite fix to getRoundedAngles
* Switched to pure math transformation
This commit is contained in:
parent
c93d3e643a
commit
677f3d95a1
@ -4,6 +4,10 @@ import Point from "./classes/Point";
|
|||||||
import {POINTER_EVENT_THRESHOLD_MIN_DIST_DELTA, POINTER_EVENT_THRESHOLD_MIN_TIME_DELTA} from "./const";
|
import {POINTER_EVENT_THRESHOLD_MIN_DIST_DELTA, POINTER_EVENT_THRESHOLD_MIN_TIME_DELTA} from "./const";
|
||||||
import ReadOnlyService from "./services/ReadOnlyService";
|
import ReadOnlyService from "./services/ReadOnlyService";
|
||||||
|
|
||||||
|
const RAD_TO_DEG = 180.0 / Math.PI;
|
||||||
|
const DEG_TO_RAD = Math.PI / 180.0;
|
||||||
|
const _45_DEG_IN_RAD = 45 * DEG_TO_RAD;
|
||||||
|
|
||||||
const whiteboard = {
|
const whiteboard = {
|
||||||
canvas: null,
|
canvas: null,
|
||||||
ctx: null,
|
ctx: null,
|
||||||
@ -308,27 +312,19 @@ const whiteboard = {
|
|||||||
* @returns {Point}
|
* @returns {Point}
|
||||||
*/
|
*/
|
||||||
getRoundedAngles: function (currentPos) {
|
getRoundedAngles: function (currentPos) {
|
||||||
const _this = this;
|
const {startCoords} = this;
|
||||||
const x = currentPos.x - _this.startCoords.x;
|
|
||||||
const y = currentPos.y - _this.startCoords.y;
|
|
||||||
const angle = Math.atan2(x, y) * (180 / Math.PI);
|
|
||||||
const angle45 = Math.round(angle / 45) * 45;
|
|
||||||
|
|
||||||
let outX = currentPos.x;
|
// these transformations operate in the standard coordinate system
|
||||||
let outY = currentPos.y;
|
// y goes from bottom to up, x goes left to right
|
||||||
if (angle45 % 90 === 0) {
|
const dx = currentPos.x - startCoords.x; // browser x is reversed
|
||||||
if (Math.abs(currentPos.x - _this.startCoords.x) > Math.abs(currentPos.y - _this.startCoords.y)) {
|
const dy = startCoords.y - currentPos.y;
|
||||||
outY = _this.startCoords.y
|
|
||||||
} else {
|
const angle = Math.atan2(dy, dx);
|
||||||
outX = _this.startCoords.x
|
const angle45 = Math.round(angle / _45_DEG_IN_RAD) * _45_DEG_IN_RAD;
|
||||||
}
|
|
||||||
} else {
|
const dist = currentPos.distTo(startCoords);
|
||||||
if ((currentPos.y - _this.startCoords.y) * (currentPos.x - _this.startCoords.x) > 0) {
|
let outX = startCoords.x + dist * Math.cos(angle45);
|
||||||
outX = _this.startCoords.x + (currentPos.y - _this.startCoords.y);
|
let outY = startCoords.y - dist * Math.sin(angle45);
|
||||||
} else {
|
|
||||||
outY = _this.startCoords.x - (currentPos.y - _this.startCoords.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Point(outX, outY);
|
return new Point(outX, outY);
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user