Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirabellensaft committed Dec 22, 2023
1 parent 1f2b0b9 commit 6276fbe
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- name: Format check
run: cargo fmt --check --manifest-path sanguine/
run: cargo fmt --check
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
Expand Down
2 changes: 1 addition & 1 deletion output/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use chrono::Local;
use std::env;

mod work;
use work::{star_burst, voronoi, voronoi_simple, voronated_star_burst};
use work::{star_burst, voronated_star_burst, voronoi, voronoi_simple};

fn main() {
env::set_var("RUST_BACKTRACE", "1");
Expand Down
2 changes: 1 addition & 1 deletion output/src/work/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod star_burst;
pub mod star_burst_lib;
pub mod tester;
pub mod voronated_star_burst;
pub mod voronoi;
pub mod voronoi_simple;
pub mod voronated_star_burst;
52 changes: 32 additions & 20 deletions output/src/work/star_burst_lib/grid_comp.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rand::{thread_rng, Rng};
use sanguine_lib::resources::composition::{Composition, CompositionCenter, Density, Direction};
use sanguine_lib::resources::layout::grid::{Field, Grid};
use sanguine_lib::resources::layout::Layout;
use sanguine_lib::resources::composition::{Density, Composition, CompositionCenter, Direction};
use rand::{thread_rng, Rng};

/// This module only prescribes compositional elements. How they are rendered depends highly on the
/// individual project. It's probably helpful to provide a code template for this.
Expand All @@ -22,12 +22,10 @@ impl Composition for MyGrid {
/// This is to start with a homogenous field of "nothing", depending
/// on how rendering of the variant is set.


/// Creates a new grid where all fields have the Density::Mid variant.
/// This is to start with a homogenous field of "something", depending
/// on how rendering of the variant is set.
fn filled(&mut self, density_var: &Density) {

for row in 0..self.0.get_rows() {
for col in 0..self.0.get_columns() {
self.0.container[row][col].density = density_var.clone();
Expand All @@ -53,7 +51,7 @@ impl Composition for MyGrid {
}
}

// This finds the next center, connects it to the first, and repeats for the second
// This finds the next center, connects it to the first, and repeats for the second
// center etc.
for row in 0..self.0.get_rows() {
for col in 0..self.0.get_columns() {
Expand All @@ -78,7 +76,7 @@ impl Composition for MyGrid {
}
}

/// Adds a specified number of random centers with Density::Focus and surrounds
/// Adds a specified number of random centers with Density::Focus and surrounds
/// them Density::High.
fn add_random_center(&mut self, amount: usize) {
let mut rng = thread_rng();
Expand Down Expand Up @@ -262,31 +260,41 @@ impl Composition for MyGrid {
Density::Empty => {
let contact = self.direction_of_contact(row, col);
match to_array(contact) {
[true, true, true, true] => self.0.container[row][col].density = Density::Low,
[true, true, true, true] => {
self.0.container[row][col].density = Density::Low
}

[true, true, true, false] => {
self.0.container[row][col].density = Density::ThreeWay(Direction::Right)
self.0.container[row][col].density =
Density::ThreeWay(Direction::Right)
}
[true, false, true, true] => {
self.0.container[row][col].density = Density::ThreeWay(Direction::Left)
self.0.container[row][col].density =
Density::ThreeWay(Direction::Left)
}
[true, true, false, true] => {
self.0.container[row][col].density = Density::ThreeWay(Direction::Down)
self.0.container[row][col].density =
Density::ThreeWay(Direction::Down)
}
[false, true, true, true] => {
self.0.container[row][col].density = Density::ThreeWay(Direction::Up)
self.0.container[row][col].density =
Density::ThreeWay(Direction::Up)
}
[true, true, false, false] => {
self.0.container[row][col].density = Density::Corner(Direction::LeftUp)
self.0.container[row][col].density =
Density::Corner(Direction::LeftUp)
}
[false, true, true, false] => {
self.0.container[row][col].density = Density::Corner(Direction::LeftDown)
self.0.container[row][col].density =
Density::Corner(Direction::LeftDown)
}
[false, false, true, true] => {
self.0.container[row][col].density = Density::Corner(Direction::RightDown)
self.0.container[row][col].density =
Density::Corner(Direction::RightDown)
}
[true, false, false, true] => {
self.0.container[row][col].density = Density::Corner(Direction::RightUp)
self.0.container[row][col].density =
Density::Corner(Direction::RightUp)
}
[false, false, false, true] => {
self.0.container[row][col].density = Density::Edge(Direction::Left)
Expand All @@ -301,12 +309,16 @@ impl Composition for MyGrid {
self.0.container[row][col].density = Density::Edge(Direction::Right)
}
[false, true, false, true] => {
self.0.container[row][col].density = Density::Transition(Direction::LeftRight)
self.0.container[row][col].density =
Density::Transition(Direction::LeftRight)
}
[true, false, true, false] => {
self.0.container[row][col].density = Density::Transition(Direction::UpDown)
self.0.container[row][col].density =
Density::Transition(Direction::UpDown)
}
[false, false, false, false] => {
self.0.container[row][col].density = Density::Empty
}
[false, false, false, false] => self.0.container[row][col].density = Density::Empty,
_ => (),
}
}
Expand All @@ -322,7 +334,7 @@ impl Composition for MyGrid {
fn direction_of_contact(&mut self, row: usize, col: usize) -> Vec<bool> {
// Direction of the Edge variant points towards the block
// edge on the right or left side of a block
let mut sides = [false;4];
let mut sides = [false; 4];

if row != 0 {
match &self.0.container[row - 1][col].density {
Expand Down Expand Up @@ -420,4 +432,4 @@ use std::convert::TryInto;
fn to_array<T, const N: usize>(v: Vec<T>) -> [T; N] {
v.try_into()
.unwrap_or_else(|v: Vec<T>| panic!("Expected a Vec of length {} but it was {}", N, v.len()))
}
}
2 changes: 1 addition & 1 deletion output/src/work/star_burst_lib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod draw;
pub mod grid_comp;
pub mod lines;
pub mod threeways;
pub mod grid_comp;
pub mod voronoi_comp;
28 changes: 14 additions & 14 deletions output/src/work/star_burst_lib/voronoi_comp.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@


use rand::prelude::*;

use sanguine_lib::resources::{
composition::CompositionCenter,
layout::voronoi::VoronoiDiagram,
shapes::{line::Line, point::Point},
};

use sanguine_lib::resources::{layout::voronoi::VoronoiDiagram, shapes::{point::Point, line::Line}, composition::CompositionCenter};

use sanguine_lib::resources::composition::{Density, Composition, Direction::Lines};
use sanguine_lib::resources::composition::{Composition, Density, Direction::Lines};

#[derive(Debug, Clone)]
pub struct MyVoronoiDiagram(pub VoronoiDiagram);
impl Composition for MyVoronoiDiagram {
fn filled(&mut self, density_var: &Density) {

for item in 0..self.0.cells.len() {
self.0.cells[item].set_density(density_var.clone());
}
}
}

fn add_random_center(&mut self, amount: usize) {
let mut rng = thread_rng();

for _i in 0..amount {
let cell_index = rng.gen_range(0..self.0.cells.len());
// high density around the focus can't be set yet, because

// high density around the focus can't be set yet, because
// there's no way yet to find the neighbors

// for row in vertical - 1..=vertical + 1 {
Expand All @@ -43,7 +43,7 @@ impl Composition for MyVoronoiDiagram {
for _i in 0..amount {
let cell_index = rng.gen_range(0..self.0.cells.len());

self.0.cells[cell_index].density = Density::Low;
self.0.cells[cell_index].density = Density::Low;
}
}

Expand Down Expand Up @@ -71,11 +71,11 @@ impl Composition for MyVoronoiDiagram {
4 => cell.set_density(Density::Edge(Lines(contactless))),
5 => cell.set_density(Density::Edge(Lines(contactless))),
6 => cell.density = Density::Empty,
_ => {},
_ => {}
}
}
_ => {}
}
}
}
}

Expand All @@ -88,8 +88,8 @@ fn direction_of_contact(neighbors: Vec<(Point, Density, Line)>) -> Vec<Line> {
let mut touch_line = Vec::new();
for neighbor in neighbors {
match neighbor.1 {
Density::Empty => touch_line.push(neighbor.2),
_ =>{},
Density::Empty => touch_line.push(neighbor.2),
_ => {}
}
}
touch_line
Expand Down
54 changes: 26 additions & 28 deletions output/src/work/voronated_star_burst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use svg::{node::element::Group, Node};
use sanguine_lib::resources::{
border_coordinates::{all::AllBorderCoordinates, cell_border},
composition::{Composition, CompositionCenter, Density},
layout::{voronoi::VoronoiDiagram, Layout}, shapes::circle::Circle,
layout::{voronoi::VoronoiDiagram, Layout},
shapes::circle::Circle,
};

use super::star_burst_lib::{self, lines};
Expand Down Expand Up @@ -50,41 +51,38 @@ pub fn form_group(work: &mut VoronoiDiagram) -> Group {
}
println!("drawing starts");
// Drawing of the Elements
// println!("len cells {}", work.cells.len());
for cell in 0..work.cells.len() {

// println!("cell center {:?}", work.cells[cell].center);
// println!("len cells {}", work.cells.len());
for cell in 0..work.cells.len() {
// println!("cell center {:?}", work.cells[cell].center);

let mut radius = 0;
let mut radius = 0;

match work.cells[cell].density {
Density::Mid => radius = rng.gen_range(RADIUS_MID),
Density::High => radius = rng.gen_range(RADIUS_HIGH),
Density::Focus => radius = rng.gen_range(RADIUS_FOCUS),
Density::Edge(_) => radius = rng.gen_range(RADIUS_MID),
Density::ThreeWay(_) => radius = rng.gen_range(RADIUS_MID),
_ => ()
}

match work.cells[cell].density {
Density::Mid => radius = rng.gen_range(RADIUS_MID),
Density::High => radius = rng.gen_range(RADIUS_HIGH),
Density::Focus => radius = rng.gen_range(RADIUS_FOCUS),
Density::Edge(_) => radius = rng.gen_range(RADIUS_MID),
Density::ThreeWay(_) => radius = rng.gen_range(RADIUS_MID),
_ => (),
}

match work.cells[cell].density {
Density::Mid|Density::High => {
let circle = Circle::new(work.cells[cell].center, radius as f32);
graph.append(circle.draw());
match work.cells[cell].density {
Density::Mid | Density::High => {
let circle = Circle::new(work.cells[cell].center, radius as f32);
graph.append(circle.draw());

for side in &all_coords.0[0][cell].0 {
for side in &all_coords.0[0][cell].0 {
lines::to_circle(&mut graph, &side, &circle, 0, side.0.len());
}
}
_ => ()
}

_ => (),
}
for cell in work.get_points() {
for line in &cell.border_lines {
graph.append(line.draw());
}
}
for cell in work.get_points() {
for line in &cell.border_lines {
graph.append(line.draw());
}

}

graph
}
14 changes: 8 additions & 6 deletions sanguine_lib/src/resources/border_coordinates/all.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::resources::{layout::{Layout,grid::Grid, voronoi::VoronoiDiagram}, shapes::line};
use crate::resources::{
layout::{grid::Grid, voronoi::VoronoiDiagram, Layout},
shapes::line,
};

use super::{cell_border::CellBorderCoords, one_side::OneSide};

Expand Down Expand Up @@ -30,10 +33,9 @@ impl AllBorderCoordinates {

pub fn new_from_voronoi(work: &VoronoiDiagram, amount: usize) -> Self {
let mut vec = Vec::new();


for cell in &work.cells {
let mut cell_v= CellBorderCoords::new_empty();
let mut cell_v = CellBorderCoords::new_empty();
cell_v.0.clear();
for line in &cell.border_lines {
cell_v.0.push(OneSide::new_random(*line, amount));
Expand Down Expand Up @@ -81,15 +83,15 @@ impl AllBorderCoordinates {

for other_cell_item in 0..work.cells.len() {
for other_line_item in 0..work.cells[other_cell_item].border_lines.len() {
let line =work.cells[cell_item].border_lines[line_item];
let other_line =work.cells[other_cell_item].border_lines[other_line_item];
let line = work.cells[cell_item].border_lines[line_item];
let other_line = work.cells[other_cell_item].border_lines[other_line_item];
if line.equal(other_line) {
self.0[0][other_cell_item].0[other_line_item] = points.clone();
}
}
}
}
};
}
}

pub fn slight_chaos(&mut self) {
Expand Down
8 changes: 2 additions & 6 deletions sanguine_lib/src/resources/border_coordinates/cell_border.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use crate::resources::{
layout::grid::Field,
shapes::point::Point};
use crate::resources::{layout::grid::Field, shapes::point::Point};
use rand::{thread_rng, Rng};

use super::one_side::OneSide;
Expand All @@ -9,14 +7,13 @@ use super::one_side::OneSide;
///
/// It's currently limited to fields with 4 sides.


#[derive(Clone, Debug, PartialEq)]
pub struct CellBorderCoords(pub Vec<OneSide>);

impl CellBorderCoords {
/// Returns a vec of 4 vecs with a given number of random points, so you have random points
/// around the edge of a field.
///
///
pub fn new(field: Field, amount: usize) -> Self {
let mut sides = Vec::new();

Expand Down Expand Up @@ -69,7 +66,6 @@ impl CellBorderCoords {
let coordinates = OneSide::new();
sides.push(coordinates);
CellBorderCoords(sides)

}
}

Expand Down
3 changes: 1 addition & 2 deletions sanguine_lib/src/resources/border_coordinates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
///
/// It's currently limited to fields with 4 sides.
pub mod all;
pub mod one_side;
pub mod cell_border;

pub mod one_side;
Loading

0 comments on commit 6276fbe

Please sign in to comment.