refactor: position & Sclae

This commit is contained in:
cha0s 2022-04-05 07:31:48 -05:00
parent 535db7cd9a
commit dad1012fd8

View File

@ -170,9 +170,7 @@ function TilesPage({
}
const onValue = (
{
clientX,
clientY,
target,
position,
type,
},
) => {
@ -180,11 +178,7 @@ function TilesPage({
switch (type) {
case 'touchstart':
case 'mousedown': {
const {left, top} = target.getBoundingClientRect();
const clamped = Vector.mul(
tileSize,
Vector.floor(Vector.div([clientX - left, clientY - top], tileSize)),
);
const clamped = Vector.mul(tileSize, Vector.floor(Vector.div(position, tileSize)));
setIncident(clamped);
setSelection(Rectangle.compose(clamped, tileSize));
setIsHolding(true);
@ -193,12 +187,7 @@ function TilesPage({
case 'touchmove':
case 'mousemove': {
if (isHolding) {
const {left, top} = target.getBoundingClientRect();
const tileSize = [16, 16];
const clamped = Vector.mul(
tileSize,
Vector.floor(Vector.div([clientX - left, clientY - top], tileSize)),
);
const clamped = Vector.mul(tileSize, Vector.floor(Vector.div(position, tileSize)));
const min = Vector.min(clamped, incident);
const max = Vector.max(clamped, incident);
setSelection(Rectangle.compose(min, Vector.add(tileSize, Vector.sub(max, min))));
@ -304,7 +293,7 @@ function TilesPage({
ref={onRef}
renderer={renderer}
renderable={container}
scalable={false}
scale={1}
size={viewport}
/>
</div>