Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  chore: update git attribs, remove obsolete files
  fix(geom): arg order pointAt() impl (RAY/RAY3)
  refactor(vectors): cleanup, update docs/readme
  refactor(vectors): renaming and minor fixes at point-on-ray
  feat(vectors, geom): point on ray at distance
  • Loading branch information
postspectacular committed Oct 3, 2020
2 parents 23a2ffa + 0a16a8b commit a8e08a6
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.pdf -text
*.png -text
*.gz -text
tools/doc/typedoc-theme/* linguist-vendored
9 changes: 6 additions & 3 deletions packages/geom/src/ops/point-at.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import type { IObjectOf } from "@thi.ng/api";
import { defmulti, Implementation2 } from "@thi.ng/defmulti";
import { IShape, Type } from "@thi.ng/geom-api";
import { Sampler } from "@thi.ng/geom-resample";
import { cossin, fit01, TAU } from "@thi.ng/math";
import {
cartesian2,
madd2,
maddN,
mixCubic,
mixN2,
mixQuadratic,
pointOnRay2,
pointOnRay3,
Vec,
} from "@thi.ng/vectors";
import { Arc } from "../api/arc";
Expand All @@ -22,7 +24,6 @@ import { Ray } from "../api/ray";
import { Rect } from "../api/rect";
import { dispatch } from "../internal/dispatch";
import { vertices } from "./vertices";
import type { IObjectOf } from "@thi.ng/api";

export const pointAt = defmulti<IShape, number, Vec>(dispatch);

Expand All @@ -45,7 +46,9 @@ pointAt.addAll(<IObjectOf<Implementation2<unknown, number, Vec>>>{
[Type.QUADRATIC]: ({ points }: Quadratic, t) =>
mixQuadratic([], points[0], points[1], points[2], t),

[Type.RAY]: ($: Ray, t) => maddN([], $.dir, t, $.pos),
[Type.RAY]: ($: Ray, t) => pointOnRay2([], $.pos, $.dir, t),

[Type.RAY3]: ($: Ray, t) => pointOnRay3([], $.pos, $.dir, t),

[Type.RECT]: ($: Rect, t) => new Sampler(vertices($), true).pointAt(t),
});
Expand Down
15 changes: 8 additions & 7 deletions packages/vectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ yarn add @thi.ng/vectors
<script src="https://unpkg.com/@thi.ng/vectors/lib/index.umd.js" crossorigin></script>
```

Package sizes (gzipped, pre-treeshake): ESM: 11.15 KB / CJS: 14.03 KB / UMD: 12.40 KB
Package sizes (gzipped, pre-treeshake): ESM: 11.19 KB / CJS: 14.08 KB / UMD: 12.43 KB

## Dependencies

Expand Down Expand Up @@ -446,12 +446,13 @@ Component wise op with one input vector and single scalar:

### Distances

| Function | Generic | Fixed | Strided | Int | Comments |
|-----------------|---------|-------|---------|-----|----------|
| `dist` || | | | |
| `distSq` || 2-4 | | | |
| `distChebyshev` || 2-4 | | | |
| `distManhattan` || 2-4 | | | |
| Function | Generic | Fixed | Strided | Int | Comments |
|-----------------|---------|-------|---------|-----|-------------------|
| `dist` || | | | |
| `distSq` || 2-4 | | | |
| `distChebyshev` || 2-4 | | | |
| `distManhattan` || 2-4 | | | |
| `pointOnRay` || 2-3 | | | point at distance |

### Orientation

Expand Down
1 change: 1 addition & 0 deletions packages/vectors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export * from "./normalizes";
export * from "./not";
export * from "./ortho-normal";
export * from "./perpendicular";
export * from "./point-on-ray";
export * from "./polar";
export * from "./pow";
export * from "./pown";
Expand Down
48 changes: 48 additions & 0 deletions packages/vectors/src/point-on-ray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Vec } from "./api";
import { maddN, maddN2, maddN3 } from "./maddn";

/**
* Calculates the nD point laying on ray at given distance. `rayDir` MUST be
* normalized.
*
* @param out -
* @param rayOrigin -
* @param rayDir -
* @param dist -
*/
export const pointOnRay = (
out: Vec | null,
rayOrigin: Vec,
rayDir: Vec,
dist: number
) => maddN(out, rayDir, dist, rayOrigin);

/**
* 2D version of {@link pointOnRay}.
*
* @param out -
* @param rayOrigin -
* @param rayDir -
* @param dist -
*/
export const pointOnRay2 = (
out: Vec | null,
rayOrigin: Vec,
rayDir: Vec,
dist: number
) => maddN2(out, rayDir, dist, rayOrigin);

/**
* 3D version of {@link pointOnRay}.
*
* @param out -
* @param rayOrigin -
* @param rayDir -
* @param dist -
*/
export const pointOnRay3 = (
out: Vec | null,
rayOrigin: Vec,
rayDir: Vec,
dist: number
) => maddN3(out, rayDir, dist, rayOrigin);
13 changes: 7 additions & 6 deletions packages/vectors/tpl.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,13 @@ Component wise op with one input vector and single scalar:

### Distances

| Function | Generic | Fixed | Strided | Int | Comments |
|-----------------|---------|-------|---------|-----|----------|
| `dist` || | | | |
| `distSq` || 2-4 | | | |
| `distChebyshev` || 2-4 | | | |
| `distManhattan` || 2-4 | | | |
| Function | Generic | Fixed | Strided | Int | Comments |
|-----------------|---------|-------|---------|-----|-------------------|
| `dist` || | | | |
| `distSq` || 2-4 | | | |
| `distChebyshev` || 2-4 | | | |
| `distManhattan` || 2-4 | | | |
| `pointOnRay` || 2-3 | | | point at distance |

### Orientation

Expand Down
Binary file removed tools/doc/typedoc-theme/assets/images/icons.psd
Binary file not shown.
Binary file removed tools/doc/typedoc-theme/assets/images/widgets.psd
Binary file not shown.

0 comments on commit a8e08a6

Please sign in to comment.