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 🙏

© 2026 – Pkg Stats / Ryan Hefner

segment2

v0.3.2

Published

2d line segment

Readme

segment2

2d line segment

install

npm install segment2

or include it in the browser

use


var Segment2 = require('segment2');
var Vec2 = require('vec2');

var s = new Segment2(Vec2(0, 0), Vec2(10, 0));

console.log(s.midpoint().toString()); // (5, 0)

console.log(s.intersect(Segment2(Vec2(5, 10), Vec2(5, -10))).toString()) // (5, 0)

properties

.start - the starting point of the line

.end - the ending point of the line

methods

fn change([fn])

Add a listener to be called when the line changes. Returns fn

callback signature: function(segment2, vec2) {} where segment2 is the segment that changed and vec2 is the component that changed

ignore([fn])

Remove a listener, or all of them if fn is not passed

clone()

Create a copy of this segment.

note: this function uses this.constructor to create clones of subclasses.

Pass segmentCtor if you have subclassed Segment2

Pass vecCtor if you have subclassed Vec2

length()

return the length of the line segment

lengthSquared()

return the length of this line segment (squared)

closestPointTo(vec2)

return the closest point on this segment to the passed vec2

containsPoint(vec2)

return true if vec2 lies on the segment

midpoint()

return the vec2 equidistant from segment2.start and segment.end

slope()

return the computed slope of this line segment.

note: this function will return Infinity for vertical lines

rotate(rads[, origin [, returnNew]])

apply a rotation to the current start/end points around origin. If origin is not passed the midpoint is used. If returnNew is truthy, a new Segment2 instance will be returnd instead of applying the result on this

note: calling it like seg.rotate(Math.PI, true) is also valid and will return a copy of seg rotated around seg's midpoint.

collinear(seg)

returns true when the passed seg is collinear with this

parallel(seg)

returns true when the passed seg is parallel with this

license

MIT (see: license.txt)