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

polyline-normals

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

polyline-normals - npm Package Compare versions

Comparing version 1.0.2 to 2.0.0

14

index.js

@@ -8,8 +8,11 @@ var util = require('polyline-miter-util')

module.exports = function(points) {
var total = points.length
module.exports = function(points, closed) {
var curNormal = null
var out = []
if (closed) {
points = points.slice()
points.push(points[0])
}
var total = points.length
for (var i=1; i<total; i++) {

@@ -43,5 +46,3 @@ var last = points[i-1]

//if the polyline is a closed loop, clean up the last normal
if (points.length > 2
&& points[0][0] === points[total-1][0]
&& points[0][1] === points[total-1][1]) {
if (points.length > 2 && closed) {
var last2 = points[total-2]

@@ -60,2 +61,3 @@ var cur2 = points[0]

out[total-1][1] = miterLen2
out.pop()
}

@@ -62,0 +64,0 @@

{
"name": "polyline-normals",
"version": "1.0.2",
"version": "2.0.0",
"description": "gets miter normals for a 2D polyline",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -12,7 +12,7 @@ # polyline-normals

//a triangle, closed
var path = [ [0, 122], [0, 190], [90, 190], [0, 122] ]
//a triangle
var path = [ [0, 122], [0, 190], [90, 190] ]
//get the normals
var normals = getNormals(path)
//get the normals, flag as closed loop
var normals = getNormals(path, true)

@@ -34,3 +34,3 @@ //now draw our thick line in 2D/3D/etc

#### `normals(path)`
#### `normals(path[, closed])`

@@ -46,4 +46,6 @@ For the given path, produces a new array of the same length with normal information for each point. The data contains a normal, `[nx, ny]` and the length of the miter (default to 1.0 where no join occurs).

If `closed` is true, it assumes a segment will be drawn from the last point to the first point, and adjusts those normals accordingly.
## License
MIT, see [LICENSE.md](http://github.com/mattdesl/polyline-normals/blob/master/LICENSE.md) for details.

@@ -11,8 +11,17 @@ require('canvas-testbed')(render, { once: true })

paths.push( [ [40, 40], [80, 30], [80, 60], [125, 33], [115, 100], [50, 120], [70, 150] ] )
paths.push( arc(130, 120, 25, 0, Math.PI*2, false) )
paths.push( { path: circle(130, 120, 25), closed: true } )
paths.push( curve([40, 40], [70, 100], [120, 20], [200, 40], 5) )
paths.push( [ [0, 122], [0, 190], [90, 190], [0, 122] ] )
paths.push( [ [50, 50], [100, 50], [100, 100], [50, 100], [50, 50] ] )
paths.push( { path: [ [0, 122], [0, 190], [90, 190] ], closed: true } )
paths.push( { path: [ [50, 50], [100, 50], [100, 100], [50, 100] ], closed: true } )
paths.push( [ [30, -60], [80, 10] ] )
function circle(x, y, radius) {
//in this case arc-to closes itself by making the
//last point equal to the first. we want to fix this
//to pass in a more typical polyline and get the right normals
var c = arc(x, y, radius, 0, Math.PI*2, false)
c.pop()
return c
}
function render(ctx, width, height) {

@@ -23,3 +32,6 @@ ctx.clearRect(0,0,width,height)

ctx.save()
paths.forEach(function(path, i) {
paths.forEach(function(data, i) {
var path = Array.isArray(data) ? data : data.path
var closed = typeof data === 'object' && data.closed
var cols = 3

@@ -29,3 +41,3 @@ var x = i % cols,

ctx.translate(x * 50, y * 50)
draw(ctx, path)
draw(ctx, path, closed)
})

@@ -35,3 +47,3 @@ ctx.restore()

function draw(ctx, path) {
function draw(ctx, path, closed) {
var thick = 25,

@@ -46,3 +58,9 @@ halfThick = thick / 2

//get the normals of the path
var normals = getNormals(path)
var normals = getNormals(path, closed)
//for drawing the join, we can just add the first point
if (closed) {
path.push(path[0])
normals.push(normals[0])
}

@@ -49,0 +67,0 @@ //draw our expanded vertices for each point in the path

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