This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new SpaceFilling interface, and made hilbert.Space implement it.
- Loading branch information
Showing
2 changed files
with
39 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package hilbert | ||
|
||
import "errors" | ||
|
||
// Errors returned when validating input. | ||
var ( | ||
ErrNotPositive = errors.New("N must be greater than zero") | ||
ErrNotPowerOfTwo = errors.New("N must be a power of two") | ||
ErrNotPowerOfThree = errors.New("N must be a power of three") | ||
ErrOutOfRange = errors.New("value is out of range") | ||
) | ||
|
||
type SpaceFilling interface { | ||
// Map transforms a one dimension value, t, in the range [0, n^2-1] to coordinates on the Hilbert | ||
// curve in the two-dimension space, where x and y are within [0,n-1]. | ||
Map(t int) (x, y int, err error) | ||
|
||
// MapInverse transform coordinates on Hilbert Curve from (x,y) to t. | ||
MapInverse(x, y int) (t int, err error) | ||
|
||
// Returns the width and height of the 2D space. | ||
GetDimensions() (x, y int) | ||
} | ||
|
||
func b2i(b bool) int { | ||
if b { | ||
return 1 | ||
} | ||
return 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters