Skip to content

Commit

Permalink
Version 1 complete
Browse files Browse the repository at this point in the history
  • Loading branch information
kjerandp committed Nov 23, 2019
1 parent 76bdc3d commit 507ae30
Show file tree
Hide file tree
Showing 19 changed files with 478 additions and 136 deletions.
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
A lib for interpolating values over a cubic Cardinal/Catmull-Rom spline curve.

## Installation
```
```bash
npm install --save curve-interpolator
```
## Usage
## Basic usage
Reference the CurveInterpolator class:
```js
// commonjs
Expand All @@ -31,8 +31,37 @@ const points = [
...
];

const interp = new CurveInterpolator(points);
const tension = 0.2;
const interp = new CurveInterpolator(points, tension);

// get single point
const position = 0.3 // [0 - 1]
const pt = interp.getPointAt(position)

// get points evently distributed along the curve
const nPoints = 1000;
const pts = interp.getPoints(nPoints - 1);

// lookup values along x and y axises
const yintersects = interp.y(position);

/*
max number of solutions (0 = all (default), 1 = first, -1 = last)
A negative max value counts solutions from end of curve
*/
const max = -1;
const xintersects = interp.x(position, max);

// get bounding box
const bbox = interp.getBoundingBox();
```

## Docs
Docs are generated using typedoc in `./docs`. To create:
```bash
npm run docs
```


## License
MIT
178 changes: 143 additions & 35 deletions docs/classes/_curve_interpolator_.curveinterpolator.html

Large diffs are not rendered by default.

29 changes: 22 additions & 7 deletions docs/classes/_point_.point.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ <h1>Class Point</h1>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Sample class that may be used as Return type.</p>
</div>
<dl class="tsd-comment-tags">
<dt>example</dt>
<dd><p>interp.getPointAt(0.2, new Point());</p>
</dd>
<dt>example</dt>
<dd><p>interp.getPoints(1000, Point);</p>
</dd>
</dl>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
Expand Down Expand Up @@ -116,7 +131,7 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L3">point.ts:3</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L8">point.ts:8</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -141,7 +156,7 @@ <h3>x</h3>
<div class="tsd-signature tsd-kind-icon">x<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L2">point.ts:2</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L7">point.ts:7</a></li>
</ul>
</aside>
</section>
Expand All @@ -151,7 +166,7 @@ <h3>y</h3>
<div class="tsd-signature tsd-kind-icon">y<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L3">point.ts:3</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L8">point.ts:8</a></li>
</ul>
</aside>
</section>
Expand All @@ -169,15 +184,15 @@ <h3>0</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L10">point.ts:10</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L15">point.ts:15</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4>
</li>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L14">point.ts:14</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L19">point.ts:19</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -201,15 +216,15 @@ <h3>1</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L18">point.ts:18</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L23">point.ts:23</a></li>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4>
</li>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/point.ts#L22">point.ts:22</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/point.ts#L27">point.ts:27</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down
35 changes: 31 additions & 4 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ <h1>Curve Interpolator</h1>
<a href="#installation" id="installation" style="color: inherit; text-decoration: none;">
<h2>Installation</h2>
</a>
<pre><code>npm install --<span class="hljs-keyword">save</span> <span class="hljs-built_in">curve</span>-interpolator</code></pre>
<a href="#usage" id="usage" style="color: inherit; text-decoration: none;">
<h2>Usage</h2>
<pre><code class="language-bash">npm install --save curve-interpolator</code></pre>
<a href="#basic-usage" id="basic-usage" style="color: inherit; text-decoration: none;">
<h2>Basic usage</h2>
</a>
<p>Reference the CurveInterpolator class:</p>
<pre><code class="language-js"><span class="hljs-comment">// commonjs</span>
Expand All @@ -94,7 +94,34 @@ <h2>Usage</h2>
...
];

<span class="hljs-keyword">const</span> interp = <span class="hljs-keyword">new</span> CurveInterpolator(points);</code></pre>
<span class="hljs-keyword">const</span> tension = <span class="hljs-number">0.2</span>;
<span class="hljs-keyword">const</span> interp = <span class="hljs-keyword">new</span> CurveInterpolator(points, tension);

<span class="hljs-comment">// get single point</span>
<span class="hljs-keyword">const</span> position = <span class="hljs-number">0.3</span> <span class="hljs-comment">// [0 - 1]</span>
<span class="hljs-keyword">const</span> pt = interp.getPointAt(position)

<span class="hljs-comment">// get points evently distributed along the curve</span>
<span class="hljs-keyword">const</span> nPoints = <span class="hljs-number">1000</span>;
<span class="hljs-keyword">const</span> pts = interp.getPoints(nPoints - <span class="hljs-number">1</span>);

<span class="hljs-comment">// lookup values along x and y axises</span>
<span class="hljs-keyword">const</span> yintersects = interp.y(position);

<span class="hljs-comment">/*
max number of solutions (0 = all (default), 1 = first, -1 = last)
A negative max value counts solutions from end of curve
*/</span>
<span class="hljs-keyword">const</span> max = <span class="hljs-number">-1</span>;
<span class="hljs-keyword">const</span> xintersects = interp.x(position, max);

<span class="hljs-comment">// get bounding box</span>
<span class="hljs-keyword">const</span> bbox = interp.getBoundingBox();</code></pre>
<a href="#docs" id="docs" style="color: inherit; text-decoration: none;">
<h2>Docs</h2>
</a>
<p>Docs are generated using typedoc in <code>./docs</code>. To create:</p>
<pre><code class="language-bash">npm run docs</code></pre>
<a href="#license" id="license" style="color: inherit; text-decoration: none;">
<h2>License</h2>
</a>
Expand Down
15 changes: 11 additions & 4 deletions docs/interfaces/_interfaces_.bbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ <h1>Interface BBox</h1>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Bounding box interface</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
Expand Down Expand Up @@ -101,7 +108,7 @@ <h3>x1</h3>
<div class="tsd-signature tsd-kind-icon">x1<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L31">interfaces.ts:31</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L44">interfaces.ts:44</a></li>
</ul>
</aside>
</section>
Expand All @@ -111,7 +118,7 @@ <h3>x2</h3>
<div class="tsd-signature tsd-kind-icon">x2<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L33">interfaces.ts:33</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L46">interfaces.ts:46</a></li>
</ul>
</aside>
</section>
Expand All @@ -121,7 +128,7 @@ <h3>y1</h3>
<div class="tsd-signature tsd-kind-icon">y1<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L32">interfaces.ts:32</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L45">interfaces.ts:45</a></li>
</ul>
</aside>
</section>
Expand All @@ -131,7 +138,7 @@ <h3>y2</h3>
<div class="tsd-signature tsd-kind-icon">y2<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L34">interfaces.ts:34</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L47">interfaces.ts:47</a></li>
</ul>
</aside>
</section>
Expand Down
17 changes: 12 additions & 5 deletions docs/interfaces/_interfaces_.bboxoptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ <h1>Interface BBoxOptions</h1>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Options to control calculation of bounding box</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
Expand Down Expand Up @@ -102,7 +109,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> arc<wbr>Divisions</h3
<div class="tsd-signature tsd-kind-icon">arc<wbr>Divisions<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L41">interfaces.ts:41</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L57">interfaces.ts:57</a></li>
</ul>
</aside>
</section>
Expand All @@ -112,7 +119,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> arc<wbr>Lengths</h3>
<div class="tsd-signature tsd-kind-icon">arc<wbr>Lengths<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">[]</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L42">interfaces.ts:42</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L58">interfaces.ts:58</a></li>
</ul>
</aside>
</section>
Expand All @@ -122,7 +129,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> from</h3>
<div class="tsd-signature tsd-kind-icon">from<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L39">interfaces.ts:39</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L55">interfaces.ts:55</a></li>
</ul>
</aside>
</section>
Expand All @@ -132,7 +139,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> tension</h3>
<div class="tsd-signature tsd-kind-icon">tension<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L38">interfaces.ts:38</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L54">interfaces.ts:54</a></li>
</ul>
</aside>
</section>
Expand All @@ -142,7 +149,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> to</h3>
<div class="tsd-signature tsd-kind-icon">to<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L40">interfaces.ts:40</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L56">interfaces.ts:56</a></li>
</ul>
</aside>
</section>
Expand Down
19 changes: 13 additions & 6 deletions docs/interfaces/_interfaces_.lookupoptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ <h1>Interface LookupOptions</h1>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<section class="tsd-panel tsd-comment">
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Used by the valuesLookup function to set axis, tension etc.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
Expand Down Expand Up @@ -103,7 +110,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> axis</h3>
<div class="tsd-signature tsd-kind-icon">axis<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L22">interfaces.ts:22</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L32">interfaces.ts:32</a></li>
</ul>
</aside>
</section>
Expand All @@ -113,7 +120,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> func</h3>
<div class="tsd-signature tsd-kind-icon">func<span class="tsd-signature-symbol">:</span> <a href="../modules/_interfaces_.html#pointfunction" class="tsd-signature-type">PointFunction</a></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L26">interfaces.ts:26</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L36">interfaces.ts:36</a></li>
</ul>
</aside>
</section>
Expand All @@ -123,7 +130,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> margin</h3>
<div class="tsd-signature tsd-kind-icon">margin<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L24">interfaces.ts:24</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L34">interfaces.ts:34</a></li>
</ul>
</aside>
</section>
Expand All @@ -133,7 +140,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> max</h3>
<div class="tsd-signature tsd-kind-icon">max<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L25">interfaces.ts:25</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L35">interfaces.ts:35</a></li>
</ul>
</aside>
</section>
Expand All @@ -143,7 +150,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> processXY</h3>
<div class="tsd-signature tsd-kind-icon">processXY<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">boolean</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L27">interfaces.ts:27</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L37">interfaces.ts:37</a></li>
</ul>
</aside>
</section>
Expand All @@ -153,7 +160,7 @@ <h3><span class="tsd-flag ts-flagOptional">Optional</span> tension</h3>
<div class="tsd-signature tsd-kind-icon">tension<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/57e58ca/src/interfaces.ts#L23">interfaces.ts:23</a></li>
<li>Defined in <a href="https://github.com/kjerandp/curve-interpolator/blob/76bdc3d/src/interfaces.ts#L33">interfaces.ts:33</a></li>
</ul>
</aside>
</section>
Expand Down
Loading

0 comments on commit 507ae30

Please sign in to comment.