renames shapes -> shape utils

This commit is contained in:
Steve Ruiz 2021-05-20 10:49:40 +01:00
parent eea9af5f31
commit 10b0c50294
22 changed files with 29 additions and 48 deletions

View file

@ -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 }) {

View file

@ -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"

View file

@ -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<CircleShape>({
const circle = registerShapeUtils<CircleShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

@ -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<DotShape>({
const dot = registerShapeUtils<DotShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

@ -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<EllipseShape>({
const ellipse = registerShapeUtils<EllipseShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

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

View file

@ -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<LineShape>({
const line = registerShapeUtils<LineShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

@ -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<PolylineShape>({
const polyline = registerShapeUtils<PolylineShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

@ -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<RayShape>({
const ray = registerShapeUtils<RayShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

@ -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<RectangleShape>({
const rectangle = registerShapeUtils<RectangleShape>({
boundsCache: new WeakMap([]),
create(props) {

View file

@ -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
}

View file

@ -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(

View file

@ -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,
}

View file

@ -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"

View file

@ -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,

View file

@ -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: {

View file

@ -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"

View file

@ -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]

View file

@ -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,

View file

@ -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,

View file

@ -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"

View file

@ -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"