Socket
Book a DemoInstallSign in
Socket

@tscircuit/math-utils

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tscircuit/math-utils

This repository contains a collection of TypeScript utility functions for geometric calculations, primarily focused on line intersection and distance calculations.

0.0.19
latest
npmnpm
Version published
Weekly downloads
23K
68.78%
Maintainers
1
Weekly downloads
 
Created
Source

@tscircuit/math-utils

This repository contains a collection of TypeScript utility functions for geometric calculations, primarily focused on line intersection and distance calculations.

Features

  • Line intersection detection
  • Segment intersection detection
  • Point-to-segment distance calculation
  • Orientation of points
  • Distance between points

Installation

bun add @tscircuit/math-utils

Usage

Import the functions you need in your TypeScript project:

import {
  doesLineIntersectLine,
  doSegmentsIntersect,
  pointToSegmentDistance,
} from "./src/index"

// Example usage
const point1 = { x: 0, y: 0 }
const point2 = { x: 5, y: 5 }
const point3 = { x: 0, y: 5 }
const point4 = { x: 5, y: 0 }

const intersects = doesLineIntersectLine([point1, point2], [point3, point4])
console.log("Lines intersect:", intersects)

API Reference

doesLineIntersectLine(line1: [Point, Point], line2: [Point, Point], options?: { lineThickness?: number }): boolean

Determines if two lines intersect, optionally considering line thickness.

doSegmentsIntersect(p1: Point, q1: Point, p2: Point, q2: Point): boolean

Checks if two line segments intersect.

orientation(p: Point, q: Point, r: Point): number

Calculates the orientation of three points.

onSegment(p: Point, q: Point, r: Point): boolean

Checks if point q lies on the segment p-r.

pointToSegmentDistance(p: Point, v: Point, w: Point): number

Calculates the minimum distance between a point and a line segment.

distance(p1: Point, p2: Point): number

Calculates the Euclidean distance between two points.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.

FAQs

Package last updated on 10 Jul 2025

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.