Skip to content

Commit

Permalink
refactor: rewrite of ink-stroke-modeler in Rust (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doublonmousse authored Jun 6, 2024
1 parent 94d5d72 commit 124cde7
Show file tree
Hide file tree
Showing 35 changed files with 5,193 additions and 2,428 deletions.
6 changes: 0 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
[submodule "ink-stroke-modeler"]
path = ink-stroke-modeler
url = https://github.com/flxzt/ink-stroke-modeler
[submodule "abseil-cpp"]
path = abseil-cpp
url = https://github.com/abseil/abseil-cpp.git
28 changes: 7 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
[package]
build = "build.rs"
edition = "2021"
license = "MIT OR Apache-2.0"
name = "ink-stroke-modeler-rs"
rust-version = "1.65"
license = "MIT OR Apache-2.0"
version = "0.1.0"

[dependencies]
autocxx = "0.26.0"
cxx = "1.0"
thiserror = "1.0"

[build-dependencies]
anyhow = "1.0"
autocxx-build = "0.26.0"
autocxx-engine = "0.26.0"
cmake = "0.1.50"
path-slash = "0.2.1"
pkg-config = "0.3.30"
edition = "2021"
rust-version = "1.65"

[dev-dependencies]
approx = "0.5.1"
anyhow = "1.0"
svg = "0.17.0"
svg = "0.16.0"
tracing = "0.1.40"

[features]
default = ["build_absl"]
build_absl = []
[dependencies]
13 changes: 2 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,11 @@
[![main docs](https://img.shields.io/badge/docs-main-informational)](https://flxzt.github.io/ink-stroke-modeler-rs/ink_stroke_modeler_rs/)
[![CI](https://github.com/flxzt/ink-stroke-modeler-rs/actions/workflows/ci.yaml/badge.svg)](https://github.com/flxzt/ink-stroke-modeler-rs/actions/workflows/ci.yaml)

WIP Rust bindings for [https://github.com/google/ink-stroke-modeler](https://github.com/google/ink-stroke-modeler), using `autocxx`

# External Dependencies
- `cmake`
- `libclang`
Partial rust rewrite of [https://github.com/google/ink-stroke-modeler](https://github.com/google/ink-stroke-modeler). Beware that not all functionalities are implemented (no kalman-based prediction) and the API is not identical either.

# Usage

Run `cargo doc --open` to view the documentation.

It is possible to choose between building the absl-cpp dependency in the crate and statically link it,
or use the system dependency. Then the `absl-cpp-dev` (or equivalent) package must be installed.

Toggled via the cargo feature `build_absl`.
Run `cargo doc --open` to view the documentation or check `examples/stroke.rs` for a full example

### License

Expand Down
1 change: 0 additions & 1 deletion abseil-cpp
Submodule abseil-cpp deleted from d7aaad
150 changes: 0 additions & 150 deletions build.rs

This file was deleted.

6 changes: 6 additions & 0 deletions docs/math_part.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "notations.typ"
#include "wobble.typ"
#include "resampling.typ"
#include "position_modeling.typ"
#include "stroke_end.typ"
#include "stylus_state_modeler.typ"
47 changes: 47 additions & 0 deletions docs/notations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<h2>Notations</h2>
<div class="box">
<p>We denote :</p>
<ul>
<li><p>Pressure :
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ν</mi><mo></mo><mo stretchy="false" form="prefix">[</mo><mn>0</mn><mo>,</mo><mn>1</mn><mo stretchy="false" form="postfix">]</mo></mrow><annotation encoding="application/x-tex">\nu \in \lbrack 0,1\rbrack</annotation></semantics></math></p></li>
<li><p>time :
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi><mo></mo><mn>0</mn></mrow><annotation encoding="application/x-tex">t \geq 0</annotation></semantics></math></p></li>
<li><p>point : defined by position
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>x</mi><annotation encoding="application/x-tex">x</annotation></semantics></math>
and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mi>y</mi><annotation encoding="application/x-tex">y</annotation></semantics></math>
(or
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="true" form="postfix">)</mo></mrow><mo></mo><msup><mi></mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">p = (x,y) \in {\mathbb{R}}^{2}</annotation></semantics></math>)</p></li>
<li><p>Raw inputs are denoted by a tuple
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo stretchy="false" form="prefix">[</mo><mi>k</mi><mo stretchy="false" form="postfix">]</mo><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mi>ν</mi><mo stretchy="false" form="prefix">[</mo><mi>k</mi><mo stretchy="false" form="postfix">]</mo><mo>,</mo><mi>t</mi><mo stretchy="false" form="prefix">[</mo><mi>k</mi><mo stretchy="false" form="postfix">]</mo><mo>,</mo><mi>x</mi><mo stretchy="false" form="prefix">[</mo><mi>k</mi><mo stretchy="false" form="postfix">]</mo><mo>,</mo><mi>y</mi><mo stretchy="false" form="prefix">[</mo><mi>k</mi><mo stretchy="false" form="postfix">]</mo><mo stretchy="true" form="postfix">)</mo></mrow></mrow><annotation encoding="application/x-tex">i\lbrack k\rbrack = \left( \nu\lbrack k\rbrack,t\lbrack k\rbrack,x\lbrack k\rbrack,y\lbrack k\rbrack \right)</annotation></semantics></math>
with
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mo></mo><mi></mi></mrow><annotation encoding="application/x-tex">k \in {\mathbb{N}}</annotation></semantics></math>.</p></li>
</ul>
</div>
<div class="box">
<p>An <em>input stream</em> is a sequence of raw inputs
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><mi>ν</mi><mo>,</mo><mi>t</mi><mo>,</mo><mi>x</mi><mo>,</mo><mi>y</mi><mo stretchy="true" form="postfix">)</mo></mrow></mrow><annotation encoding="application/x-tex">i = (\nu,t,x,y)</annotation></semantics></math></p>
<ul>
<li><p>with time
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi><mo stretchy="false" form="prefix">[</mo><mi>k</mi><mo stretchy="false" form="postfix">]</mo></mrow><annotation encoding="application/x-tex">t\lbrack k\rbrack</annotation></semantics></math>
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo></mo><mo></mo></mrow><annotation encoding="application/x-tex">\nearrow \nearrow</annotation></semantics></math>
strictly increasing</p></li>
<li><p>starts with a <code>Down</code> event</p></li>
<li><p>contains <code>Move</code> for
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mo></mo><mn>1</mn></mrow><annotation encoding="application/x-tex">k \geq 1</annotation></semantics></math></p></li>
<li><p>ends either with a <code>Move</code> or a <code>Up</code> . If it
is a <code>Up</code> we say the input stream is
<em>complete</em></p></li>
</ul>
</div>
<div class="box">
<p>We addition define</p>
<ul>
<li><p><math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>v</mi><mi>x</mi></msub><mo>,</mo><msub><mi>v</mi><mi>y</mi></msub><mo>,</mo><msub><mi>a</mi><mi>x</mi></msub><mo>,</mo><msub><mi>a</mi><mi>y</mi></msub></mrow><annotation encoding="application/x-tex">v_{x},v_{y},a_{x},a_{y}</annotation></semantics></math>
as the velocity and acceleration.</p></li>
</ul>
<p>With the vector shorthand
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>v</mi><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><msub><mi>v</mi><mi>x</mi></msub><mo>,</mo><msub><mi>v</mi><mi>y</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow><mo></mo><msup><mi></mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">v = \left( v_{x},v_{y} \right) \in {\mathbb{R}}^{2}</annotation></semantics></math>
and
<math display="inline" xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>a</mi><mo>=</mo><mrow><mo stretchy="true" form="prefix">(</mo><msub><mi>a</mi><mi>x</mi></msub><mo>,</mo><msub><mi>a</mi><mi>y</mi></msub><mo stretchy="true" form="postfix">)</mo></mrow><mo></mo><msup><mi></mi><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">a = \left( a_{x},a_{y} \right) \in {\mathbb{R}}^{2}</annotation></semantics></math></p>
</div>
31 changes: 31 additions & 0 deletions docs/notations.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#set page(width: 16cm, margin: 0.5em, height: auto)
#let definition(content) = box(fill: luma(92%), width: 100%, inset: 0.5em, stroke: black)[#content]

#import "@preview/lovelace:0.2.0": *
#show: setup-lovelace.with(body-inset: 0pt)

#let pr = $nu$
#let time = $t$
== Notations

#definition[
We denote :
- Pressure : $pr in [0,1]$
- time : $t >=0$
- point : defined by position $x$ and $y$ (or $p = (x,y) in RR^2$)
- Raw inputs are denoted by a tuple $i[k] = (pr[k], t[k], x[k],y[k])$ with $k in NN$.
]

#definition[
An _input stream_ is a sequence of raw inputs $i = (pr, t,x,y)$
- with time $t[k]$ $arrow.tr arrow.tr$ strictly increasing
- starts with a #raw("Down") event
- contains #raw("Move") for $k >=1$
- ends either with a #raw("Move") or a #raw("Up") . If it is a #raw("Up") we say the input stream is _complete_
]

#definition[
We addition define
- $v_x, v_y, a_x, a_y$ as the velocity and acceleration.
With the vector shorthand $v = (v_x,v_y) in RR^2$ and $a = (a_x, a_y) in RR^2$
]
Loading

0 comments on commit 124cde7

Please sign in to comment.