clean transforms

canvas-rendering
Steve Ruiz 2021-05-22 21:35:01 +01:00
rodzic b752782753
commit 3310f1a94c
2 zmienionych plików z 20 dodań i 26 usunięć

Wyświetl plik

@ -1,14 +1,11 @@
import { v4 as uuid } from "uuid"
import * as vec from "utils/vec"
import { RectangleShape, ShapeType, Corner, Edge } from "types"
import { RectangleShape, ShapeType } from "types"
import { registerShapeUtils } from "./index"
import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds"
import {
getBoundsFromPoints,
getRotatedCorners,
getRotatedSize,
lerp,
rotateBounds,
translateBounds,
} from "utils/utils"
@ -98,16 +95,9 @@ const rectangle = registerShapeUtils<RectangleShape>({
transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
if (shape.rotation === 0) {
shape.size = [bounds.width, bounds.height]
shape.point = [bounds.minX, bounds.minY]
shape.size = [bounds.width, bounds.height]
} else {
// Size
shape.size = vec.mul(
initialShape.size,
Math.min(Math.abs(scaleX), Math.abs(scaleY))
)
// Point
shape.point = [
bounds.minX +
(bounds.width - shape.size[0]) *
@ -117,7 +107,11 @@ const rectangle = registerShapeUtils<RectangleShape>({
(scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]),
]
// Rotation
shape.size = vec.mul(
initialShape.size,
Math.min(Math.abs(scaleX), Math.abs(scaleY))
)
shape.rotation =
(scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0)
? -initialShape.rotation

Wyświetl plik

@ -66,19 +66,6 @@ export default class TransformSession extends BaseSession {
const shape = shapes[id]
// const transformOrigins = {
// [Edge.Top]: [0.5, 1],
// [Edge.Right]: [0, 0.5],
// [Edge.Bottom]: [0.5, 0],
// [Edge.Left]: [1, 0.5],
// [Corner.TopLeft]: [1, 1],
// [Corner.TopRight]: [0, 1],
// [Corner.BottomLeft]: [1, 0],
// [Corner.BottomRight]: [0, 0],
// }
// const origin = transformOrigins[this.transformType]
getShapeUtils(shape).transform(shape, newShapeBounds, {
type: this.transformType,
initialShape,
@ -177,3 +164,16 @@ export function getTransformSnapshot(
}
export type TransformSnapshot = ReturnType<typeof getTransformSnapshot>
// const transformOrigins = {
// [Edge.Top]: [0.5, 1],
// [Edge.Right]: [0, 0.5],
// [Edge.Bottom]: [0.5, 0],
// [Edge.Left]: [1, 0.5],
// [Corner.TopLeft]: [1, 1],
// [Corner.TopRight]: [0, 1],
// [Corner.BottomLeft]: [1, 0],
// [Corner.BottomRight]: [0, 0],
// }
// const origin = transformOrigins[this.transformType]