(null)
const pos = posWithinBase(posRatio, parentBase)
@@ -325,10 +466,10 @@ function ControlPoint({
const pointPos = middlePos(ref.current!.getBoundingClientRect())
onMoves(ratioWithinBase(pointPos, parentBase))
}}
- position={{ x: pos.x - radius, y: pos.y - radius }}>
+ position={{x: pos.x - radius, y: pos.y - radius}}>
{
if (e.key == "Delete") {
- onPosValidated(undefined)
+ onRemove()
}
}}
tabIndex={0}
diff --git a/front/components/arrows/Box.ts b/front/components/arrows/Box.ts
new file mode 100644
index 0000000..6fd7548
--- /dev/null
+++ b/front/components/arrows/Box.ts
@@ -0,0 +1,35 @@
+import {Pos} from "./Pos";
+
+
+export interface Box {
+ x: number,
+ y: number,
+ width: number,
+ height: number
+}
+
+export function boundsOf(...positions: Pos[]): Box {
+
+ const allPosX = positions.map(p => p.x)
+ const allPosY = positions.map(p => p.y)
+
+ const x = Math.min(...allPosX)
+ const y = Math.min(...allPosY)
+ const width = Math.max(...allPosX) - x
+ const height = Math.max(...allPosY) - y
+
+ return {x, y, width, height}
+}
+
+export function surrounds(pos: Pos, width: number, height: number): Box {
+ return {
+ x: pos.x + (width / 2),
+ y: pos.y + (height / 2),
+ width,
+ height
+ }
+}
+
+export function contains(box: Box, pos: Pos): boolean {
+ return (pos.x >= box.x && pos.x <= box.x + box.width && pos.y >= box.y && pos.y <= box.y + box.height)
+}
\ No newline at end of file
diff --git a/front/components/arrows/Pos.ts b/front/components/arrows/Pos.ts
index bb59627..08ddc7a 100644
--- a/front/components/arrows/Pos.ts
+++ b/front/components/arrows/Pos.ts
@@ -3,7 +3,7 @@ export interface Pos {
y: number
}
-export const NULL_POS: Pos = { x: 0, y: 0 }
+export const NULL_POS: Pos = {x: 0, y: 0}
/**
* Returns position of a relative to b
@@ -11,7 +11,7 @@ export const NULL_POS: Pos = { x: 0, y: 0 }
* @param b
*/
export function relativeTo(a: Pos, b: Pos): Pos {
- return { x: a.x - b.x, y: a.y - b.y }
+ return {x: a.x - b.x, y: a.y - b.y}
}
/**
@@ -19,20 +19,24 @@ export function relativeTo(a: Pos, b: Pos): Pos {
* @param rect
*/
export function middlePos(rect: DOMRect): Pos {
- return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 }
+ return {x: rect.x + rect.width / 2, y: rect.y + rect.height / 2}
}
-/**
- * Returns x and y distance between given two pos
- * @param a
- * @param b
- */
-export function size(a: Pos, b: Pos): Pos {
- return { x: Math.abs(a.x - b.x), y: Math.abs(a.y - b.y) }
-}
export function add(a: Pos, b: Pos): Pos {
- return { x: a.x + b.x, y: a.y + b.y }
+ return {x: a.x + b.x, y: a.y + b.y}
+}
+
+export function minus(a: Pos, b: Pos): Pos {
+ return {x: a.x - b.x, y: a.y - b.y}
+}
+
+export function mul(a: Pos, t: number): Pos {
+ return {x: a.x * t, y: a.y * t}
+}
+
+export function distance(a: Pos, b: Pos): number {
+ return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2)
}
export function angle(a: Pos, b: Pos): number {
@@ -53,3 +57,10 @@ export function posWithinBase(ratio: Pos, base: DOMRect): Pos {
y: ratio.y * base.height,
}
}
+
+export function between(a: Pos, b: Pos): Pos {
+ return {
+ x: a.x / 2 + b.x / 2,
+ y: a.y / 2 + b.y / 2
+ }
+}
\ No newline at end of file
diff --git a/front/style/bendable_arrows.css b/front/style/bendable_arrows.css
index ad9fb83..65325f8 100644
--- a/front/style/bendable_arrows.css
+++ b/front/style/bendable_arrows.css
@@ -1,4 +1,4 @@
-.arrow-edge-control-point {
+.arrow-point {
cursor: pointer;
border-radius: 100px;
@@ -6,7 +6,7 @@
outline: none;
}
-.arrow-edge-control-point:hover {
+.arrow-point:hover {
background-color: var(--selection-color);
}
diff --git a/front/views/Editor.tsx b/front/views/Editor.tsx
index 610a3ab..7bd1a4c 100644
--- a/front/views/Editor.tsx
+++ b/front/views/Editor.tsx
@@ -453,7 +453,6 @@ function EditorView({
onActionDeleted={() => {
setContent((content) => ({
...content,
- players: content.players,
actions: content.actions.toSpliced(
i,
1,