1111
1212var BADNUM = require ( '../../constants/numerical' ) . BADNUM ;
1313var segmentsIntersect = require ( '../../lib/geometry2d' ) . segmentsIntersect ;
14+ var constants = require ( './constants' ) ;
1415
1516
1617module . exports = function linePoints ( d , opts ) {
17- var xa = opts . xaxis ,
18- ya = opts . yaxis ,
19- simplify = opts . simplify ,
20- connectGaps = opts . connectGaps ,
21- baseTolerance = opts . baseTolerance ,
22- linear = opts . linear ,
23- segments = [ ] ,
24- minTolerance = 0.2 , // fraction of tolerance "so close we don't even consider it a new point"
25- pts = new Array ( d . length ) ,
26- pti = 0 ,
27- i ,
28-
29- // pt variables are pixel coordinates [x,y] of one point
30- clusterStartPt , // these four are the outputs of clustering on a line
31- clusterEndPt ,
32- clusterHighPt ,
33- clusterLowPt ,
34- thisPt , // "this" is the next point we're considering adding to the cluster
35-
36- clusterRefDist ,
37- clusterHighFirst , // did we encounter the high point first, then a low point, or vice versa?
38- clusterUnitVector , // the first two points in the cluster determine its unit vector
39- // so the second is always in the "High" direction
40- thisVector , // the pixel delta from clusterStartPt
41-
42- // val variables are (signed) pixel distances along the cluster vector
43- clusterHighVal ,
44- clusterLowVal ,
45- thisVal ,
46-
47- // deviation variables are (signed) pixel distances normal to the cluster vector
48- clusterMinDeviation ,
49- clusterMaxDeviation ,
50- thisDeviation ;
18+ var xa = opts . xaxis ;
19+ var ya = opts . yaxis ;
20+ var simplify = opts . simplify ;
21+ var connectGaps = opts . connectGaps ;
22+ var baseTolerance = opts . baseTolerance ;
23+ var linear = opts . linear ;
24+ var segments = [ ] ;
25+ var minTolerance = constants . minTolerance ;
26+ var pts = new Array ( d . length ) ;
27+ var pti = 0 ;
28+
29+ var i ;
30+
31+ // pt variables are pixel coordinates [x,y] of one point
32+ // these four are the outputs of clustering on a line
33+ var clusterStartPt , clusterEndPt , clusterHighPt , clusterLowPt ;
34+
35+ // "this" is the next point we're considering adding to the cluster
36+ var thisPt ;
37+
38+ // did we encounter the high point first, then a low point, or vice versa?
39+ var clusterHighFirst ;
40+
41+ // the first two points in the cluster determine its unit vector
42+ // so the second is always in the "High" direction
43+ var clusterUnitVector ;
44+
45+ // the pixel delta from clusterStartPt
46+ var thisVector ;
47+
48+ // val variables are (signed) pixel distances along the cluster vector
49+ var clusterRefDist , clusterHighVal , clusterLowVal , thisVal ;
50+
51+ // deviation variables are (signed) pixel distances normal to the cluster vector
52+ var clusterMinDeviation , clusterMaxDeviation , thisDeviation ;
5153
5254 if ( ! simplify ) {
5355 baseTolerance = minTolerance = - 1 ;
5456 }
5557
5658 // turn one calcdata point into pixel coordinates
5759 function getPt ( index ) {
58- var x = xa . c2p ( d [ index ] . x ) ,
59- y = ya . c2p ( d [ index ] . y ) ;
60+ var x = xa . c2p ( d [ index ] . x ) ;
61+ var y = ya . c2p ( d [ index ] . y ) ;
6062 if ( x === BADNUM || y === BADNUM ) return false ;
6163 return [ x , y ] ;
6264 }
@@ -65,20 +67,19 @@ module.exports = function linePoints(d, opts) {
6567 function getTolerance ( pt ) {
6668 var xFrac = pt [ 0 ] / xa . _length ;
6769 var yFrac = pt [ 1 ] / ya . _length ;
68- return ( 1 + 10 * Math . max ( 0 , - xFrac , xFrac - 1 , - yFrac , yFrac - 1 ) ) * baseTolerance ;
70+ return ( 1 + constants . toleranceGrowth * Math . max ( 0 , - xFrac , xFrac - 1 , - yFrac , yFrac - 1 ) ) * baseTolerance ;
6971 }
7072
7173 function ptDist ( pt1 , pt2 ) {
72- var dx = pt1 [ 0 ] - pt2 [ 0 ] ,
73- dy = pt1 [ 1 ] - pt2 [ 1 ] ;
74+ var dx = pt1 [ 0 ] - pt2 [ 0 ] ;
75+ var dy = pt1 [ 1 ] - pt2 [ 1 ] ;
7476 return Math . sqrt ( dx * dx + dy * dy ) ;
7577 }
7678
7779 // last bit of filtering: clip paths that are VERY far off-screen
7880 // so we don't get near the browser's hard limit (+/- 2^29 px in Chrome and FF)
7981
80- // maximum multiple of the screen size to use
81- var maxScreensAway = 20 ;
82+ var maxScreensAway = constants . maxScreensAway ;
8283
8384 // find the intersections between the segment from pt1 to pt2
8485 // and the large rectangle maxScreensAway around the viewport
0 commit comments