infinite_math_plot 0.1.0
infinite_math_plot: ^0.1.0 copied to clipboard
A Flutter package that renders interactive mathematical graphs on a simulated infinite coordinate plane.
Changelog #
All notable changes to this package will be documented here.
The format follows Keep a Changelog, and this project uses Semantic Versioning.
0.1.0 - 2026-05-12 #
First public release. This is the initial version of the package, so everything listed here is new.
Added #
Core widget
InfiniteMathPlot— aStatefulWidgetthat accepts an equation string and renders an interactive graph- Single-equation mode via the
equationparameter - Multi-equation mode via the
equationsparameter (list ofEquationConfig) - Mutual exclusion assertion: providing both
equationandequations, or neither, throws at construction time xMin,xMax,yMin,yMaxparameters to set the initial viewport (default: -10 to 10 on both axes)showGrid,showAxes,enableZoom,enablePanboolean flags, all defaulting totruegraphColorandstrokeWidthfor single-equation stylingsamplingPrecisionto control sample density (default: 2.0 points per logical pixel)- Adaptive layout via
LayoutBuilder— fills available space and maintains math aspect ratio on resize
Equation parser
- Parses Cartesian (
y = f(x)), implicit (F(x,y) = 0), parametric (x = f(t), y = g(t)), and polar (r = f(θ)) equations from plain strings - Supported functions:
sin,cos,tan,asin,acos,atan,sqrt,abs,exp,log,pow - Supported constants:
pi,π,e,theta,θ ParseExceptionwith a human-readable message and character position on invalid input- Canonical serialization via
serialize(Expression)— stable across round-trips
Sampling
- Cartesian sampling: iterates x over the viewport, evaluates y = f(x)
- Polar sampling: iterates θ from 0 to 2π, computes x = r·cos(θ), y = r·sin(θ)
- Parametric sampling: iterates t from 0 to 2π, evaluates x = f(t) and y = g(t) independently
- Implicit sampling: marching squares over a 50×50 grid, linear interpolation of zero-crossings
- Sample cache keyed on
(equation, viewport, samplingPrecision, screenWidth)— no recomputation when nothing changes
Discontinuity detection
isUndefined: classifiesNaN,+Infinity,-Infinityas undefined — path is lifted at these pointsisAsymptote: detects true vertical asymptotes (values straddling the viewport from above and below) without breaking steep-but-continuous functions likey = x³
Rendering
GraphPainter(CustomPainter) draws grid → axes → curves in that order- Grid interval snaps to "nice" numbers (1, 2, 5, 10, 20, 50, …) based on the current viewport scale
- Axes drawn only when x=0 or y=0 is within the viewport
- Tick marks with numeric labels on both axes
- Curve paths use
moveToafter null entries (discontinuities) andlineTootherwise shouldRepaintreturnsfalsewhen nothing has changed — avoids unnecessary redraws
Gesture handling
- Pinch-to-zoom: applies incremental scale delta each frame (not cumulative), centered on the focal point
- Scroll-wheel zoom: scroll down = zoom out (×0.9), scroll up = zoom in (×1.1)
- Drag-to-pan: converts screen delta to math units via the coordinate transformer
- All gestures respect
enableZoomandenablePanflags
Coordinate transformer
toScreen(x, y)— linear mapping from math coordinates to screen pixels, Y-axis invertedtoMath(screenOffset)— algebraic inverse of the forward transform- Round-trip accuracy within floating-point tolerance (< 1e-10)
Data models
Viewport— immutable value class withcopyWith, structural equality, andhashCodeParsedEquation— holds the expression tree, equation type, and canonical serialized formParseException— implementsExceptionwithmessageandpositionEquationConfig— equation string + color + strokeWidth with structural equalitySampleCacheKey— composite cache key with structural equality on all four fieldsGraphState— runtime state withcopyWithEquationTypeenum —cartesian,implicit,parametric,polar
Example app
- Interactive demo in
example/with 8 presets, a custom equation input field, and toggles for all display and gesture options
Tests
- 241 tests covering all components
- Property-based round-trip tests for the equation parser and coordinate transformer
- Property-based classification test for the discontinuity detector
- Unit tests for all components
- Widget tests for
InfiniteMathPlot
Upcoming #
Things I'm planning for future releases:
- Configurable parametric t-range (currently fixed at 0 to 2π)
- Tap-to-inspect: show the y-value at a tapped x position
- Isolate-based sampling for very high precision or many simultaneous equations
- Animation support for time-varying equations
- Export to image