From 10b0c50294fed1201fda7e2df109279d8ca815c5 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Thu, 20 May 2021 10:49:40 +0100 Subject: [PATCH] renames shapes -> shape utils --- components/canvas/shape.tsx | 2 +- lib/code/index.ts | 2 +- lib/{shapes => shape-utils}/circle.tsx | 4 ++-- lib/{shapes => shape-utils}/dot.tsx | 4 ++-- lib/{shapes => shape-utils}/ellipse.tsx | 4 ++-- lib/{shapes => shape-utils}/index.tsx | 2 +- lib/{shapes => shape-utils}/line.tsx | 4 ++-- lib/{shapes => shape-utils}/polyline.tsx | 4 ++-- lib/{shapes => shape-utils}/ray.tsx | 4 ++-- lib/{shapes => shape-utils}/rectangle.tsx | 4 ++-- lib/shapes/base-shape.tsx | 19 ------------------- state/commands/create-shape.ts | 2 +- state/commands/index.ts | 4 ++-- state/commands/transform-single.ts | 2 +- state/commands/transform.ts | 2 +- state/data.ts | 2 +- state/sessions/brush-session.ts | 2 +- state/sessions/rotate-session.ts | 2 +- state/sessions/transform-session.ts | 2 +- state/sessions/transform-single-session.ts | 2 +- state/state.ts | 2 +- utils/utils.ts | 2 +- 22 files changed, 29 insertions(+), 48 deletions(-) rename lib/{shapes => shape-utils}/circle.tsx (97%) rename lib/{shapes => shape-utils}/dot.tsx (95%) rename lib/{shapes => shape-utils}/ellipse.tsx (96%) rename lib/{shapes => shape-utils}/index.tsx (98%) rename lib/{shapes => shape-utils}/line.tsx (95%) rename lib/{shapes => shape-utils}/polyline.tsx (96%) rename lib/{shapes => shape-utils}/ray.tsx (95%) rename lib/{shapes => shape-utils}/rectangle.tsx (96%) delete mode 100644 lib/shapes/base-shape.tsx diff --git a/components/canvas/shape.tsx b/components/canvas/shape.tsx index f525fa4f9..cabc15746 100644 --- a/components/canvas/shape.tsx +++ b/components/canvas/shape.tsx @@ -1,7 +1,7 @@ import React, { useCallback, useRef, memo } from "react" import state, { useSelector } from "state" import inputs from "state/inputs" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" import styled from "styles" function Shape({ id }: { id: string }) { diff --git a/lib/code/index.ts b/lib/code/index.ts index 915b56141..f67aefd75 100644 --- a/lib/code/index.ts +++ b/lib/code/index.ts @@ -1,5 +1,5 @@ import { Shape } from "types" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" import * as vec from "utils/vec" import Vector from "./vector" import { vectorToPoint } from "utils/utils" diff --git a/lib/shapes/circle.tsx b/lib/shape-utils/circle.tsx similarity index 97% rename from lib/shapes/circle.tsx rename to lib/shape-utils/circle.tsx index 92811928d..941fc9fcb 100644 --- a/lib/shapes/circle.tsx +++ b/lib/shape-utils/circle.tsx @@ -1,13 +1,13 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { CircleShape, ShapeType, TransformCorner, TransformEdge } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { boundsContained } from "utils/bounds" import { intersectCircleBounds } from "utils/intersections" import { pointInCircle } from "utils/hitTests" import { getTransformAnchor, translateBounds } from "utils/utils" -const circle = createShape({ +const circle = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/dot.tsx b/lib/shape-utils/dot.tsx similarity index 95% rename from lib/shapes/dot.tsx rename to lib/shape-utils/dot.tsx index c3223c20d..b66e8388a 100644 --- a/lib/shapes/dot.tsx +++ b/lib/shape-utils/dot.tsx @@ -1,14 +1,14 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { DotShape, ShapeType } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { boundsContained } from "utils/bounds" import { intersectCircleBounds } from "utils/intersections" import styled from "styles" import { DotCircle } from "components/canvas/misc" import { translateBounds } from "utils/utils" -const dot = createShape({ +const dot = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/ellipse.tsx b/lib/shape-utils/ellipse.tsx similarity index 96% rename from lib/shapes/ellipse.tsx rename to lib/shape-utils/ellipse.tsx index b7bb14ee6..556b1636f 100644 --- a/lib/shapes/ellipse.tsx +++ b/lib/shape-utils/ellipse.tsx @@ -1,7 +1,7 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { EllipseShape, ShapeType } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { boundsContained } from "utils/bounds" import { intersectEllipseBounds } from "utils/intersections" import { pointInEllipse } from "utils/hitTests" @@ -12,7 +12,7 @@ import { translateBounds, } from "utils/utils" -const ellipse = createShape({ +const ellipse = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/index.tsx b/lib/shape-utils/index.tsx similarity index 98% rename from lib/shapes/index.tsx rename to lib/shape-utils/index.tsx index bbccca952..f8decc40c 100644 --- a/lib/shapes/index.tsx +++ b/lib/shape-utils/index.tsx @@ -114,7 +114,7 @@ export function getShapeUtils(shape: Shape): ShapeUtility { * @param shape * @returns */ -export function createShape( +export function registerShapeUtils( shape: ShapeUtility ): ShapeUtility { return Object.freeze(shape) diff --git a/lib/shapes/line.tsx b/lib/shape-utils/line.tsx similarity index 95% rename from lib/shapes/line.tsx rename to lib/shape-utils/line.tsx index da50e8916..5590659a7 100644 --- a/lib/shapes/line.tsx +++ b/lib/shape-utils/line.tsx @@ -1,13 +1,13 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { LineShape, ShapeType } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { boundsContained } from "utils/bounds" import { intersectCircleBounds } from "utils/intersections" import { DotCircle } from "components/canvas/misc" import { translateBounds } from "utils/utils" -const line = createShape({ +const line = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/polyline.tsx b/lib/shape-utils/polyline.tsx similarity index 96% rename from lib/shapes/polyline.tsx rename to lib/shape-utils/polyline.tsx index 1508df448..a9729f60e 100644 --- a/lib/shapes/polyline.tsx +++ b/lib/shape-utils/polyline.tsx @@ -1,7 +1,7 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { PolylineShape, ShapeType } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { intersectPolylineBounds } from "utils/intersections" import { boundsCollide, @@ -10,7 +10,7 @@ import { } from "utils/bounds" import { getBoundsFromPoints, translateBounds } from "utils/utils" -const polyline = createShape({ +const polyline = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/ray.tsx b/lib/shape-utils/ray.tsx similarity index 95% rename from lib/shapes/ray.tsx rename to lib/shape-utils/ray.tsx index 417bbb406..d469b6283 100644 --- a/lib/shapes/ray.tsx +++ b/lib/shape-utils/ray.tsx @@ -1,13 +1,13 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" import { RayShape, ShapeType } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { boundsContained } from "utils/bounds" import { intersectCircleBounds } from "utils/intersections" import { DotCircle } from "components/canvas/misc" import { translateBounds } from "utils/utils" -const ray = createShape({ +const ray = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/rectangle.tsx b/lib/shape-utils/rectangle.tsx similarity index 96% rename from lib/shapes/rectangle.tsx rename to lib/shape-utils/rectangle.tsx index d70bbb7e4..58b35cec7 100644 --- a/lib/shapes/rectangle.tsx +++ b/lib/shape-utils/rectangle.tsx @@ -6,7 +6,7 @@ import { TransformCorner, TransformEdge, } from "types" -import { createShape } from "./index" +import { registerShapeUtils } from "./index" import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds" import { getBoundsFromPoints, @@ -15,7 +15,7 @@ import { translateBounds, } from "utils/utils" -const rectangle = createShape({ +const rectangle = registerShapeUtils({ boundsCache: new WeakMap([]), create(props) { diff --git a/lib/shapes/base-shape.tsx b/lib/shapes/base-shape.tsx deleted file mode 100644 index 904b3735d..000000000 --- a/lib/shapes/base-shape.tsx +++ /dev/null @@ -1,19 +0,0 @@ -import { Bounds, Shape } from "types" - -export default interface ShapeUtil { - create(props: Partial): K - getBounds(this: ShapeUtil, shape: K): Bounds - hitTest(this: ShapeUtil, shape: K, test: number[]): boolean - hitTestBounds(this: ShapeUtil, shape: K, bounds: Bounds): boolean - rotate(this: ShapeUtil, shape: K): K - translate(this: ShapeUtil, shape: K, delta: number[]): K - scale(this: ShapeUtil, shape: K, scale: number): K - stretch(this: ShapeUtil, shape: K, scaleX: number, scaleY: number): K - render(this: ShapeUtil, shape: K): JSX.Element -} - -export function createShape( - shape: ShapeUtil -): ShapeUtil { - return shape -} diff --git a/state/commands/create-shape.ts b/state/commands/create-shape.ts index 4646017aa..38b820947 100644 --- a/state/commands/create-shape.ts +++ b/state/commands/create-shape.ts @@ -2,7 +2,7 @@ import Command from "./command" import history from "../history" import { Data, Shape } from "types" -export default function createShapeCommand(data: Data, shape: Shape) { +export default function registerShapeUtilsCommand(data: Data, shape: Shape) { const { currentPageId } = data history.execute( diff --git a/state/commands/index.ts b/state/commands/index.ts index 98b2f62a3..3ff025a48 100644 --- a/state/commands/index.ts +++ b/state/commands/index.ts @@ -2,7 +2,7 @@ import translate from "./translate" import transform from "./transform" import transformSingle from "./transform-single" import generate from "./generate" -import createShape from "./create-shape" +import registerShapeUtils from "./create-shape" import direct from "./direct" import rotate from "./rotate" @@ -11,7 +11,7 @@ const commands = { transform, transformSingle, generate, - createShape, + registerShapeUtils, direct, rotate, } diff --git a/state/commands/transform-single.ts b/state/commands/transform-single.ts index a94a3577e..84f9033c8 100644 --- a/state/commands/transform-single.ts +++ b/state/commands/transform-single.ts @@ -1,7 +1,7 @@ import Command from "./command" import history from "../history" import { Data, TransformCorner, TransformEdge } from "types" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" import { current } from "immer" import { TransformSingleSnapshot } from "state/sessions/transform-single-session" diff --git a/state/commands/transform.ts b/state/commands/transform.ts index fb3c195f7..5a0500a4a 100644 --- a/state/commands/transform.ts +++ b/state/commands/transform.ts @@ -2,7 +2,7 @@ import Command from "./command" import history from "../history" import { Data, TransformCorner, TransformEdge } from "types" import { TransformSnapshot } from "state/sessions/transform-session" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" export default function transformCommand( data: Data, diff --git a/state/data.ts b/state/data.ts index e518e23d6..758185f4d 100644 --- a/state/data.ts +++ b/state/data.ts @@ -1,5 +1,5 @@ import { Data, ShapeType } from "types" -import shapeUtils from "lib/shapes" +import shapeUtils from "lib/shape-utils" export const defaultDocument: Data["document"] = { pages: { diff --git a/state/sessions/brush-session.ts b/state/sessions/brush-session.ts index 8d54d9f16..8ee5309ec 100644 --- a/state/sessions/brush-session.ts +++ b/state/sessions/brush-session.ts @@ -1,7 +1,7 @@ import { current } from "immer" import { ShapeUtil, Bounds, Data, Shapes } from "types" import BaseSession from "./base-session" -import shapes, { getShapeUtils } from "lib/shapes" +import shapes, { getShapeUtils } from "lib/shape-utils" import { getBoundsFromPoints } from "utils/utils" import * as vec from "utils/vec" diff --git a/state/sessions/rotate-session.ts b/state/sessions/rotate-session.ts index d3bfa66cd..fc661ed81 100644 --- a/state/sessions/rotate-session.ts +++ b/state/sessions/rotate-session.ts @@ -4,7 +4,7 @@ import BaseSession from "./base-session" import commands from "state/commands" import { current } from "immer" import { getCommonBounds } from "utils/utils" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" export default class RotateSession extends BaseSession { delta = [0, 0] diff --git a/state/sessions/transform-session.ts b/state/sessions/transform-session.ts index 48d968f65..72848d9ed 100644 --- a/state/sessions/transform-session.ts +++ b/state/sessions/transform-session.ts @@ -3,7 +3,7 @@ import * as vec from "utils/vec" import BaseSession from "./base-session" import commands from "state/commands" import { current } from "immer" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" import { getCommonBounds, getRelativeTransformedBoundingBox, diff --git a/state/sessions/transform-single-session.ts b/state/sessions/transform-single-session.ts index 1ce94512e..a0c761358 100644 --- a/state/sessions/transform-single-session.ts +++ b/state/sessions/transform-single-session.ts @@ -3,7 +3,7 @@ import * as vec from "utils/vec" import BaseSession from "./base-session" import commands from "state/commands" import { current } from "immer" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" import { getTransformedBoundingBox, getCommonBounds, diff --git a/state/state.ts b/state/state.ts index a0fc2a512..5c87f7cdd 100644 --- a/state/state.ts +++ b/state/state.ts @@ -12,7 +12,7 @@ import { } from "types" import inputs from "./inputs" import { defaultDocument } from "./data" -import shapeUtilityMap, { getShapeUtils } from "lib/shapes" +import shapeUtilityMap, { getShapeUtils } from "lib/shape-utils" import history from "state/history" import * as Sessions from "./sessions" import commands from "./commands" diff --git a/utils/utils.ts b/utils/utils.ts index e950be8ae..952fac180 100644 --- a/utils/utils.ts +++ b/utils/utils.ts @@ -1,5 +1,5 @@ import Vector from "lib/code/vector" -import { getShapeUtils } from "lib/shapes" +import { getShapeUtils } from "lib/shape-utils" import React from "react" import { Data, Bounds, TransformEdge, TransformCorner, Shape } from "types" import * as svg from "./svg"