apply suggestions
continuous-integration/drone/push Build is failing Details

pull/82/head
maxime.batista 1 year ago
parent 768eae92ad
commit ec46fb78a2

@ -11,7 +11,7 @@ import {
import { import {
add, add,
angle, angle,
between, middle,
distance, distance,
middlePos, middlePos,
minus, minus,
@ -20,7 +20,7 @@ import {
posWithinBase, posWithinBase,
ratioWithinBase, ratioWithinBase,
relativeTo, relativeTo,
size, norm,
} from "./Pos" } from "./Pos"
import "../../style/bendable_arrows.css" import "../../style/bendable_arrows.css"
@ -137,14 +137,14 @@ export default function BendableArrow({
if (idx == 0) { if (idx == 0) {
return { return {
start: startPos, start: startPos,
controlPoint: segment.controlPoint, controlPoint: segment.controlPoint ?? null,
end: segment.next, end: segment.next,
} }
} }
const start = segments[idx - 1].next const start = segments[idx - 1].next
return { return {
start, start,
controlPoint: segment.controlPoint, controlPoint: segment.controlPoint ?? null,
end: segment.next, end: segment.next,
} }
}) })
@ -164,15 +164,15 @@ export default function BendableArrow({
const cpPos = const cpPos =
controlPoint || controlPoint ||
ratioWithinBase( ratioWithinBase(
add(between(prevRelative, nextRelative), parentBase), add(middle(prevRelative, nextRelative), parentBase),
parentBase, parentBase,
) )
const setControlPointPos = (newPos: Pos | undefined) => { const setControlPointPos = (newPos: Pos | null) => {
const segment = segments[i] const segment = segments[i]
const newSegments = segments.toSpliced(i, 1, { const newSegments = segments.toSpliced(i, 1, {
...segment, ...segment,
controlPoint: newPos, controlPoint: newPos ?? undefined,
}) })
onSegmentsChanges(newSegments) onSegmentsChanges(newSegments)
} }
@ -185,7 +185,7 @@ export default function BendableArrow({
posRatio={cpPos} posRatio={cpPos}
parentBase={parentBase} parentBase={parentBase}
onPosValidated={setControlPointPos} onPosValidated={setControlPointPos}
onRemove={() => setControlPointPos(undefined)} onRemove={() => setControlPointPos(null)}
onMoves={(controlPoint) => { onMoves={(controlPoint) => {
setInternalSegments((is) => { setInternalSegments((is) => {
return is.toSpliced(i, 1, { return is.toSpliced(i, 1, {
@ -322,7 +322,7 @@ export default function BendableArrow({
posWithinBase(controlPoint, parentBase), posWithinBase(controlPoint, parentBase),
svgPosRelativeToBase, svgPosRelativeToBase,
) )
: between(startRelative, nextRelative) : middle(startRelative, nextRelative)
return { return {
start: startRelative, start: startRelative,
@ -344,7 +344,7 @@ export default function BendableArrow({
const previousSegmentCpAndCurrentPosVector = minus( const previousSegmentCpAndCurrentPosVector = minus(
start, start,
previousSegment?.cp ?? between(start, end), previousSegment?.cp ?? middle(start, end),
) )
const smoothCp = previousSegment const smoothCp = previousSegment
@ -422,7 +422,7 @@ export default function BendableArrow({
const nextPos = segment.next const nextPos = segment.next
const segmentCp = segment.controlPoint const segmentCp = segment.controlPoint
? segment.controlPoint ? segment.controlPoint
: between(currentPos, nextPos) : middle(currentPos, nextPos)
const smoothCp = beforeSegment const smoothCp = beforeSegment
? add( ? add(
@ -430,7 +430,7 @@ export default function BendableArrow({
minus( minus(
currentPos, currentPos,
beforeSegment.controlPoint ?? beforeSegment.controlPoint ??
between(beforeSegmentPos, currentPos), middle(beforeSegmentPos, currentPos),
), ),
) )
: segmentCp : segmentCp
@ -549,7 +549,7 @@ enum PointSegmentSearchResult {
interface FullSegment { interface FullSegment {
start: Pos start: Pos
controlPoint: Pos | undefined controlPoint: Pos | null
end: Pos end: Pos
} }
@ -573,7 +573,7 @@ function wavyBezier(
): string { ): string {
function getVerticalAmplification(t: number): Pos { function getVerticalAmplification(t: number): Pos {
const velocity = cubicBeziersDerivative(start, cp1, cp2, end, t) const velocity = cubicBeziersDerivative(start, cp1, cp2, end, t)
const velocityLength = size(velocity) const velocityLength = norm(velocity)
//rotate the velocity by 90 deg //rotate the velocity by 90 deg
const projection = { x: velocity.y, y: -velocity.x } const projection = { x: velocity.y, y: -velocity.x }

@ -38,7 +38,7 @@ export function distance(a: Pos, b: Pos): number {
return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2) return Math.sqrt((a.x - b.x) ** 2 + (a.y - b.y) ** 2)
} }
export function size(vector: Pos): number { export function norm(vector: Pos): number {
return distance(NULL_POS, vector) return distance(NULL_POS, vector)
} }
@ -66,16 +66,16 @@ export function posWithinBase(ratio: Pos, base: DOMRect): Pos {
} }
} }
export function between(a: Pos, b: Pos): Pos { export function middle(a: Pos, b: Pos): Pos {
return { return {
x: a.x / 2 + b.x / 2, x: a.x / 2 + b.x / 2,
y: a.y / 2 + b.y / 2, y: a.y / 2 + b.y / 2,
} }
} }
export function rotate(vec: Pos, deg: number): Pos { export function rotate(vec: Pos, rad: number): Pos {
return { return {
x: Math.cos(deg * vec.x) - Math.sin(deg * vec.y), x: Math.cos(rad) * vec.x - Math.sin(rad) * vec.y,
y: Math.sin(deg * vec.x) + Math.cos(deg * vec.y), y: Math.sin(rad) * vec.x + Math.cos(rad) * vec.y,
} }
} }

@ -1,5 +1,3 @@
import React from "react"
import "../../style/ball.css" import "../../style/ball.css"
import BallSvg from "../../assets/icon/ball.svg?react" import BallSvg from "../../assets/icon/ball.svg?react"

@ -5,13 +5,13 @@ import { PlayerPiece } from "./PlayerPiece"
import { Player } from "../../tactic/Player" import { Player } from "../../tactic/Player"
import { NULL_POS, ratioWithinBase } from "../arrows/Pos" import { NULL_POS, ratioWithinBase } from "../arrows/Pos"
export interface PlayerProps<A extends ReactNode> { export interface PlayerProps {
player: Player player: Player
onDrag: () => void onDrag: () => void
onChange: (p: Player) => void onChange: (p: Player) => void
onRemove: () => void onRemove: () => void
courtRef: RefObject<HTMLElement> courtRef: RefObject<HTMLElement>
availableActions: (ro: HTMLElement) => A[] availableActions: (ro: HTMLElement) => ReactNode[]
} }
/** /**
@ -24,7 +24,7 @@ export default function CourtPlayer<A extends ReactNode>({
onRemove, onRemove,
courtRef, courtRef,
availableActions, availableActions,
}: PlayerProps<A>) { }: PlayerProps) {
const hasBall = player.hasBall const hasBall = player.hasBall
const x = player.rightRatio const x = player.rightRatio
const y = player.bottomRatio const y = player.bottomRatio

@ -1,4 +1,3 @@
import React from "react"
import "../../style/player.css" import "../../style/player.css"
import { Team } from "../../tactic/Team" import { Team } from "../../tactic/Team"

@ -571,8 +571,8 @@ function debounceAsync<A, B>(
let task = 0 let task = 0
return (args: A) => { return (args: A) => {
clearTimeout(task) clearTimeout(task)
return new Promise((resolve) => { return new Promise((resolve, reject) => {
task = setTimeout(() => f(args).then(resolve), delay) task = setTimeout(() => f(args).then(resolve).catch(reject), delay)
}) })
} }
} }

@ -13,7 +13,6 @@
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-draggable": "^4.4.6", "react-draggable": "^4.4.6",
"react-xarrows": "^2.0.2",
"typescript": "^5.2.2", "typescript": "^5.2.2",
"vite": "^4.5.0", "vite": "^4.5.0",
"vite-plugin-css-injected-by-js": "^3.3.0" "vite-plugin-css-injected-by-js": "^3.3.0"
@ -33,7 +32,6 @@
}, },
"devDependencies": { "devDependencies": {
"@vitejs/plugin-react": "^4.1.0", "@vitejs/plugin-react": "^4.1.0",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^3.1.0", "prettier": "^3.1.0",
"typescript": "^5.2.2", "typescript": "^5.2.2",
"vite-plugin-svgr": "^4.1.0" "vite-plugin-svgr": "^4.1.0"

Loading…
Cancel
Save