|
|
4 years ago | |
|---|---|---|
| .. | ||
| img | 4 years ago | |
| test | 4 years ago | |
| .npmignore | 4 years ago | |
| LICENSE | 4 years ago | |
| README.md | 4 years ago | |
| abs.js | 4 years ago | |
| add.js | 4 years ago | |
| cmp.js | 4 years ago | |
| div.js | 4 years ago | |
| divs.js | 4 years ago | |
| dot.js | 4 years ago | |
| equals.js | 4 years ago | |
| index.js | 4 years ago | |
| is-vec.js | 4 years ago | |
| lerp.js | 4 years ago | |
| max.js | 4 years ago | |
| min.js | 4 years ago | |
| mul.js | 4 years ago | |
| muls.js | 4 years ago | |
| neg.js | 4 years ago | |
| package.json | 4 years ago | |
| recip.js | 4 years ago | |
| sub.js | 4 years ago | |
| to-float.js | 4 years ago | |
README.md
rat-vec
Exact rational vector arithmetic.
rat-vec is slow but reliable. You can use it to get quickly and reliably implement geometric algorithms, then go back and smash your head into a wall trying to optimize them with filters and predicates and snap rounding and so on.
This library is built on top of bn.js
Example
var vec = require('rat-vec')
var toFloat = require('rat-vec/to-float')
var add = require('rat-vec/add')
var sub = require('rat-vec/sub')
var dot = require('rat-vec/sub')
Install
npm i rat-vec
API
A rat-vec is an array of big-rats.
var r = require('rat-vec')(v)
Converts a vector of n floating point numbers into an exact rational vector of n+1 big ints.
vis a vector of floats,big-rats or strings
Returns A rational vector of big integers
require('rat-vec/is-vec')(v)
Test if v is a rat-vec
var v = require('rat-vec/to-float')(r)
Rounds a vector of big-rats into a
ris a vector ofnbig integers
Returns A vector of n floats representing the closest representable vector
var s = require('rat-vec/add')(a, b)
Returns The vector sum of a and b
var d = require('rat-vec/sub')(a, b)
Returns The vector difference of a and b
var f = require('rat-vec/dot')(a, b)
Returns The dot product of a and b
var v = require('rat-vec/muls')(a, s)
Returns The scalar product of a and s, where s is a float, big-rat or string
var v = require('rat-vec/divs')(a, s)
Returns a divided by the scalar s
var lerp = require('rat-vec/lerp')(a, b, t)
Linearly interpolate between a and b with parameter t
var c = require('rat-vec/cmp')(a, b)
Compares the components of a and b, returns an array of 0,+1,-1 whose components are the result of comparing each value.
var eq = require('rat-vec/equals')(a, b)
Test if two rational vectors are equal.
var h = require('rat-vec/max')(a, b)
Computes the component-wise maximum of a and b
var l = require('rat-vec/min')(a, b)
Computes the component-wise minimum of a and b
var p = require('rat-vec/mul')(a, b)
Computes the component-wise product of a and b
var r = require('rat-vec/recip')(a)
Computes the component-wise reciprocal of a
var q = require('rat-vec/div')(a, b)
Computes the component-wise quotient of a and b
var n = require('rat-vec/neg')(x)
Computes the additive inverse of x
var n = require('rat-vec/abs')(x)
Computes the component-wise absolute value of x
Credits
(c) 2015, MIT License