npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

orthogonal-path-finding

v0.0.3

Published

Compute an orthogonal line from start to end with obstacles

Downloads

24

Readme

Orthogonal Path Finding Library

Overview

This is a powerful tool designed to calculate orthogonal (right-angled) paths between two points while avoiding obstacles. This library is particularly useful in applications such as diagramming tools, routing algorithms, and any scenario where clear, non-overlapping paths are required.

Features

  • Efficient Path Calculation: Quickly computes the shortest orthogonal path between two points.
  • Obstacle Avoidance: Takes into account rectangular obstacles and finds a path that navigates around them.
  • Customizable Options: Provides flexibility through optional parameters to fine-tune the path finding behavior.

Demo

To see the library in action, check out our live demo. This demo provides an interactive interface to visualize how the orthogonal path finding algorithm works with various start and end points and obstacles.

Installation

To install the library, use npm or yarn:

npm install orthogonal-path-finding

or

yarn add orthogonal-path-finding

Usage

Importing the Library

First, import the orthogonalPathFinding function from the library:

import { orthogonalPathFinding } from 'orthogonal-path-finding';

Function Signature

export declare const orthogonalPathFinding: (
  start: Point, 
  end: Point, 
  obstacles: Rectangle[], 
  options?: PathFindingOptions
) => { path: Point[], d: string };

Parameters

  • start: The starting point of the path. It should be an object with x and y properties.
  • end: The ending point of the path. It should be an object with x and y properties.
  • obstacles: An array of rectangular obstacles. Each rectangle should be an object with x, y, width, and height properties.
  • options (optional): An object containing additional options to customize the path finding behavior.

Return Value

The function returns an object with the following properties:

  • path: An array of points representing the calculated path.
  • d: A string representing the path in SVG path data format.

Example

Here is a simple example demonstrating how to use the orthogonalPathFinding function:

import { orthogonalPathFinding } from 'orthogonal-path-finding';

const start = { x: 10, y: 10 };
const end = { x: 200, y: 200 };
const obstacles = [
  { x: 50, y: 50, width: 100, height: 100 },
  { x: 150, y: 150, width: 50, height: 50 }
];

const result = orthogonalPathFinding(start, end, obstacles);

console.log(result.path); // Array of points representing the path
console.log(result.d);    // SVG path data string

Visualization

To visualize the path, you can use the SVG path data string (d) in an SVG element. Here is an example using HTML and JavaScript:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Orthogonal Path Visualization</title>
</head>
<body>
  <svg width="300" height="300" style="border: 1px solid black;">
    <path id="path" stroke="blue" fill="none" />
  </svg>

  <script type="module">
    import { orthogonalPathFinding } from 'orthogonal-path-finding';

    const start = { x: 10, y: 10 };
    const end = { x: 200, y: 200 };
    const obstacles = [
      { x: 50, y: 50, width: 100, height: 100 },
      { x: 150, y: 150, width: 50, height: 50 }
    ];

    const result = orthogonalPathFinding(start, end, obstacles);

    const pathElement = document.getElementById('path');
    pathElement.setAttribute('d', result.d);
  </script>
</body>
</html>

Use Cases

  • Diagramming Tools: Automatically generate clear, non-overlapping connections between nodes in flowcharts, UML diagrams, and other visual representations.
  • Routing Algorithms: Find optimal paths in grid-based games or applications where movement is restricted to orthogonal directions.

Acknowledgements

This library is built upon the excellent work done in the PathFinding.js library by Xueqiao Xu. We have rewritten parts of the code in TypeScript to better suit our needs and to provide a more robust and type-safe implementation. We extend our gratitude for the foundational path finding algorithms provided by PathFinding.js.