profile
viewpoint

scien/svg-path-properties 0

Pure Javascript alternative to path.getPointAtLength(t) and getTotalLength() functions. Works with Canvas & Node

startedubilabs/kd-tree-javascript

started time in 21 days

issue closedrveciana/svg-path-properties

Tangents for points along Linear segments are backwards

I had some paths that use a combination of Bezier Curves and Linear segments. Every time I reached a linear segment, the tangents would be pointing in the wrong direction.

let path = "M 930 197 L 639 904 L 462 828 L 751 118 Z M 555 183 L 249 896 L 70 810 L 385 96 Z";
let properties = new SVGPathProperties(path);
let p1 = properties.getPointAtLength(8);
let p2 = properties.getPointAtLength(10);
let dx = (p2.x - p1.x)
let dy = (p2.y - p1.y)
let length = Math.sqrt(dx*dx + dy*dy)
let expected = {x: dx/length, y: dy/length}
let actual = properties.getTangentAtLength(9);
console.log({expected, actual})

{
  expected: { x: -0.3806182308124968, y: 0.9247322652385203 },
  actual: { x: -0.38061823081246554, y: 0.9247322652385331 }
}

this is because getTangentAtLength for LinearPosition has negative signs on both the x and y component for some reason:

    return {
      x: -(this.x1 - this.x0) / module,
      y: -(this.y1 - this.y0) / module,
    };

Issue introduced in this commit on Sep 14, 2022: https://github.com/rveciana/svg-path-properties/commit/eab0526fa8a71bb40a0c2a97139acc094eae3a6b

closed time in 21 days

scien

PR opened rveciana/svg-path-properties

fix tangent for LinearPosition

The tangents for points along a LinearPosition are current pointing in the wrong direction. Fixes Issue #63

+40 -40

0 comment

6 changed files

pr created time in 22 days

issue openedrveciana/svg-path-properties

Tangents for points along Linear segments are backwards

I had some paths that use a combination of Bezier Curves and Linear segments. Every time I reached a linear segment, the tangents would be pointing in the wrong direction.

let path = "M 930 197 L 639 904 L 462 828 L 751 118 Z M 555 183 L 249 896 L 70 810 L 385 96 Z";
let properties = new SVGPathProperties(path);
let p1 = properties.getPointAtLength(8);
let p2 = properties.getPointAtLength(9);
let dx = (p2.x - p1.x)
let dy = (p2.y - p1.y)
let length = Math.sqrt(dx*dx + dy*dy)
let expected = {x: dx/length, y: dy/length}
let actual = properties.getTangentAtLength(10);
console.log({expected, actual})

{
  expected: { x: -0.3806182308124968, y: 0.9247322652385203 },
  actual: { x: 0.38061823081246554, y: -0.9247322652385331 }
}

this is because getTangentAtLength for LinearPosition has negative signs on both the x and y component for some reason:

    return {
      x: -(this.x1 - this.x0) / module,
      y: -(this.y1 - this.y0) / module,
    };

Issue introduced in this commit on Sep 14, 2022: https://github.com/rveciana/svg-path-properties/commit/eab0526fa8a71bb40a0c2a97139acc094eae3a6b

created time in 22 days

push eventscien/svg-path-properties

Bryant Williams

commit sha 00773c8641f9c89596e46d4415551344cb4a2e3c

fix tangent for LinearPosition

view details

push time in 22 days

push eventscien/svg-path-properties

Roger Veciana i Rovira

commit sha c48c67e5b5b6f7c4461bac676f9c11aaf579bf58

Merge pull request #62 from scien/master fix infinite length path due to float precision. Thank you!

view details

Roger Veciana

commit sha c90975d672c57e37755538a1892c17e0add86e7c

new version

view details

Roger Veciana

commit sha 53b51478ceb219d115279b72c7cccfbce406345a

1.1.1

view details

push time in 22 days

issue closedrveciana/svg-path-properties

getTotalLength() == Infinity due to float precision

The following paths will cause getTotalLength() to return Infinity.

  • example 1: "Q 0 0 267 0 Q 391 0 512 0"
  • example 2:"Q 0 0 267 10 Q 391 10 512 10"

It ends up using getQuadraticArcLength() in bezier-functions.

  • It returns Infinity because term is infinity.
  • term is Infinity because Math.log(-0) is -Infinity
  • this only happens when (u + uuk) / (b + bbk) is zero or negative zero
  • this happens when (u + uuk) is 0, but (b + bbk) is very small but non-zero due to float precision during Math.sqrt

In example 1 ("Q 0 0 267 0 Q 391 0 512 0"), we get the following:

  • getQuadraticArcLength([ 267, 391, 512, 0 ], [ 0, 0, 0, 0 ], 1)
  • A = 36, B = -2976, C = 61504
  • k = -2.2737367544323206e-13
  • u = -40.333333333333336
  • b = -41.333333333333336
  • Math.sqrt(u * u + k) = 40.333333333333336
  • Math.sqrt(b * b + k) = 41.33333333333333
  • (u + uuk) = 0
  • (b + bbk) = -7.105427357601002e-15
  • term = Infinity

closed time in 22 days

scien

startedabbr/deasync

started time in 23 days

startedsvgdotjs/svg.js

started time in 24 days

startedtooolbox/node-potrace

started time in 24 days

PR opened rveciana/svg-path-properties

fix infinite length path due to float precision

Fix for issue: https://github.com/rveciana/svg-path-properties/issues/61

TLDR: The path "Q 0 0 267 0 Q 391 0 512 0 "causes getTotalLength() to return Infinity. This PR will have it return 0 in that case.

+15 -7

0 comment

5 changed files

pr created time in 24 days

push eventscien/svg-path-properties

Bryant Williams

commit sha 2015f8e2a46007c00f3a3365e5d2d5790c085b33

build

view details

push time in 24 days

push eventscien/svg-path-properties

Bryant Williams

commit sha 55effc5bc8631798e9ca317e90cae47bd3fab333

fix infinite length path issue

view details

push time in 24 days

fork scien/svg-path-properties

Pure Javascript alternative to path.getPointAtLength(t) and getTotalLength() functions. Works with Canvas & Node

fork in 24 days

issue openedrveciana/svg-path-properties

getTotalLength() == Infinity due to float precision

The following paths will cause getTotalLength() to return Infinity.

  • example 1: "Q 0 0 267 0 Q 391 0 512 0"
  • example 2:"Q 0 0 267 10 Q 391 10 512 10"

It ends up using getQuadraticArcLength() in bezier-functions.

  • It returns Infinity because term is infinity.
  • term is Infinity because Math.log(-0) is -Infinity
  • this only happens when (u + uuk) / (b + bbk) is zero or negative zero
  • this happens when (u + uuk) is 0, but (b + bbk) is very small but non-zero due to float precision during Math.sqrt

In example 1 ("Q 0 0 267 0 Q 391 0 512 0"), we get the following:

  • getQuadraticArcLength([ 267, 391, 512, 0 ], [ 0, 0, 0, 0 ], 1)
  • A = 36, B = -2976, C = 61504
  • k = -2.2737367544323206e-13
  • u = -40.333333333333336
  • b = -41.333333333333336
  • Math.sqrt(u * u + k) = 40.333333333333336
  • Math.sqrt(b * b + k) = 41.33333333333333
  • (u + uuk) = 0
  • (b + bbk) = -7.105427357601002e-15
  • term = Infinity

created time in 24 days

startedrveciana/svg-path-properties

started time in 24 days

startedsunhao2014/SGCPD

started time in 25 days

startedyisibl/resvg-js

started time in 25 days

more