gonum.org/v1/gonum@v0.15.1-0.20240517103525-f853624cb1bb/spatial/curve/doc.go (about) 1 // Copyright ©2024 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package curve defines space filling curves. A space filling curve is a curve 6 // whose range contains the entirety of a finite k-dimensional space. Space 7 // filling curves can be used to map between a linear space and a 2D, 3D, or 4D 8 // space. 9 // 10 // # Hilbert Curves 11 // 12 // The Hilbert curve is a continuous, space filling curve first described by 13 // David Hilbert. The implementation of Hilbert2D is based on example code from 14 // the [Hilbert curve (Wikipedia)]. The implementation of Hilbert3D and 15 // Hilbert4D are extrapolated from Hilbert2D. 16 // 17 // Technically, a Hilbert curve is a continuous, fractal, space-filling curve of 18 // infinite length, constructed as the limit of a series of piecewise linear 19 // curves. We refer to the kth piecewise linear curve as the k-order Hilbert 20 // curve. The first-order 2D Hilbert curve looks like ⊐. The k-order 21 // n-dimensional curve can be constructed from 2ⁿ copies of the (k-1) order 22 // curve. These (finite) Hilbert curves are iterative/recursive, and the order 23 // refers to the iteration number. 24 // 25 // The runtime of Space and Curve scales as O(n∙k) where n is the dimension and 26 // k is the order. The length of the curve is 2^(n∙k). 27 // 28 // # Limitations 29 // 30 // An n-dimensional, k-order Hilbert curve will not be fully usable if 2ⁿᵏ 31 // overflows int (which is dependent on architecture). Len will overflow if n∙k 32 // ≥ bits.UintSize-1. Curve will overflow if n∙k > bits.UintSize-1 for some 33 // values of v. Space will not overflow, but it cannot be called with values 34 // that do not fit in a signed integer, thus only a subset of the curve can be 35 // utilized. 36 // 37 // [Hilbert curve (Wikipedia)]: https://en.wikipedia.org/w/index.php?title=Hilbert_curve&oldid=1011599190 38 package curve