diff --git a/src/external.d.ts b/src/external.d.ts index 60b149d..ceaf6da 100644 --- a/src/external.d.ts +++ b/src/external.d.ts @@ -7,7 +7,7 @@ declare module 'interval-arithmetic-eval' { export class Interval { lo: number hi: number - + constructor(lo: number | Interval, hi?: number) static isEmpty(n: Interval | number): boolean static isWhole(n: Interval | number): boolean static intervalsOverlap(n: Interval, r: Interval): boolean diff --git a/src/samplers/builtIn.ts b/src/samplers/builtIn.ts index 730b155..39ddd87 100644 --- a/src/samplers/builtIn.ts +++ b/src/samplers/builtIn.ts @@ -1,5 +1,5 @@ import { linspace, sgn, infinity, clamp, space, isValidNumber } from '../utils.mjs' -import { builtIn as evaluate } from './eval.mjs' +import { builtIn as builtInEvaluate } from './eval.mjs' import type { FunctionPlotDatum, FunctionPlotScale, PointFunction, VectorFunction } from '../types.js' import type { SamplerParams, SamplerFn, BuiltInSamplerResult, BuiltInSamplerResultGroup } from './types.js' @@ -27,7 +27,7 @@ function checkAsymptote( let oldY: number, oldX: number for (let i = 0; i < n; i += 1) { const x = samples[i] - const y = evaluate(d, 'fn', { x }) + const y = builtInEvaluate(d, 'fn', { x }) if (oldY) { const deltaY = y - oldY @@ -122,7 +122,7 @@ function linear(samplerParams: SamplerParams): BuiltInSamplerResult { const data: Array<[number, number]> = [] for (let i = 0; i < allX.length; i += 1) { const x = allX[i] - let y = evaluate(samplerParams.d, 'fn', { x }) + let y = builtInEvaluate(samplerParams.d, 'fn', { x }) if (isValidNumber(x) && isValidNumber(y)) { y = clamp(y, yMin, yMax) data.push([x, y]) @@ -140,8 +140,8 @@ function parametric(samplerParams: SamplerParams): BuiltInSamplerResult { const samples: BuiltInSamplerResultGroup = [] for (let i = 0; i < tCoords.length; i += 1) { const t = tCoords[i] - const x = evaluate(samplerParams.d, 'x', { t }) - const y = evaluate(samplerParams.d, 'y', { t }) + const x = builtInEvaluate(samplerParams.d, 'x', { t }) + const y = builtInEvaluate(samplerParams.d, 'y', { t }) samples.push([x, y]) } return [samples] @@ -155,7 +155,7 @@ function polar(samplerParams: SamplerParams): BuiltInSamplerResult { const samples: BuiltInSamplerResultGroup = [] for (let i = 0; i < thetaSamples.length; i += 1) { const theta = thetaSamples[i] - const r = evaluate(samplerParams.d, 'r', { theta }) + const r = builtInEvaluate(samplerParams.d, 'r', { theta }) const x = r * Math.cos(theta) const y = r * Math.sin(theta) samples.push([x, y]) diff --git a/src/samplers/interval.ts b/src/samplers/interval.ts index 84bb1a6..7c4cbcc 100644 --- a/src/samplers/interval.ts +++ b/src/samplers/interval.ts @@ -1,6 +1,6 @@ import intervalArithmeticEval, { Interval } from 'interval-arithmetic-eval' -import { interval as evaluate } from './eval.mjs' +import { interval as intervalEvaluate, builtIn as builtInEvaluate } from './eval.mjs' import { infinity, space, interval2dTypedArray } from '../utils.mjs' import globals from '../globals.mjs' @@ -125,7 +125,7 @@ function interval1d({ d, xAxis, range, nSamples, xScale, yScale }: SamplerParams const samples: IntervalSamplerResultGroup = [] for (let i = 0; i < xCoords.length - 1; i += 1) { const x = { lo: xCoords[i], hi: xCoords[i + 1] } - const y = evaluate(d, 'fn', { x }) + const y = intervalEvaluate(d, 'fn', { x }) if (!Interval.isEmpty(y) && !Interval.isWhole(y)) { samples.push([x, y]) } @@ -179,7 +179,7 @@ function smallRect(x: Interval, _: Interval) { } function quadTree(x: Interval, y: Interval, d: FunctionPlotDatum) { - const sample = evaluate(d, 'fn', { x, y }) + const sample = intervalEvaluate(d, 'fn', { x, y }) const fulfills = Interval.zeroIn(sample) if (!fulfills) { return this