From 4ebdd1abb1225aa8c3acc12c3ca4db42dd199588 Mon Sep 17 00:00:00 2001 From: Rob Nadal Date: Wed, 27 Jul 2022 17:30:08 -0400 Subject: [PATCH] Added Subpaths to bezier-rs (#730) * Added Subpath constructor, iterator and length * Asserted that subpaths of len < 2 cannot be closed. Added len() and comments * Added subpath to_svg(), made structs public, made quadratic use either in_handle or out_handle * add bezier handles * Added basic interactivity and index traits * Added SubPath interactivity * Added svg styling * Broke subpath impl across multiple files. More sylistic changes per review * Fixed format error * Added closed subpath to documentation page * Modified subpath to_svg to use functional style * Stylistic changes per review * Fixed build errors * More sylistic changes per review * Moved svg commands to constants * Moved formatting for svg arguments to ToSVGOptions * Renamed files in git * Even more stylistic changes per review --- bezier-rs/docs/interactive-docs/src/App.vue | 30 ++++-- .../src/components/Example.vue | 11 +-- .../src/components/ExamplePane.vue | 11 +-- .../src/components/SliderExample.vue | 7 +- .../src/components/SubpathExample.vue | 79 +++++++++++++++ .../src/components/SubpathExamplePane.vue | 72 ++++++++++++++ .../interactive-docs/src/utils/drawing.ts | 2 +- .../docs/interactive-docs/src/utils/types.ts | 4 + .../docs/interactive-docs/wasm/src/lib.rs | 5 +- .../docs/interactive-docs/wasm/src/subpath.rs | 47 +++++++++ .../interactive-docs/wasm/src/svg_drawing.rs | 11 +++ bezier-rs/lib/src/consts.rs | 7 ++ bezier-rs/lib/src/lib.rs | 50 +++++++--- bezier-rs/lib/src/subpath/core.rs | 88 +++++++++++++++++ bezier-rs/lib/src/subpath/lookup.rs | 95 +++++++++++++++++++ bezier-rs/lib/src/subpath/mod.rs | 68 +++++++++++++ bezier-rs/lib/src/subpath/structs.rs | 83 ++++++++++++++++ 17 files changed, 634 insertions(+), 36 deletions(-) create mode 100644 bezier-rs/docs/interactive-docs/src/components/SubpathExample.vue create mode 100644 bezier-rs/docs/interactive-docs/src/components/SubpathExamplePane.vue create mode 100644 bezier-rs/docs/interactive-docs/wasm/src/subpath.rs create mode 100644 bezier-rs/docs/interactive-docs/wasm/src/svg_drawing.rs create mode 100644 bezier-rs/lib/src/subpath/core.rs create mode 100644 bezier-rs/lib/src/subpath/lookup.rs create mode 100644 bezier-rs/lib/src/subpath/mod.rs create mode 100644 bezier-rs/lib/src/subpath/structs.rs diff --git a/bezier-rs/docs/interactive-docs/src/App.vue b/bezier-rs/docs/interactive-docs/src/App.vue index ed1750ad..9340d028 100644 --- a/bezier-rs/docs/interactive-docs/src/App.vue +++ b/bezier-rs/docs/interactive-docs/src/App.vue @@ -2,7 +2,8 @@

Bezier-rs Interactive Documentation

This is the interactive documentation for the bezier-rs library. Click and drag on the endpoints of the example curves to visualize the various Bezier utilities and functions.

-
+

Beziers

+
+

Subpaths

+
+ +
@@ -21,10 +26,11 @@ import { defineComponent, markRaw } from "vue"; import { drawText, drawPoint, drawBezier, drawLine, getContextFromCanvas, drawBezierHelper, COLORS } from "@/utils/drawing"; -import { BezierCurveType, Point, WasmBezierInstance } from "@/utils/types"; +import { BezierCurveType, Point, WasmBezierInstance, WasmSubpathInstance } from "@/utils/types"; import ExamplePane from "@/components/ExamplePane.vue"; import SliderExample from "@/components/SliderExample.vue"; +import SubpathExamplePane from "@/components/SubpathExamplePane.vue"; const tSliderOptions = { min: 0, @@ -37,13 +43,9 @@ const tSliderOptions = { const SCALE_UNIT_VECTOR_FACTOR = 50; export default defineComponent({ - name: "App", - components: { - ExamplePane, - }, data() { return { - features: [ + bezierFeatures: [ { name: "Constructor", // eslint-disable-next-line @@ -355,8 +357,22 @@ export default defineComponent({ }, }, ], + subpathFeatures: [ + { + name: "Constructor", + callback: (subpath: WasmSubpathInstance): string => subpath.to_svg(), + }, + { + name: "Length", + callback: (subpath: WasmSubpathInstance): string => subpath.length(), + }, + ], }; }, + components: { + ExamplePane, + SubpathExamplePane, + }, }); diff --git a/bezier-rs/docs/interactive-docs/src/components/Example.vue b/bezier-rs/docs/interactive-docs/src/components/Example.vue index ec5dce8a..b5411bca 100644 --- a/bezier-rs/docs/interactive-docs/src/components/Example.vue +++ b/bezier-rs/docs/interactive-docs/src/components/Example.vue @@ -12,12 +12,6 @@ import BezierDrawing from "@/components/BezierDrawing"; import { BezierCallback, WasmBezierInstance } from "@/utils/types"; export default defineComponent({ - name: "ExampleComponent", - data() { - return { - bezierDrawing: new BezierDrawing(this.bezier, this.callback, this.options, this.createThroughPoints), - }; - }, props: { title: String, bezier: { @@ -37,6 +31,11 @@ export default defineComponent({ default: false, }, }, + data() { + return { + bezierDrawing: new BezierDrawing(this.bezier, this.callback, this.options, this.createThroughPoints), + }; + }, mounted() { const drawing = this.$refs.drawing as HTMLElement; drawing.appendChild(this.bezierDrawing.getCanvas()); diff --git a/bezier-rs/docs/interactive-docs/src/components/ExamplePane.vue b/bezier-rs/docs/interactive-docs/src/components/ExamplePane.vue index 1cded33d..8b919503 100644 --- a/bezier-rs/docs/interactive-docs/src/components/ExamplePane.vue +++ b/bezier-rs/docs/interactive-docs/src/components/ExamplePane.vue @@ -1,6 +1,6 @@