npm i @thi.ng/geom-closest-point


⛱ Broadly scoped ecosystem & mono-repository of 165+ TypeScript projects for functional, data driven development

by thi-ng

2.1.12 (see all)License:Apache-2.0TypeScript:Built-In
npm i @thi.ng/geom-closest-point


Build status Code Climate Become a patron Discord chat Twitter Follow


"A collection of functional programming libraries that can be composed together. Unlike a framework, thi.ng is a suite of instruments and you (the user) must be the composer of. Geared towards versatility, not any specific type of music." — @loganpowell via Twitter

Please visit thi.ng for additional information & topic based search of packages relevant to your use cases...

This mono-repository is home to 165+ thi.ng TypeScript/ES6 projects, a wide and jointly developed collection of packages and building blocks for (non-exhaustive list of topics):

  • Functional programming (ES6 iterators/generators, composition, memoization, transducers, multi-methods)
  • Reactive programming, stream / transducer based dataflow graphs / pipelines
  • Data structures & data transformations for wide range of use cases (maps, sets, heaps, queues, graphs etc.)
  • 2D geometry generation, shape primitives, math, manipulation, intersections, conversions & visualizations
  • Canvas abstractions, pixel buffers & SVG serialization/conversion
  • Vector, matrix (dense & sparse), ECS implementations with optional support for strided memory layouts
  • Semi-declarative WebGL 1/2 abstraction layer
  • DSL for shader functions defined in TypeScript and cross-compilation to GLSL, JS, VEX etc.
  • Value-based equivalence
  • DSP building blocks: oscillators, noise generators, filters, 1D FFT/IFFT, muxers, rate converters
  • Immutable data handling, state containers, transacted state updates, Undo-Redo history
  • Data driven UI component toolkits (DOM-based, canvas-based, immediate-mode, multiple approaches...)
  • Multi-format, multi-channel pixel buffers (int & float based), conversions, dithering, Porter-Duff alpha-blending operators
  • Color space/format conversions, matrix based color manipulation, gradient generators, color palettes
  • Date-time abstraction, relative dates, iterators, formatters, math
  • WebWorker workflow abstractions
  • PEG-style functional parser combinators w/ (optional) custom grammar definition language
  • Forth-style pointfree DSL for functional composition and DSL development/extension
  • S-expression parser & runtime (interpreter) infrastructure for custom DSL creation
  • Low-level tooling for binary data, shared memory/WASM/WebGL interop
  • SIMD batch-processing of vector data
  • Various interpolations, math helpers, automatic differentiation (Dual numbers)
  • etc. (see package overview below)

This project is NOT a framework, provides no turn-key, one-size-fits-all approach and instead encourages a mix & match philosophy for various key aspects of application design (in & outside the browser). Most customization points only expect certain interfaces/type signatures rather than concrete implementations.

All packages:

  • are versioned independently
  • distributed as ESM modules (ES2020 syntax) with export maps, TypeScript typings & change logs
  • highly modular with largely only single function / class (only closely related functions) per file to help w/ selective imports and tree shaking
  • provide re-exports of all their publics for full library imports
  • have either none or only @thi.ng internal runtime dependencies
  • declare public interfaces, enums & types in an api.ts and/or constants.ts file (larger packages only)
  • have auto-generated online documentation at docs.thi.ng
  • licensed under Apache Software License 2.0

Getting started

The sheer number and varied nature & purpose of these packages makes it impossible to provide traditional "Getting started" tutorials. To compensate, this repo provides a large number of example projects, detailed readmes (at the very least for all the larger and/or more important packages) and smaller usage examples in the docstrings.


There's a steadily growing number (100+) of standalone examples (different complexities, often combining functionality from several packages) in the examples directory.

Example screenshots(small selection)

Blog posts

Community, contributing, getting help

Join our little community on our Discord server or get in touch via Twitter or the issue tracker. If you'd like to contribute, please first read this document.

