Skip to content

Commit

Permalink
chore: added comments everywhere and fixed lints
Browse files Browse the repository at this point in the history
  • Loading branch information
CalliEve committed Jun 20, 2024
1 parent da0fcaa commit b96b803
Show file tree
Hide file tree
Showing 32 changed files with 934 additions and 403 deletions.
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Calli Evers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
![Check and Deploy](https://img.shields.io/github/check-runs/callieve/metro-map-editor/main?style=flat-square)
![GitHub License](https://img.shields.io/github/license/callieve/metro-map-editor?style=flat-square)
![Website](https://img.shields.io/website?url=https%3A%2F%2Fcalli.dev%2Funiversity%2Fmetro-map&up_message=Online%20editor&up_color=blue&down_message=Temporarily%20unavailable&down_color=red&style=flat-square&label=try%20it%20out!)

# Algorithmically Assisted Metro Map Editor

This project is being made as part of my master thesis / graduation project at the [TU/e] as part of the [algo] research group.

Try it out over at the deployed [site].

## Deploy it yourself

### Prerequisites:

Ensure you have [Rust] installed.
Then, install and enable the rust nightly toolchain for this repository using `rustup toolchain install nightly && rustup override set nightly`.
Since this repository uses WASM, ensure the wasm target has been added to your rust install with `rustup target add wasm32-unknown-unknown`.
As tailwindcss is being used, [npm] is needed.
Once npm has been installed, run `npm install -D` to install the tailwindcss package.
Lastly ensure [trunk] has been installed using `cargo install --locked trunk`.

### Deploy locally

To deploy and run the editor on your local machine, you only need to run `trunk serve --open`.
This will build the project, start listening on localhost:8080 and then open it in your browser.
It will also watch for changes to the project files.

[TU/e]: https://www.tue.nl/en/
[ALGO]: https://algo.win.tue.nl/
[site]: https://calli.dev/university/metro-map
[Rust]: https://www.rust-lang.org/learn/get-started
[NPM]: https://docs.npmjs.com/downloading-and-installing-node-js-and-npm
[trunk]: https://trunkrs.dev/
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc-valid-idents = ["GraphML", ".."]
19 changes: 19 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
match_block_trailing_comma = true
struct_lit_width = 0
use_field_init_shorthand = true
chain_width = 0
array_width = 40
fn_call_width = 40

# unstable features: require nightly
# call using `cargo +nightly fmt`
wrap_comments = true
combine_control_expr = false
group_imports = "StdExternalCrate"
imports_layout = "Vertical"
imports_granularity = "Crate"
normalize_doc_attributes = true
reorder_impl_items = true
condense_wildcard_suffixes = true
force_multiline_blocks = true
format_macro_matchers = true
29 changes: 23 additions & 6 deletions src/algorithm/grid.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,56 @@
//! Contains everything for depicting the grid onto the canvas.
use wasm_bindgen::JsValue;
use web_sys::CanvasRenderingContext2d;

/// Draws the grid onto the canvas based on the given screen size and grid
/// square size. This should be called before anything else is drawn, so the
/// grid is in the background.
pub fn draw_grid(canvas: &CanvasRenderingContext2d, size: (u32, u32), square_size: u32) {
canvas.begin_path();
canvas.set_line_width(1.0);
canvas.set_stroke_style(&JsValue::from_str("grey"));

draw_vertical_lines(canvas, size.0, square_size, size.1 / square_size);
draw_horizontal_lines(canvas, size.1, square_size, size.0 / square_size);
draw_vertical_lines(
canvas,
size.0,
square_size,
size.1 / square_size,
);
draw_horizontal_lines(
canvas,
size.1,
square_size,
size.0 / square_size,
);

canvas.stroke();
}

/// Draw all vertical grid lines
fn draw_vertical_lines(
canvas: &CanvasRenderingContext2d,
length: u32,
square_size: u32,
count: u32,
) {
for i in 0..count {
let x = (i * square_size + square_size) as f64;
let x = f64::from(i * square_size + square_size);
canvas.move_to(x, 0.0);
canvas.line_to(x, length as f64);
canvas.line_to(x, f64::from(length));
}
}

/// Draw all horizontal grid lines
fn draw_horizontal_lines(
canvas: &CanvasRenderingContext2d,
length: u32,
square_size: u32,
count: u32,
) {
for i in 0..count {
let y = (i * square_size + square_size) as f64;
let y = f64::from(i * square_size + square_size);
canvas.move_to(0.0, y);
canvas.line_to(length as f64, y);
canvas.line_to(f64::from(length), y);
}
}
22 changes: 17 additions & 5 deletions src/algorithm/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
//! Contains all methods involving the algorithm itself
use wasm_bindgen::JsCast;
use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement};
use web_sys::{
CanvasRenderingContext2d,
HtmlCanvasElement,
};

mod grid;
mod objects;

use grid::draw_grid;
pub use objects::*;

use crate::state::MapState;
use crate::{
components::MapState,
models::Drawable,
};

/// Redraws the given canvas based on the given state
pub fn redraw_canvas(canvas: &HtmlCanvasElement, state: &MapState) {
// Get a 2d canvas rendering context
let context = canvas
.get_context("2d")
.unwrap()
.unwrap()
.dyn_into::<CanvasRenderingContext2d>()
.unwrap();

draw_grid(&context, state.get_size(), state.get_square_size());
draw_grid(
&context,
state.get_size(),
state.get_square_size(),
);

state
.get_map()
Expand Down
122 changes: 0 additions & 122 deletions src/algorithm/objects/line.rs

This file was deleted.

70 changes: 0 additions & 70 deletions src/algorithm/objects/map.rs

This file was deleted.

13 changes: 0 additions & 13 deletions src/algorithm/objects/mod.rs

This file was deleted.

Loading

0 comments on commit b96b803

Please sign in to comment.