Skip to content

Commit 1e22cce

Browse files
committed
chore(example): update example and readme
1 parent e704c0c commit 1e22cce

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Internally the `valueOf()` implementation returns `x` in first call, `y` in seco
8989

9090
[![code preview](https://us-central1-code-snippet-to-svg.cloudfunctions.net/default/basics/vector/blob/master/examples/example.js?theme=atom_one_light&range=42-48)](https://github.com/basics/vector/blob/master/examples/example.js)
9191

92+
### normalize only with arithmetic
93+
94+
[![code preview](https://us-central1-code-snippet-to-svg.cloudfunctions.net/default/basics/vector/blob/master/examples/example.js?theme=atom_one_light&range=58-63)](https://github.com/basics/vector/blob/master/examples/example.js)
95+
9296
## immutable vector called Victor
9397

9498
behaves exactly like Vector but code cant change its `x`, `y` and `z` axes.

examples/example.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ try {
5656
// error: Error: set x() not implemented
5757
}
5858

59+
// normalize only with arithmetic
60+
const norm = calc(() => offsetA / offsetA.length);
61+
console.log(debug`norm: ${norm}`);
62+
// norm: { x: 0.967, y: 0.1658, z: 0.1934 }
63+
5964
// creating vector inside calculation works, but has overhead
6065
const inlineVec = new Victor(() => new Victor(25, 30) / 2);
6166
console.log(debug`inlineVec: ${inlineVec}`);

0 commit comments

Comments
 (0)