clean transforms
This commit is contained in:
parent
b752782753
commit
3310f1a94c
2 changed files with 20 additions and 26 deletions
|
@ -1,14 +1,11 @@
|
||||||
import { v4 as uuid } from "uuid"
|
import { v4 as uuid } from "uuid"
|
||||||
import * as vec from "utils/vec"
|
import * as vec from "utils/vec"
|
||||||
import { RectangleShape, ShapeType, Corner, Edge } from "types"
|
import { RectangleShape, ShapeType } from "types"
|
||||||
import { registerShapeUtils } from "./index"
|
import { registerShapeUtils } from "./index"
|
||||||
import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds"
|
import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds"
|
||||||
import {
|
import {
|
||||||
getBoundsFromPoints,
|
getBoundsFromPoints,
|
||||||
getRotatedCorners,
|
getRotatedCorners,
|
||||||
getRotatedSize,
|
|
||||||
lerp,
|
|
||||||
rotateBounds,
|
|
||||||
translateBounds,
|
translateBounds,
|
||||||
} from "utils/utils"
|
} from "utils/utils"
|
||||||
|
|
||||||
|
@ -98,16 +95,9 @@ const rectangle = registerShapeUtils<RectangleShape>({
|
||||||
|
|
||||||
transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
|
transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
|
||||||
if (shape.rotation === 0) {
|
if (shape.rotation === 0) {
|
||||||
shape.size = [bounds.width, bounds.height]
|
|
||||||
shape.point = [bounds.minX, bounds.minY]
|
shape.point = [bounds.minX, bounds.minY]
|
||||||
|
shape.size = [bounds.width, bounds.height]
|
||||||
} else {
|
} else {
|
||||||
// Size
|
|
||||||
shape.size = vec.mul(
|
|
||||||
initialShape.size,
|
|
||||||
Math.min(Math.abs(scaleX), Math.abs(scaleY))
|
|
||||||
)
|
|
||||||
|
|
||||||
// Point
|
|
||||||
shape.point = [
|
shape.point = [
|
||||||
bounds.minX +
|
bounds.minX +
|
||||||
(bounds.width - shape.size[0]) *
|
(bounds.width - shape.size[0]) *
|
||||||
|
@ -117,7 +107,11 @@ const rectangle = registerShapeUtils<RectangleShape>({
|
||||||
(scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]),
|
(scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]),
|
||||||
]
|
]
|
||||||
|
|
||||||
// Rotation
|
shape.size = vec.mul(
|
||||||
|
initialShape.size,
|
||||||
|
Math.min(Math.abs(scaleX), Math.abs(scaleY))
|
||||||
|
)
|
||||||
|
|
||||||
shape.rotation =
|
shape.rotation =
|
||||||
(scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0)
|
(scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0)
|
||||||
? -initialShape.rotation
|
? -initialShape.rotation
|
||||||
|
|
|
@ -66,19 +66,6 @@ export default class TransformSession extends BaseSession {
|
||||||
|
|
||||||
const shape = shapes[id]
|
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, {
|
getShapeUtils(shape).transform(shape, newShapeBounds, {
|
||||||
type: this.transformType,
|
type: this.transformType,
|
||||||
initialShape,
|
initialShape,
|
||||||
|
@ -177,3 +164,16 @@ export function getTransformSnapshot(
|
||||||
}
|
}
|
||||||
|
|
||||||
export type TransformSnapshot = ReturnType<typeof 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]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue