Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

line-intersect

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

line-intersect

Line vs line, point vs line in 2D space

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.4K
decreased by-14.05%
Maintainers
1
Weekly downloads
 
Created
Source

line-intersect

Line vs line, point vs line in 2D space

Math is mostly from here.

Install

npm install line-intersect

API

es modules

import {
  checkIntersection,
  colinearPointWithinSegment
} from 'line-intersect';

commonjs modules

const {
  checkIntersection,
  colinearPointWithinSegment
} = require('line-intersect');

checkIntersection(x1, y1, x2, y2, x3, y3, x4, y4)

Given a line segment from (x1, y1) to (x2, y2) and line segment from (x3, y3) to (x4, y4), check if the line segments intersect.

Parameters
  • x1, y1, x2, y2 - 1st line segment
  • x3, y3, x4, y4 - 2nd line segment

All params are Numbers and are required.

Returns

A read-only Object that looks like

{
  type: 'none' | 'parallel' | 'colinear'
}

// or

{
  type: 'intersecting',
  point: {
    x: number,
    y: number
  }
}

point is only exists when type == 'intersecting'

typeWhat it meansAre the line segments touching?
noneLine segments are not intersectingNo
parallelLine segments are not intersecting but they are parallel to eachotherNo
colinearLine segments are on the same line and may be overlapping. Use colinearPointWithinSegment() to checkMaybe
intersectingLine segments intersect at exactly one pointYes

colinearPointWithinSegment(px, py, x1, y1, x2, y2)

Given a point (px, py) that is on the same line as line segment (x1, y1) to (x2, y2), check if the point is within the line segment.

Parameters
  • px, py - Point to check
  • x1, y1, x2, y2 - Line segment

All params are Numbers and are required.

Returns

true if point is within the line segment, false otherwise.

License

MIT

Keywords

FAQs

Package last updated on 04 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc