Skip to content

Commit 4273729

Browse files
committed
Rename interval & builtIn eval imports
1 parent 6310edd commit 4273729

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

src/external.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare module 'interval-arithmetic-eval' {
77
export class Interval {
88
lo: number
99
hi: number
10-
10+
constructor(lo: number | Interval, hi?: number)
1111
static isEmpty(n: Interval | number): boolean
1212
static isWhole(n: Interval | number): boolean
1313
static intervalsOverlap(n: Interval, r: Interval): boolean

src/samplers/builtIn.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { linspace, sgn, infinity, clamp, space, isValidNumber } from '../utils.mjs'
2-
import { builtIn as evaluate } from './eval.mjs'
2+
import { builtIn as builtInEvaluate, interval as intervalEvaluate } from './eval.mjs'
33

44
import type { FunctionPlotDatum, FunctionPlotScale, PointFunction, VectorFunction } from '../types.js'
55
import type { SamplerParams, SamplerFn, BuiltInSamplerResult, BuiltInSamplerResultGroup } from './types.js'
@@ -27,7 +27,7 @@ function checkAsymptote(
2727
let oldY: number, oldX: number
2828
for (let i = 0; i < n; i += 1) {
2929
const x = samples[i]
30-
const y = evaluate(d, 'fn', { x })
30+
const y = builtInEvaluate(d, 'fn', { x })
3131

3232
if (oldY) {
3333
const deltaY = y - oldY
@@ -120,13 +120,15 @@ function linear(samplerParams: SamplerParams): BuiltInSamplerResult {
120120
const yMin = yDomain[0] - infinity()
121121
const yMax = yDomain[1] + infinity()
122122
const data: Array<[number, number]> = []
123+
let oldY: number
123124
for (let i = 0; i < allX.length; i += 1) {
124125
const x = allX[i]
125-
let y = evaluate(samplerParams.d, 'fn', { x })
126+
let y = builtInEvaluate(samplerParams.d, 'fn', { x })
126127
if (isValidNumber(x) && isValidNumber(y)) {
127128
y = clamp(y, yMin, yMax)
128129
data.push([x, y])
129130
}
131+
oldY = y
130132
}
131133
const splitData = split(samplerParams.d, data, samplerParams.yScale)
132134
return splitData
@@ -140,8 +142,8 @@ function parametric(samplerParams: SamplerParams): BuiltInSamplerResult {
140142
const samples: BuiltInSamplerResultGroup = []
141143
for (let i = 0; i < tCoords.length; i += 1) {
142144
const t = tCoords[i]
143-
const x = evaluate(samplerParams.d, 'x', { t })
144-
const y = evaluate(samplerParams.d, 'y', { t })
145+
const x = builtInEvaluate(samplerParams.d, 'x', { t })
146+
const y = builtInEvaluate(samplerParams.d, 'y', { t })
145147
samples.push([x, y])
146148
}
147149
return [samples]
@@ -155,7 +157,7 @@ function polar(samplerParams: SamplerParams): BuiltInSamplerResult {
155157
const samples: BuiltInSamplerResultGroup = []
156158
for (let i = 0; i < thetaSamples.length; i += 1) {
157159
const theta = thetaSamples[i]
158-
const r = evaluate(samplerParams.d, 'r', { theta })
160+
const r = builtInEvaluate(samplerParams.d, 'r', { theta })
159161
const x = r * Math.cos(theta)
160162
const y = r * Math.sin(theta)
161163
samples.push([x, y])

src/samplers/interval.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import intervalArithmeticEval, { Interval } from 'interval-arithmetic-eval'
22

3-
import { interval as evaluate } from './eval.mjs'
3+
import { interval as intervalEvaluate, builtIn as builtInEvaluate } from './eval.mjs'
44
import { infinity, space, interval2dTypedArray } from '../utils.mjs'
55
import globals from '../globals.mjs'
66

@@ -120,19 +120,22 @@ async function asyncInterval1d({
120120
return [samples]
121121
}
122122

123-
function interval1d({ d, xAxis, range, nSamples, xScale, yScale }: SamplerParams): IntervalSamplerResult {
123+
function interval1d({ d, xAxis, yAxis, range, nSamples, xScale, yScale }: SamplerParams): IntervalSamplerResult {
124124
const xCoords = space(xAxis, range, nSamples)
125125
const samples: IntervalSamplerResultGroup = []
126+
let oldYBuiltIn: number
126127
for (let i = 0; i < xCoords.length - 1; i += 1) {
127128
const x = { lo: xCoords[i], hi: xCoords[i + 1] }
128-
const y = evaluate(d, 'fn', { x })
129+
const y = intervalEvaluate(d, 'fn', { x })
130+
const yBuiltIn = builtInEvaluate(d, 'fn', { x: xCoords[i + 1] })
129131
if (!Interval.isEmpty(y) && !Interval.isWhole(y)) {
130132
samples.push([x, y])
131133
}
132134
if (Interval.isWhole(y)) {
133135
// means that the next and prev intervals need to be fixed
134136
samples.push(null)
135137
}
138+
oldYBuiltIn = yBuiltIn
136139
}
137140

138141
// asymptote determination
@@ -179,7 +182,7 @@ function smallRect(x: Interval, _: Interval) {
179182
}
180183

181184
function quadTree(x: Interval, y: Interval, d: FunctionPlotDatum) {
182-
const sample = evaluate(d, 'fn', { x, y })
185+
const sample = intervalEvaluate(d, 'fn', { x, y })
183186
const fulfills = Interval.zeroIn(sample)
184187
if (!fulfills) {
185188
return this

0 commit comments

Comments
 (0)