chore: lint files

Signed-off-by: braks <78412429+bcakmakoglu@users.noreply.github.com>
This commit is contained in:
braks
2023-03-31 20:23:32 +02:00
committed by Braks
parent 9d597ff454
commit f61e5beb02
69 changed files with 623 additions and 424 deletions

View File

@@ -13,7 +13,7 @@ export interface PointInfo {
position: Position
}
export const createGrid = (graph: GraphBoundingBox, nodes: NodeBoundingBox[], source: PointInfo, target: PointInfo) => {
export function createGrid(graph: GraphBoundingBox, nodes: NodeBoundingBox[], source: PointInfo, target: PointInfo) {
const { xMin, yMin, width, height } = graph
// Create a grid representation of the graph box, where each cell is

View File

@@ -4,13 +4,13 @@ import type { XYPosition } from '@vue-flow/core'
* Draws an SVG path from a list of points, using straight lines.
*/
const getMidPoint = (Ax: number, Ay: number, Bx: number, By: number) => {
function getMidPoint(Ax: number, Ay: number, Bx: number, By: number) {
const Zx = (Ax - Bx) / 2 + Bx
const Zy = (Ay - By) / 2 + By
return [Zx, Zy]
}
export const drawStraightLinePath = (source: XYPosition, target: XYPosition, path: number[][]) => {
export function drawStraightLinePath(source: XYPosition, target: XYPosition, path: number[][]) {
let svgPathString = `M ${source.x}, ${source.y} `
path.forEach((point) => {
@@ -23,7 +23,7 @@ export const drawStraightLinePath = (source: XYPosition, target: XYPosition, pat
return svgPathString
}
const quadraticBezierCurve = (points: number[][]) => {
function quadraticBezierCurve(points: number[][]) {
const X = 0
const Y = 1
let point = points[0]
@@ -49,7 +49,7 @@ const quadraticBezierCurve = (points: number[][]) => {
/**
* Draws a SVG path from a list of points, using rounded lines.
*/
export const drawSmoothLinePath = (source: XYPosition, target: XYPosition, path: number[][]) => {
export function drawSmoothLinePath(source: XYPosition, target: XYPosition, path: number[][]) {
const points = [[source.x, source.y], ...path, [target.x, target.y]]
return quadraticBezierCurve(points)
}

View File

@@ -12,7 +12,7 @@ declare module 'pathfinding' {
}
}
export const generatePath = (grid: Grid, start: XYPosition, end: XYPosition): number[][] => {
export function generatePath(grid: Grid, start: XYPosition, end: XYPosition): number[][] {
const finder = new AStarFinder({
diagonalMovement: DiagonalMovement.Always,
allowDiagonal: true,

View File

@@ -34,7 +34,7 @@ export interface GraphBoundingBox {
* @param roundTo If the coordinates should be rounded to this nearest integer
* @returns Graph and nodes bounding boxes.
*/
export const getBoundingBoxes = (storeNodes: GraphNode[], nodePadding = 0, graphPadding = 0, roundTo = 0) => {
export function getBoundingBoxes(storeNodes: GraphNode[], nodePadding = 0, graphPadding = 0, roundTo = 0) {
// Guarantee that the given parameters are positive integers
nodePadding = Math.max(Math.round(nodePadding), 0)
graphPadding = Math.max(Math.round(graphPadding), 0)

View File

@@ -3,7 +3,7 @@ import type { Position, XYPosition } from '@vue-flow/core'
type Direction = 'top' | 'bottom' | 'left' | 'right'
export const getNextPointFromPosition = (point: XYPosition, position: Direction): XYPosition => {
export function getNextPointFromPosition(point: XYPosition, position: Direction): XYPosition {
switch (position) {
case 'top':
return { x: point.x, y: point.y - 1 }
@@ -21,7 +21,7 @@ export const getNextPointFromPosition = (point: XYPosition, position: Direction)
* walkable area, by adding a walkable path in the direction of the point's
* Position.
*/
export const guaranteeWalkablePath = (grid: Grid, point: XYPosition, position: Position) => {
export function guaranteeWalkablePath(grid: Grid, point: XYPosition, position: Position) {
let node = grid.getNodeAt(point.x, point.y)
while (!node.walkable) {
grid.setWalkableAt(node.x, node.y, true)

View File

@@ -22,7 +22,7 @@ const gridRatio = 10
* We avoid setting nodes in the border of the grid (x=0 or y=0), so there's
* always a "walkable" area around the grid.
*/
export const graphToGridPoint = (graphPoint: XYPosition, smallestX: number, smallestY: number): XYPosition => {
export function graphToGridPoint(graphPoint: XYPosition, smallestX: number, smallestY: number): XYPosition {
let x = graphPoint.x / gridRatio
let y = graphPoint.y / gridRatio
@@ -60,7 +60,7 @@ export const graphToGridPoint = (graphPoint: XYPosition, smallestX: number, smal
* Converts a grid point back to a graph point, using the reverse logic of
* graphToGridPoint.
*/
export const gridToGraphPoint = (gridPoint: XYPosition, smallestX: number, smallestY: number): XYPosition => {
export function gridToGraphPoint(gridPoint: XYPosition, smallestX: number, smallestY: number): XYPosition {
let x = gridPoint.x * gridRatio
let y = gridPoint.y * gridRatio

View File

@@ -1,5 +1,11 @@
export const round = (x: number, multiple = 10) => Math.round(x / multiple) * multiple
export function round(x: number, multiple = 10) {
return Math.round(x / multiple) * multiple
}
export const roundDown = (x: number, multiple = 10) => Math.floor(x / multiple) * multiple
export function roundDown(x: number, multiple = 10) {
return Math.floor(x / multiple) * multiple
}
export const roundUp = (x: number, multiple = 10) => Math.ceil(x / multiple) * multiple
export function roundUp(x: number, multiple = 10) {
return Math.ceil(x / multiple) * multiple
}