In general, we welcome contributions of all kinds (docs, examples, bug fixes, feature requests, financial contributions etc.). You can find a fairly detailed overview for contributors here: CONTRIBUTING.md.

Note: The default branch for this repo is develop and all PRs should be created based on this branch. This too means, the README files on this branch might refer to yet-unreleased features or packages. Please use the main branch for viewing the most recently released version(s)!.

Also please be sure to check the wiki for other project-wide information, tidbits, useful snippets etc.


Important changes (10/2021)

All packages are now only published in ESM format (ES2020 syntax) with TypeScript typings. You can find more details & rationale in issue #315.

As a result (and opportunity), many packages have undergone internal restructuring, some have been split up. All are now fully supporting deep-imports (based on declared export maps), leading to drastically smaller userland bundle sizes.

Previously we also created & published CommonJS & UMD formats, but deemed them an unnecessary burden & hindrance, since all important JS tooling/platforms do support ES modules by now.

Latest updates

As of: 2022-05-23



@thi.ng/argsversionchangelogDeclarative & functional CLI arg parsing & coercions
@thi.ng/apiversionchangelogCommon types, decorators, mixins
@thi.ng/benchversionchangelogBasic benchmarking helpers
@thi.ng/checksversionchangelogType & value checks
@thi.ng/composeversionchangelogFunctional composition helpers
@thi.ng/dateversionchangelogDate/time iterators, formatters, rounding
@thi.ng/defmultiversionchangelogDynamic multiple dispatch
@thi.ng/distanceversionchangelogn-D distance metrics & K-nearest neighborhoods
@thi.ng/equivversionchangelogDeep value equivalence checking
@thi.ng/errorsversionchangelogCustom error types
@thi.ng/exposeversionchangelogConditional global variable exposition
@thi.ng/hexversionchangelogHex value formatters for U4-64 words
@thi.ng/loggerversionchangelogBasis infrastructure for arbitrary logging
@thi.ng/memoizeversionchangelogFunction memoization w/ customizable caching
@thi.ng/oqueryversionchangelogPattern based query engine for JS objects
@thi.ng/parseversionchangelogParser combinators & AST generator/transformer
@thi.ng/pathsversionchangelogImmutable nested object accessors
@thi.ng/stringsversionchangelogHigher-order string formatting utils
@thi.ng/systemversionchangelogMinimal life cycle container for stateful app components
@thi.ng/testamentversionchangelogMinimal test runner


@thi.ng/dual-algebraversionchangelogDual number algebra / automatic differentiation
@thi.ng/dspversionchangelogDSP utils, composable signal gens/processors
@thi.ng/fuzzyversionchangelogFuzzy logic primitives & rule inference engine
@thi.ng/intervalsversionchangelogOpen/closed intervals, queries, set ops
@thi.ng/mathversionchangelogAssorted common math functions & utilities
@thi.ng/matricesversionchangelogMatrix operations
@thi.ng/sparseversionchangelogSparse matrix & vector impls
@thi.ng/vectorsversionchangelogFixed & arbitrary-length vector ops


@thi.ng/colored-noiseversionchangelog1D colored noise generators
@thi.ng/ksuidversionchangelogK-sortable unique identifiers, binary & base-N encoded
@thi.ng/lowdiscversionchangelogn-D Low discrepancy sequence generators
@thi.ng/randomversionchangelogSeedable PRNG implementations, distributions & utilities
@thi.ng/random-fxhashversionchangelogPRNG impl & utilities for fxhash projects

File / file format support

