@@ -18,15 +18,14 @@ import {isObject} from "./options.js";
18
18
// - conic equal area?
19
19
// - conic equidistant?
20
20
// - transverse mercator?
21
- // - allow configuration of rotation?
22
21
// - allow configuration of parallels?
23
22
// - camelCase or hypen-separated?
24
23
// - more named projections?
25
24
// - apply x and y scales as linear projection by default?
26
25
// - disallow non-default projection if x and y scales exist?
27
26
export function maybeProjection ( projection , dimensions ) {
28
27
if ( projection == null ) return ;
29
- if ( typeof projection === "function" ) return projection ;
28
+ if ( typeof projection . stream === "function" ) return projection ;
30
29
const { width, height} = dimensions ;
31
30
let rotate , scale , precision ;
32
31
if ( isObject ( projection ) ) {
@@ -74,11 +73,16 @@ export function maybeProjection(projection, dimensions) {
74
73
export function applyProjection ( values , projection ) {
75
74
const { x, y} = values ;
76
75
const n = x . length ;
77
- const X = ( values . x = new Float64Array ( n ) ) ;
78
- const Y = ( values . y = new Float64Array ( n ) ) ;
79
- for ( let i = 0 ; i < n ; ++ i ) {
80
- const p = projection ( [ x [ i ] , y [ i ] ] ) ;
81
- if ( p ) ( X [ i ] = p [ 0 ] ) , ( Y [ i ] = p [ 1 ] ) ;
82
- else X [ i ] = Y [ i ] = NaN ;
76
+ const X = ( values . x = new Float64Array ( n ) . fill ( NaN ) ) ;
77
+ const Y = ( values . y = new Float64Array ( n ) . fill ( NaN ) ) ;
78
+ let i ;
79
+ const stream = projection . stream ( {
80
+ point ( x , y ) {
81
+ X [ i ] = x ;
82
+ Y [ i ] = y ;
83
+ }
84
+ } ) ;
85
+ for ( i = 0 ; i < n ; ++ i ) {
86
+ stream . point ( x [ i ] , y [ i ] ) ;
83
87
}
84
88
}
0 commit comments