-
-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from steveruizok/vector
1.4.0
- Loading branch information
Showing
15 changed files
with
685 additions
and
169 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 |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
node_modules | ||
dist | ||
example/yarn.lock | ||
|
||
.vercel |
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
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
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
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
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
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
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,93 @@ | ||
// Some helpers for drawing SVGs. | ||
|
||
import * as vec from 'vec' | ||
|
||
// General | ||
|
||
export function ellipse(A: number[], r: number) { | ||
return `M ${A[0] - r},${A[1]} | ||
a ${r},${r} 0 1,0 ${r * 2},0 | ||
a ${r},${r} 0 1,0 -${r * 2},0 ` | ||
} | ||
|
||
export function dot(v: number[]) { | ||
return ellipse(v, 3) | ||
} | ||
|
||
export function moveTo(v: number[]) { | ||
return `M ${v[0]},${v[1]} ` | ||
} | ||
|
||
export function lineTo(v: number[]) { | ||
return `L ${v[0]},${v[1]} ` | ||
} | ||
|
||
export function line(a: number[], ...pts: number[][]) { | ||
return moveTo(a) + pts.map(p => lineTo(p)).join() | ||
} | ||
|
||
export function hLineTo(v: number[]) { | ||
return `H ${v[0]},${v[1]} ` | ||
} | ||
|
||
export function vLineTo(v: number[]) { | ||
return `V ${v[0]},${v[1]} ` | ||
} | ||
|
||
// /** | ||
// * Return the path for a rectangle between two points. | ||
// * @param a | ||
// * @param b | ||
// * @returns | ||
// */ | ||
// export function rectFromBounds(bounds: IBounds) { | ||
// const { minX, maxX, minY, maxY } = bounds | ||
// return [ | ||
// moveTo([minX, maxX]), | ||
// lineTo([maxX, minY]), | ||
// lineTo([maxX, maxY]), | ||
// lineTo([minX, minY]), | ||
// closePath(), | ||
// ].join(' ') | ||
// } | ||
|
||
// /** | ||
// * Return the path for a rectangle with a given point and size. | ||
// * @param point | ||
// * @param size | ||
// * @returns | ||
// */ | ||
// export function rect(point: number[], size: number[]) { | ||
// return rectFromBounds(getBoundsBetweenPoints(point, vec.add(point, size))) | ||
// } | ||
|
||
export function bezierTo(A: number[], B: number[], C: number[]) { | ||
return `C ${A[0]},${A[1]} ${B[0]},${B[1]} ${C[0]},${C[1]} ` | ||
} | ||
|
||
// export function arcTo(C: number[], r: number, A: number[], B: number[]) { | ||
// return [ | ||
// // moveTo(A), | ||
// 'A', | ||
// r, | ||
// r, | ||
// 0, | ||
// getSweep(C, A, B) > 0 ? '1' : '0', | ||
// 0, | ||
// B[0], | ||
// B[1], | ||
// ].join(' ') | ||
// } | ||
|
||
export function closePath() { | ||
return 'Z' | ||
} | ||
|
||
export function rectTo(A: number[]) { | ||
return ['R', A[0], A[1]].join(' ') | ||
} | ||
|
||
export function getPointAtLength(path: SVGPathElement, length: number) { | ||
const point = path.getPointAtLength(length) | ||
return [point.x, point.y] | ||
} |
Oops, something went wrong.