@@ -2,18 +2,14 @@ import { linspace, sgn, infinity, clamp, space, isValidNumber } from '../utils.m
2
2
import { builtIn as evaluate } from './eval.mjs'
3
3
4
4
import { FunctionPlotDatum , FunctionPlotScale , PointFunction , VectorFunction } from '../types.js'
5
- import { SamplerParams , SamplerFn } from './types.js'
5
+ import { SamplerParams , SamplerFn , BuiltInSamplerResult , BuiltInSamplerResultGroup } from './types.js'
6
6
7
7
type Asymptote = {
8
8
asymptote : boolean
9
9
d0 : [ number , number ]
10
10
d1 : [ number , number ]
11
11
}
12
12
13
- type SamplerResultSingle = [ number , number ]
14
- type SamplerResultGroup = Array < SamplerResultSingle >
15
- type SamplerResult = Array < SamplerResultGroup >
16
-
17
13
function checkAsymptote (
18
14
d0 : [ number , number ] ,
19
15
d1 : [ number , number ] ,
@@ -50,18 +46,18 @@ function checkAsymptote(
50
46
* Splits the evaluated data into arrays, each array is separated by any asymptote found
51
47
* through the process of detecting slope/sign brusque changes
52
48
*/
53
- function split ( d : FunctionPlotDatum , data : SamplerResultGroup , yScale : FunctionPlotScale ) : SamplerResult {
49
+ function split ( d : FunctionPlotDatum , data : BuiltInSamplerResultGroup , yScale : FunctionPlotScale ) : BuiltInSamplerResult {
54
50
if ( data . length === 0 ) {
55
51
// This case is possible when the function didn't render any valid points
56
52
// e.g. when evaluating sqrt(x) with all negative values.
57
53
return [ ]
58
54
}
59
55
60
- const samplerResult : SamplerResult = [ ]
56
+ const samplerResult : BuiltInSamplerResult = [ ]
61
57
const yMin = yScale . domain ( ) [ 0 ] - infinity ( )
62
58
const yMax = yScale . domain ( ) [ 1 ] + infinity ( )
63
59
64
- let samplerGroup : SamplerResultGroup = [ data [ 0 ] ]
60
+ let samplerGroup : BuiltInSamplerResultGroup = [ data [ 0 ] ]
65
61
66
62
let i = 1
67
63
let deltaX = infinity ( )
@@ -117,7 +113,7 @@ function split(d: FunctionPlotDatum, data: SamplerResultGroup, yScale: FunctionP
117
113
return samplerResult
118
114
}
119
115
120
- function linear ( samplerParams : SamplerParams ) : SamplerResult {
116
+ function linear ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
121
117
const allX = space ( samplerParams . xAxis , samplerParams . range , samplerParams . nSamples )
122
118
const yDomain = samplerParams . yScale . domain ( )
123
119
// const yDomainMargin = yDomain[1] - yDomain[0]
@@ -136,12 +132,12 @@ function linear(samplerParams: SamplerParams): SamplerResult {
136
132
return splitData
137
133
}
138
134
139
- function parametric ( samplerParams : SamplerParams ) : SamplerResult {
135
+ function parametric ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
140
136
// range is mapped to canvas coordinates from the input
141
137
// for parametric plots the range will tell the start/end points of the `t` param
142
138
const parametricRange = samplerParams . d . range || [ 0 , 2 * Math . PI ]
143
139
const tCoords = space ( samplerParams . xAxis , parametricRange , samplerParams . nSamples )
144
- const samples : SamplerResultGroup = [ ]
140
+ const samples : BuiltInSamplerResultGroup = [ ]
145
141
for ( let i = 0 ; i < tCoords . length ; i += 1 ) {
146
142
const t = tCoords [ i ]
147
143
const x = evaluate ( samplerParams . d , 'x' , { t } )
@@ -151,12 +147,12 @@ function parametric(samplerParams: SamplerParams): SamplerResult {
151
147
return [ samples ]
152
148
}
153
149
154
- function polar ( samplerParams : SamplerParams ) : SamplerResult {
150
+ function polar ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
155
151
// range is mapped to canvas coordinates from the input
156
152
// for polar plots the range will tell the start/end points of the `theta` param
157
153
const polarRange = samplerParams . d . range || [ - Math . PI , Math . PI ]
158
154
const thetaSamples = space ( samplerParams . xAxis , polarRange , samplerParams . nSamples )
159
- const samples : SamplerResultGroup = [ ]
155
+ const samples : BuiltInSamplerResultGroup = [ ]
160
156
for ( let i = 0 ; i < thetaSamples . length ; i += 1 ) {
161
157
const theta = thetaSamples [ i ]
162
158
const r = evaluate ( samplerParams . d , 'r' , { theta } )
@@ -167,18 +163,18 @@ function polar(samplerParams: SamplerParams): SamplerResult {
167
163
return [ samples ]
168
164
}
169
165
170
- function points ( samplerParams : SamplerParams ) : SamplerResult {
166
+ function points ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
171
167
const d : PointFunction = samplerParams . d as PointFunction
172
168
return [ d . points ]
173
169
}
174
170
175
- function vector ( samplerParms : SamplerParams ) : SamplerResult {
171
+ function vector ( samplerParms : SamplerParams ) : BuiltInSamplerResult {
176
172
const d : VectorFunction = samplerParms . d as VectorFunction
177
173
d . offset = d . offset || [ 0 , 0 ]
178
174
return [ [ d . offset , [ d . vector [ 0 ] + d . offset [ 0 ] , d . vector [ 1 ] + d . offset [ 1 ] ] ] ]
179
175
}
180
176
181
- const sampler : SamplerFn = function sampler ( samplerParams : SamplerParams ) : SamplerResult {
177
+ const sampler : SamplerFn = function sampler ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
182
178
switch ( samplerParams . d . fnType ) {
183
179
case 'linear' :
184
180
return linear ( samplerParams )
0 commit comments