@thi.ng/bencodeversionchangelogBencode binary format encoding
@thi.ng/csvversionchangelogCustomizable CSV parser/object mapper
@thi.ng/dotversionchangelogGraphviz DOM & export
@thi.ng/dsp-io-wavversionchangelogWAV file format exporter
@thi.ng/file-ioversionchangelogAssorted file I/O utils for NodeJS
@thi.ng/geom-io-objversionchangelogWavefront OBJ model parser
@thi.ng/hiccup-cssversionchangelogCSS from nested JS data structures
@thi.ng/hiccup-htmlversionchangelogType-checked HTML5 element wrappers for hiccup
@thi.ng/hiccup-markdownversionchangelogHiccup-to-Markdown serialization
@thi.ng/hiccup-svgversionchangeloghiccup based SVG vocab
@thi.ng/igesversionchangelogIGES format geometry serialization
@thi.ng/markdown-tableversionchangelogMarkdown table generator / formatter
@thi.ng/mimeversionchangelogFile extension to MIME type mappings
@thi.ng/pixel-io-netpbmversionchangelog1/8/16/24bit NetPBM image format reader/writer
@thi.ng/prefixesversionchangelogLinked Data, RDF & xmlns prefixes/URLs
@thi.ng/saxversionchangelogSAX-like XML parser / transducer

Iterator, stream & sequence processing

@thi.ng/cspversionchangelogChannel based async ops
@thi.ng/fsmversionchangelogFSM / parser primitives
@thi.ng/grid-iteratorsversionchangelog2D grid iterator strategies
@thi.ng/iteratorsversionchangelogES6 generators / iterators
@thi.ng/seqversionchangelogLisp/Clojure-style sequence abstraction
@thi.ng/transducersversionchangelogComposable data transformations
@thi.ng/transducers-binaryversionchangelogBinary data related transducers
@thi.ng/transducers-fsmversionchangelogFinite state transducer
@thi.ng/transducers-hdomversionchangelogTransducer based hdom UI updates
@thi.ng/transducers-patchversionchangelogPatch-based, array & object editing
@thi.ng/transducers-statsversionchangelogTechnical / statistical analysis

Reactive programming

@thi.ng/rstreamversionchangelogPush-based, reactive event stream primitves
@thi.ng/rstream-cspversionchangelogAdapter bridge CSP -> rstream
@thi.ng/rstream-dotversionchangelogGraphviz visualization of rstream topologies
@thi.ng/rstream-gesturesversionchangelogMouse & touch event stream abstraction
@thi.ng/rstream-graphversionchangelogDeclarative dataflow graph construction
@thi.ng/rstream-logversionchangelogHierarchical structured data logging
@thi.ng/rstream-log-fileversionchangelogLog-file output handler
@thi.ng/rstream-queryversionchangelogTriple store & query engine

Algorithms & data structures

@thi.ng/adjacencyversionchangelogAdjacency matrices & graph algorithms
@thi.ng/arraysversionchangelogArray utilities
@thi.ng/associativeversionchangelogAlt Set & Map implementations
@thi.ng/atomversionchangelogImmutable value wrappers, views, history
@thi.ng/bitfieldversionchangelog1D/2D bit field implementations
@thi.ng/cacheversionchangelogIn-memory caches / strategies
@thi.ng/dconsversionchangelogDoubly-linked list
@thi.ng/diffversionchangelogArray & object diffing
@thi.ng/dgraphversionchangelogDependency graph
@thi.ng/ecsversionchangelogEntity-Component System
@thi.ng/egfversionchangelogExtensible Graph Format
@thi.ng/gpversionchangelogGenetic programming helpers / AST gen
@thi.ng/heapsversionchangelogBinary & d-ary heap impls
@thi.ng/idgenversionchangelogVersioned ID generation / free-list
@thi.ng/k-meansversionchangelogK-means clustering of n-D data
@thi.ng/rampversionchangelogParametric, interpolated lookup tables
@thi.ng/quad-edgeversionchangelogQuad-edge, dual-graph data structure
@thi.ng/resolve-mapversionchangelogDAG computations & value resolution
@thi.ng/vclockversionchangelogVector clock functions / comparators
@thi.ng/zipperversionchangelogImmutable tree editing / navigation

Frontend / UI

