renames shapes -> shape utils

canvas-rendering
Steve Ruiz 2021-05-20 10:49:40 +01:00
rodzic eea9af5f31
commit 10b0c50294
22 zmienionych plików z 29 dodań i 48 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
import React, { useCallback, useRef, memo } from "react" import React, { useCallback, useRef, memo } from "react"
import state, { useSelector } from "state" import state, { useSelector } from "state"
import inputs from "state/inputs" import inputs from "state/inputs"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
import styled from "styles" import styled from "styles"
function Shape({ id }: { id: string }) { function Shape({ id }: { id: string }) {

Wyświetl plik

@ -1,5 +1,5 @@
import { Shape } from "types" import { Shape } from "types"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
import * as vec from "utils/vec" import * as vec from "utils/vec"
import Vector from "./vector" import Vector from "./vector"
import { vectorToPoint } from "utils/utils" import { vectorToPoint } from "utils/utils"

Wyświetl plik

@ -1,13 +1,13 @@
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 { CircleShape, ShapeType, TransformCorner, TransformEdge } from "types" import { CircleShape, ShapeType, TransformCorner, TransformEdge } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { boundsContained } from "utils/bounds" import { boundsContained } from "utils/bounds"
import { intersectCircleBounds } from "utils/intersections" import { intersectCircleBounds } from "utils/intersections"
import { pointInCircle } from "utils/hitTests" import { pointInCircle } from "utils/hitTests"
import { getTransformAnchor, translateBounds } from "utils/utils" import { getTransformAnchor, translateBounds } from "utils/utils"
const circle = createShape<CircleShape>({ const circle = registerShapeUtils<CircleShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -1,14 +1,14 @@
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 { DotShape, ShapeType } from "types" import { DotShape, ShapeType } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { boundsContained } from "utils/bounds" import { boundsContained } from "utils/bounds"
import { intersectCircleBounds } from "utils/intersections" import { intersectCircleBounds } from "utils/intersections"
import styled from "styles" import styled from "styles"
import { DotCircle } from "components/canvas/misc" import { DotCircle } from "components/canvas/misc"
import { translateBounds } from "utils/utils" import { translateBounds } from "utils/utils"
const dot = createShape<DotShape>({ const dot = registerShapeUtils<DotShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -1,7 +1,7 @@
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 { EllipseShape, ShapeType } from "types" import { EllipseShape, ShapeType } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { boundsContained } from "utils/bounds" import { boundsContained } from "utils/bounds"
import { intersectEllipseBounds } from "utils/intersections" import { intersectEllipseBounds } from "utils/intersections"
import { pointInEllipse } from "utils/hitTests" import { pointInEllipse } from "utils/hitTests"
@ -12,7 +12,7 @@ import {
translateBounds, translateBounds,
} from "utils/utils" } from "utils/utils"
const ellipse = createShape<EllipseShape>({ const ellipse = registerShapeUtils<EllipseShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -114,7 +114,7 @@ export function getShapeUtils(shape: Shape): ShapeUtility<typeof shape> {
* @param shape * @param shape
* @returns * @returns
*/ */
export function createShape<T extends Shape>( export function registerShapeUtils<T extends Shape>(
shape: ShapeUtility<T> shape: ShapeUtility<T>
): ShapeUtility<T> { ): ShapeUtility<T> {
return Object.freeze(shape) return Object.freeze(shape)

Wyświetl plik

@ -1,13 +1,13 @@
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 { LineShape, ShapeType } from "types" import { LineShape, ShapeType } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { boundsContained } from "utils/bounds" import { boundsContained } from "utils/bounds"
import { intersectCircleBounds } from "utils/intersections" import { intersectCircleBounds } from "utils/intersections"
import { DotCircle } from "components/canvas/misc" import { DotCircle } from "components/canvas/misc"
import { translateBounds } from "utils/utils" import { translateBounds } from "utils/utils"
const line = createShape<LineShape>({ const line = registerShapeUtils<LineShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -1,7 +1,7 @@
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 { PolylineShape, ShapeType } from "types" import { PolylineShape, ShapeType } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { intersectPolylineBounds } from "utils/intersections" import { intersectPolylineBounds } from "utils/intersections"
import { import {
boundsCollide, boundsCollide,
@ -10,7 +10,7 @@ import {
} from "utils/bounds" } from "utils/bounds"
import { getBoundsFromPoints, translateBounds } from "utils/utils" import { getBoundsFromPoints, translateBounds } from "utils/utils"
const polyline = createShape<PolylineShape>({ const polyline = registerShapeUtils<PolylineShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -1,13 +1,13 @@
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 { RayShape, ShapeType } from "types" import { RayShape, ShapeType } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { boundsContained } from "utils/bounds" import { boundsContained } from "utils/bounds"
import { intersectCircleBounds } from "utils/intersections" import { intersectCircleBounds } from "utils/intersections"
import { DotCircle } from "components/canvas/misc" import { DotCircle } from "components/canvas/misc"
import { translateBounds } from "utils/utils" import { translateBounds } from "utils/utils"
const ray = createShape<RayShape>({ const ray = registerShapeUtils<RayShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -6,7 +6,7 @@ import {
TransformCorner, TransformCorner,
TransformEdge, TransformEdge,
} from "types" } from "types"
import { createShape } from "./index" import { registerShapeUtils } from "./index"
import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds" import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds"
import { import {
getBoundsFromPoints, getBoundsFromPoints,
@ -15,7 +15,7 @@ import {
translateBounds, translateBounds,
} from "utils/utils" } from "utils/utils"
const rectangle = createShape<RectangleShape>({ const rectangle = registerShapeUtils<RectangleShape>({
boundsCache: new WeakMap([]), boundsCache: new WeakMap([]),
create(props) { create(props) {

Wyświetl plik

@ -1,19 +0,0 @@
import { Bounds, Shape } from "types"
export default interface ShapeUtil<K extends Shape> {
create(props: Partial<K>): K
getBounds(this: ShapeUtil<K>, shape: K): Bounds
hitTest(this: ShapeUtil<K>, shape: K, test: number[]): boolean
hitTestBounds(this: ShapeUtil<K>, shape: K, bounds: Bounds): boolean
rotate(this: ShapeUtil<K>, shape: K): K
translate(this: ShapeUtil<K>, shape: K, delta: number[]): K
scale(this: ShapeUtil<K>, shape: K, scale: number): K
stretch(this: ShapeUtil<K>, shape: K, scaleX: number, scaleY: number): K
render(this: ShapeUtil<K>, shape: K): JSX.Element
}
export function createShape<T extends Shape>(
shape: ShapeUtil<T>
): ShapeUtil<T> {
return shape
}

Wyświetl plik

@ -2,7 +2,7 @@ import Command from "./command"
import history from "../history" import history from "../history"
import { Data, Shape } from "types" import { Data, Shape } from "types"
export default function createShapeCommand(data: Data, shape: Shape) { export default function registerShapeUtilsCommand(data: Data, shape: Shape) {
const { currentPageId } = data const { currentPageId } = data
history.execute( history.execute(

Wyświetl plik

@ -2,7 +2,7 @@ import translate from "./translate"
import transform from "./transform" import transform from "./transform"
import transformSingle from "./transform-single" import transformSingle from "./transform-single"
import generate from "./generate" import generate from "./generate"
import createShape from "./create-shape" import registerShapeUtils from "./create-shape"
import direct from "./direct" import direct from "./direct"
import rotate from "./rotate" import rotate from "./rotate"
@ -11,7 +11,7 @@ const commands = {
transform, transform,
transformSingle, transformSingle,
generate, generate,
createShape, registerShapeUtils,
direct, direct,
rotate, rotate,
} }

Wyświetl plik

@ -1,7 +1,7 @@
import Command from "./command" import Command from "./command"
import history from "../history" import history from "../history"
import { Data, TransformCorner, TransformEdge } from "types" import { Data, TransformCorner, TransformEdge } from "types"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
import { current } from "immer" import { current } from "immer"
import { TransformSingleSnapshot } from "state/sessions/transform-single-session" import { TransformSingleSnapshot } from "state/sessions/transform-single-session"

Wyświetl plik

@ -2,7 +2,7 @@ import Command from "./command"
import history from "../history" import history from "../history"
import { Data, TransformCorner, TransformEdge } from "types" import { Data, TransformCorner, TransformEdge } from "types"
import { TransformSnapshot } from "state/sessions/transform-session" import { TransformSnapshot } from "state/sessions/transform-session"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
export default function transformCommand( export default function transformCommand(
data: Data, data: Data,

Wyświetl plik

@ -1,5 +1,5 @@
import { Data, ShapeType } from "types" import { Data, ShapeType } from "types"
import shapeUtils from "lib/shapes" import shapeUtils from "lib/shape-utils"
export const defaultDocument: Data["document"] = { export const defaultDocument: Data["document"] = {
pages: { pages: {

Wyświetl plik

@ -1,7 +1,7 @@
import { current } from "immer" import { current } from "immer"
import { ShapeUtil, Bounds, Data, Shapes } from "types" import { ShapeUtil, Bounds, Data, Shapes } from "types"
import BaseSession from "./base-session" import BaseSession from "./base-session"
import shapes, { getShapeUtils } from "lib/shapes" import shapes, { getShapeUtils } from "lib/shape-utils"
import { getBoundsFromPoints } from "utils/utils" import { getBoundsFromPoints } from "utils/utils"
import * as vec from "utils/vec" import * as vec from "utils/vec"

Wyświetl plik

@ -4,7 +4,7 @@ import BaseSession from "./base-session"
import commands from "state/commands" import commands from "state/commands"
import { current } from "immer" import { current } from "immer"
import { getCommonBounds } from "utils/utils" import { getCommonBounds } from "utils/utils"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
export default class RotateSession extends BaseSession { export default class RotateSession extends BaseSession {
delta = [0, 0] delta = [0, 0]

Wyświetl plik

@ -3,7 +3,7 @@ import * as vec from "utils/vec"
import BaseSession from "./base-session" import BaseSession from "./base-session"
import commands from "state/commands" import commands from "state/commands"
import { current } from "immer" import { current } from "immer"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
import { import {
getCommonBounds, getCommonBounds,
getRelativeTransformedBoundingBox, getRelativeTransformedBoundingBox,

Wyświetl plik

@ -3,7 +3,7 @@ import * as vec from "utils/vec"
import BaseSession from "./base-session" import BaseSession from "./base-session"
import commands from "state/commands" import commands from "state/commands"
import { current } from "immer" import { current } from "immer"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
import { import {
getTransformedBoundingBox, getTransformedBoundingBox,
getCommonBounds, getCommonBounds,

Wyświetl plik

@ -12,7 +12,7 @@ import {
} from "types" } from "types"
import inputs from "./inputs" import inputs from "./inputs"
import { defaultDocument } from "./data" import { defaultDocument } from "./data"
import shapeUtilityMap, { getShapeUtils } from "lib/shapes" import shapeUtilityMap, { getShapeUtils } from "lib/shape-utils"
import history from "state/history" import history from "state/history"
import * as Sessions from "./sessions" import * as Sessions from "./sessions"
import commands from "./commands" import commands from "./commands"

Wyświetl plik

@ -1,5 +1,5 @@
import Vector from "lib/code/vector" import Vector from "lib/code/vector"
import { getShapeUtils } from "lib/shapes" import { getShapeUtils } from "lib/shape-utils"
import React from "react" import React from "react"
import { Data, Bounds, TransformEdge, TransformCorner, Shape } from "types" import { Data, Bounds, TransformEdge, TransformCorner, Shape } from "types"
import * as svg from "./svg" import * as svg from "./svg"