Skip to content

Commit

Permalink
Small demo for constraint solving (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkeeter authored Jun 6, 2024
1 parent ef544ca commit 0cf551f
Show file tree
Hide file tree
Showing 9 changed files with 469 additions and 0 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/constraints-demo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: constraints build

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./constraints
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Install wasm target
run: rustup target add wasm32-unknown-unknown
- name: Install trunk
run: |
wget -qO- https://github.com/trunk-rs/trunk/releases/download/v0.20.2/trunk-x86_64-unknown-linux-gnu.tar.gz | tar -xzf-
- name: Build wasm-demo
run: ./trunk build --release

14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
resolver = "2"
members = [
"fidget",
"constraints",
"demo",
"viewer",
"workspace-hack",
Expand Down
1 change: 1 addition & 0 deletions constraints/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
21 changes: 21 additions & 0 deletions constraints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "constraints"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
eframe = { version = "0.27", default-features = false, features = [
"default_fonts", # Embed the default egui fonts.
"glow", # Use the glow rendering backend. Alternative: "wgpu".
] }

fidget = { path = "../fidget", default-features = false, features = ["solver"] }
log = "0.4"
workspace-hack = { version = "0.1", path = "../workspace-hack" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger = "0.10.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4"
29 changes: 29 additions & 0 deletions constraints/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Demo of constraint solving
## WebAssembly
### Setup
```
cargon install +locked trunk # installs the `trunk` bundler
```
### Developing
In this folder, run
```
trunk serve
```
`trunk` will serve the webpage at `127.0.0.1:8080`

### Deploying
In this folder, run
```
trunk build --release
```
`trunk` will populate the `dist/` subfolder with assets.

If the site will be hosted at a non-root URL, then add `--public-url`, e.g.
```
trunk build --release --public-url=/projects/fidget/constraints/
```

## Native
```
cargo run -pconstraints
```
57 changes: 57 additions & 0 deletions constraints/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Disable zooming: -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">

<head>
<title>Fidget constraint demo</title>

<link data-trunk rel="rust" data-wasm-opt="2" />
<base data-trunk-public-url />

<style>
html {
/* Remove touch delay: */
touch-action: manipulation;
}

html,
body {
overflow: hidden;
margin: 0 !important;
padding: 0 !important;
height: 100%;
width: 100%;
}

div.box {
outline: 1px solid #bbb;
margin: 20px;
}

/* Position canvas in center-top: */
canvas {
display: block;
}
</style>
</head>

<body>
<!--
canvas-in-div is required because egui will float the canvas to the
top of its container; see https://github.com/emilk/egui/discussions/746
-->
<div class="box" style="position: relative; width: 300px; height: 300px">
<canvas id="the_canvas_id"></canvas>
</div>

<!--
<div class="box" style="position: relative; width: 300px; height: 300px">
<canvas id="the_other_canvas_id"></canvas>
</div>
-->
</body>

</html>
Loading

0 comments on commit 0cf551f

Please sign in to comment.