@thi.ng/adapt-dpiversionchangelogHDPI canvas adaptation / styling util
@thi.ng/dl-assetversionchangelogAsset/canvas/file download helpers
@thi.ng/hdiffversionchangelogString diffing w/ hiccup output (includes CLI)
@thi.ng/hdomversionchangelogHiccup based VDOM & diffing
@thi.ng/hdom-canvasversionchangeloghdom adapter for hiccup-canvas
@thi.ng/hdom-componentsversionchangeloghdom based UI components
@thi.ng/hdom-mockversionchangeloghdom mock implementation (testing / prototyping)
@thi.ng/hiccupversionchangelogS-expression based HTML/XML serialization
@thi.ng/hiccup-canvasversionchangeloghiccup interpreter for canvas api
@thi.ng/hiccup-carbon-iconsversionchangelogIBM Carbon icons in hiccup format
@thi.ng/imguiversionchangelogImmediate mode GUI
@thi.ng/interceptorsversionchangelogComposable event handlers & processor
@thi.ng/rdomversionchangelogReactive, diff-less, async UI components
@thi.ng/rdom-canvasversionchangelogrdom component wrapper for thi.ng/hiccup-canvas
@thi.ng/rdom-componentsversionchangelogUnstyled, customizable component collection
@thi.ng/routerversionchangelogCustomizable browser & non-browser router
@thi.ng/text-canvasversionchangelogText-mode canvas, drawing, tables, charts
@thi.ng/text-formatversionchangelogColor text formatting w/ ANSI & HTML presets

Geometry, image & visualization

@thi.ng/colorversionchangelogColor conversions, gradients
@thi.ng/color-palettesversionchangelogCollection of image-based color palettes
@thi.ng/dgraph-dotversionchangelogDependency graph -> Graphviz
@thi.ng/distance-transformversionchangelogImage based distance field generation
@thi.ng/fuzzy-vizversionchangelogVisualization, instrumentation for @thi.ng/fuzzy
@thi.ng/geomversionchangelog2D only geometry types & ops
@thi.ng/geom-accelversionchangelogSpatial indexing data structures
@thi.ng/geom-apiversionchangelogShared types & interfaces
@thi.ng/geom-arcversionchangelog2D elliptic arc utils
@thi.ng/geom-clip-lineversionchangelog2D line clipping
@thi.ng/geom-clip-polyversionchangelog2D convex polygon clipping
@thi.ng/geom-closest-pointversionchangelogClosest point helpers
@thi.ng/geom-fuzzversionchangelogFuzzy 2D shape drawing / filling
@thi.ng/geom-hullversionchangelog2D convex hull (Graham scan)
@thi.ng/geom-isecversionchangelogPoint & shape intersection tests
@thi.ng/geom-isolineversionchangelog2D contour line extraction
@thi.ng/geom-poly-utilsversionchangelog2D polygon helpers
@thi.ng/geom-resampleversionchangelognD polyline / curve resampling
@thi.ng/geom-splinesversionchangelognD cubic / quadratic spline ops
@thi.ng/geom-subdiv-curveversionchangelognD iterative subdivision curves
@thi.ng/geom-tessellateversionchangelognD convex polygon tessellators
@thi.ng/geom-voronoiversionchangelog2D iterative delaunay/voronoi
@thi.ng/lsysversionchangelogExtensible L-System architecture
@thi.ng/pixelversionchangelogMulti-format pixel buffers
@thi.ng/pixel-ditherversionchangelogImage dithering w/ various algorithm presets
@thi.ng/poissonversionchangelognD Poisson disk sampling
@thi.ng/porter-duffversionchangelogAlpha blending / compositing ops
@thi.ng/rasterizeversionchangelogShape drawing, filling & rasterization
@thi.ng/scenegraphversionchangelogExtensible 2D/3D scenegraph
@thi.ng/simdversionchangelogWebAssembly SIMD vector batch processing
@thi.ng/vizversionchangelogDeclarative & functional data visualization toolkit


