@@ -2,18 +2,14 @@ import { linspace, sgn, infinity, clamp, space, isValidNumber } from '../utils.m
22import { builtIn as evaluate } from './eval.mjs'
33
44import { FunctionPlotDatum , FunctionPlotScale , PointFunction , VectorFunction } from '../types.js'
5- import { SamplerParams , SamplerFn } from './types.js'
5+ import { SamplerParams , SamplerFn , BuiltInSamplerResult , BuiltInSamplerResultGroup } from './types.js'
66
77type Asymptote = {
88 asymptote : boolean
99 d0 : [ number , number ]
1010 d1 : [ number , number ]
1111}
1212
13- type SamplerResultSingle = [ number , number ]
14- type SamplerResultGroup = Array < SamplerResultSingle >
15- type SamplerResult = Array < SamplerResultGroup >
16-
1713function checkAsymptote (
1814 d0 : [ number , number ] ,
1915 d1 : [ number , number ] ,
@@ -50,18 +46,18 @@ function checkAsymptote(
5046 * Splits the evaluated data into arrays, each array is separated by any asymptote found
5147 * through the process of detecting slope/sign brusque changes
5248 */
53- function split ( d : FunctionPlotDatum , data : SamplerResultGroup , yScale : FunctionPlotScale ) : SamplerResult {
49+ function split ( d : FunctionPlotDatum , data : BuiltInSamplerResultGroup , yScale : FunctionPlotScale ) : BuiltInSamplerResult {
5450 if ( data . length === 0 ) {
5551 // This case is possible when the function didn't render any valid points
5652 // e.g. when evaluating sqrt(x) with all negative values.
5753 return [ ]
5854 }
5955
60- const samplerResult : SamplerResult = [ ]
56+ const samplerResult : BuiltInSamplerResult = [ ]
6157 const yMin = yScale . domain ( ) [ 0 ] - infinity ( )
6258 const yMax = yScale . domain ( ) [ 1 ] + infinity ( )
6359
64- let samplerGroup : SamplerResultGroup = [ data [ 0 ] ]
60+ let samplerGroup : BuiltInSamplerResultGroup = [ data [ 0 ] ]
6561
6662 let i = 1
6763 let deltaX = infinity ( )
@@ -117,7 +113,7 @@ function split(d: FunctionPlotDatum, data: SamplerResultGroup, yScale: FunctionP
117113 return samplerResult
118114}
119115
120- function linear ( samplerParams : SamplerParams ) : SamplerResult {
116+ function linear ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
121117 const allX = space ( samplerParams . xAxis , samplerParams . range , samplerParams . nSamples )
122118 const yDomain = samplerParams . yScale . domain ( )
123119 // const yDomainMargin = yDomain[1] - yDomain[0]
@@ -136,12 +132,12 @@ function linear(samplerParams: SamplerParams): SamplerResult {
136132 return splitData
137133}
138134
139- function parametric ( samplerParams : SamplerParams ) : SamplerResult {
135+ function parametric ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
140136 // range is mapped to canvas coordinates from the input
141137 // for parametric plots the range will tell the start/end points of the `t` param
142138 const parametricRange = samplerParams . d . range || [ 0 , 2 * Math . PI ]
143139 const tCoords = space ( samplerParams . xAxis , parametricRange , samplerParams . nSamples )
144- const samples : SamplerResultGroup = [ ]
140+ const samples : BuiltInSamplerResultGroup = [ ]
145141 for ( let i = 0 ; i < tCoords . length ; i += 1 ) {
146142 const t = tCoords [ i ]
147143 const x = evaluate ( samplerParams . d , 'x' , { t } )
@@ -151,12 +147,12 @@ function parametric(samplerParams: SamplerParams): SamplerResult {
151147 return [ samples ]
152148}
153149
154- function polar ( samplerParams : SamplerParams ) : SamplerResult {
150+ function polar ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
155151 // range is mapped to canvas coordinates from the input
156152 // for polar plots the range will tell the start/end points of the `theta` param
157153 const polarRange = samplerParams . d . range || [ - Math . PI , Math . PI ]
158154 const thetaSamples = space ( samplerParams . xAxis , polarRange , samplerParams . nSamples )
159- const samples : SamplerResultGroup = [ ]
155+ const samples : BuiltInSamplerResultGroup = [ ]
160156 for ( let i = 0 ; i < thetaSamples . length ; i += 1 ) {
161157 const theta = thetaSamples [ i ]
162158 const r = evaluate ( samplerParams . d , 'r' , { theta } )
@@ -167,18 +163,18 @@ function polar(samplerParams: SamplerParams): SamplerResult {
167163 return [ samples ]
168164}
169165
170- function points ( samplerParams : SamplerParams ) : SamplerResult {
166+ function points ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
171167 const d : PointFunction = samplerParams . d as PointFunction
172168 return [ d . points ]
173169}
174170
175- function vector ( samplerParms : SamplerParams ) : SamplerResult {
171+ function vector ( samplerParms : SamplerParams ) : BuiltInSamplerResult {
176172 const d : VectorFunction = samplerParms . d as VectorFunction
177173 d . offset = d . offset || [ 0 , 0 ]
178174 return [ [ d . offset , [ d . vector [ 0 ] + d . offset [ 0 ] , d . vector [ 1 ] + d . offset [ 1 ] ] ] ]
179175}
180176
181- const sampler : SamplerFn = function sampler ( samplerParams : SamplerParams ) : SamplerResult {
177+ const sampler : SamplerFn = function sampler ( samplerParams : SamplerParams ) : BuiltInSamplerResult {
182178 switch ( samplerParams . d . fnType ) {
183179 case 'linear' :
184180 return linear ( samplerParams )
0 commit comments