1
0
Fork 0

use subject to reduce number of variables that all sound like the same thing

This commit is contained in:
Enoch Riese 2022-06-28 13:29:00 -05:00
parent 8f35ccf9b9
commit e21ffa4bc8

View file

@ -120,10 +120,6 @@ const angle = (pointA, pointB) => {
} }
const generateTransform = (x, y, rot, flipX, flipY, part) => { const generateTransform = (x, y, rot, flipX, flipY, part) => {
// const anchor = {
// x: 0,
// y: 0
// }
const center = { const center = {
x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2, x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2,
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2, y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
@ -175,7 +171,6 @@ const Part = props => {
let translateY = partLayout.move.y let translateY = partLayout.move.y
let partRotation = partLayout.rotate || 0; let partRotation = partLayout.rotate || 0;
let rotation = partRotation; let rotation = partRotation;
let startRotation = 0;
let flipX = partLayout.flipX ? true : false let flipX = partLayout.flipX ? true : false
let flipY = partLayout.flipY ? true : false let flipY = partLayout.flipY ? true : false
let partRect let partRect
@ -185,21 +180,18 @@ const Part = props => {
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2, y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
} }
const getRotation = (event) => angle(center, { x:event.x, y: event.y }); const getRotation = (event) => angle(center, event.subject) - angle(center, { x:event.x, y: event.y });
const handleDrag = drag() const handleDrag = drag()
.subject(function() { .subject(function(event) {
return { x: translateX, y: translateY } return rotate ? { x: event.x, y: event.y } : {x: translateX, y: translateY}
}) })
.on('start', function(event) { .on('start', function(event) {
partRect = partRef.current.getBoundingClientRect() partRect = partRef.current.getBoundingClientRect()
console.log(layout.parts[name].rotate, partLayout.rotate);
partRotation = partLayout.rotate || 0;
startRotation = getRotation(event);
}) })
.on('drag', function(event) { .on('drag', function(event) {
if (rotate) { if (rotate) {
let newRotation = startRotation - getRotation(event); let newRotation = getRotation(event);
if (flipX) newRotation *= -1 if (flipX) newRotation *= -1
if (flipY) newRotation *= -1 if (flipY) newRotation *= -1
rotation = partRotation + newRotation rotation = partRotation + newRotation