@thi.ng/shader-astversionchangelogAST DSL for x-platform shader code
@thi.ng/shader-ast-glslversionchangelogGLSL code generator
@thi.ng/shader-ast-jsversionchangelogJS code generator
@thi.ng/shader-ast-optimizeversionchangelogAST code optimization strategies
@thi.ng/shader-ast-stdlibversionchangelog100+ useful AST shader functions
@thi.ng/webglversionchangelogWebGL 1/2 / GPGPU facilities
@thi.ng/webgl-msdfversionchangelogMSDF font rendering
@thi.ng/webgl-shadertoyversionchangelogShadertoy-like WebGL setup

Low-level, binary, memory management

@thi.ng/base-nversionchangelogArbitrary base-n encoding/decoding with presets
@thi.ng/binaryversionchangelogAssorted binary / bitwise ops, utilities
@thi.ng/bitstreamversionchangelogBitwise input / output streams
@thi.ng/dlogicversionchangelogDigital logic ops / constructs
@thi.ng/leb128versionchangelogWASM based LEB128 varint encoder / decoder
@thi.ng/mallocversionchangelogRaw & typed array memory pool & allocator
@thi.ng/mortonversionchangelogZ-order-curve / Morton coding
@thi.ng/range-coderversionchangelogBinary data Range encoder / decoder
@thi.ng/rle-packversionchangelogRun-length encoding data compression
@thi.ng/soaversionchangelogMemory mapped data structures & serialization
@thi.ng/unionstructversionchangelogWrapper for C-like structs / unions
@thi.ng/vector-poolsversionchangelogData structures for memory mapped vectors


@thi.ng/pointfreeversionchangelogStack-based DSL & functional composition
@thi.ng/pointfree-langversionchangelogForth-like syntax layer for @thi.ng/pointfree
@thi.ng/sexprversionchangelogS-Expression parser & runtime infrastructure


git clone https://github.com/thi-ng/umbrella.git
cd umbrella

yarn install
yarn build

Once the entire mono-repo has been fully built at least once before, individual packages can then be (re)built like so:

yarn workspace @thi.ng/transducers run build

# or

(cd packages/transducers && yarn build)

Building example projects

Please see the example build instructions in the wiki for further details.


(Most, but not all packages have tests)

Due to various build/config issues/complexities, we're now using our own minimal test runner @thi.ng/testament

yarn test

# or individually
yarn workspace @thi.ng/rstream run test


Autogenerated documentation (using TypeDoc) will be saved under /packages/*/doc/ and is also available at docs.thi.ng.

yarn doc

Furthermore, an experimental tsdoc-based documentation repo provides an alternative markdown output including cross-references between all packages, but currently isn't frequently updated (only every few months):



© 2015 - 2022 Karsten Schmidt // Apache Software License 2.0

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Karsten Schmidt

💻 📖 🚧 💵


💻 💡 🐛 🤔 💵

Arthur Carabott

💻 🤔 💡 📝 💵

André Wachter

💻 🤔 🐛

Gavin Cannizzaro

💻 🐛 🤔

Logan Powell

📖 🐛 🤔 💵

Marcin Ignac





🐛 💻 🤔 💵

Yifan Wu

🐛 📖


💻 🐛



Bnaya Peretz

💻 🐛 🤔



Nik Shevchenko

🐛 💻

Matei Adriel

💻 🐛 🤔

Pierre Grimaud


Matt Huebert


Raphael Saunier


Eric Ihli


David Pham



🐛 🤔

Pedro Henriques dos Santos Teixeira


Jamie Owen

💻 🐛

Robert Kesteson

🐛 💻

Chancy Kennedy


Jarred Sumner


Jamie Slome

🐛 🛡️


🐛 🛡️

Jannis Pohlmann


Shakthi Prasad G S

🐛 💻

Robin Gower


Michael Latzoni


Z Yin


Damien Seguin

🐛 💻

Rui Gil



💻 🚇 🚧

Tyler Freeman

🐛 💻



David Negstad


Muhammad Ridho

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!



GitHub Stars



2mos ago








1d ago
No alternatives found
No tutorials found
Add a tutorial