From 9fe0337c9d35d4b15a27f038ac8e0d7246b944bf Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sat, 18 Mar 2023 19:52:33 +0000 Subject: [PATCH] Hex work! --- src/system/spaces/vector_storage.rs | 1 - src/tools/render.rs | 21 ++++++++++++--------- src/tools_cli.rs | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/system/spaces/vector_storage.rs b/src/system/spaces/vector_storage.rs index 4818ec8..50bbc47 100644 --- a/src/system/spaces/vector_storage.rs +++ b/src/system/spaces/vector_storage.rs @@ -15,7 +15,6 @@ impl VectorStorage { impl Storage

for VectorStorage { fn is_occupied(&self, position: &P) -> bool { let i = position.linear_index(self.grid_size); - println!("{i}"); return self.backing[i]; } diff --git a/src/tools/render.rs b/src/tools/render.rs index 085194f..4d8171e 100644 --- a/src/tools/render.rs +++ b/src/tools/render.rs @@ -15,7 +15,7 @@ use num_traits::Signed; use serde::de::DeserializeOwned; use serde::Deserialize; use svg::Node; -use svg::node::element::{Circle, Rectangle}; +use svg::node::element::{Circle, Polygon, Rectangle}; use crate::{RenderCli, Space}; use crate::system::{GriddedPosition, Position}; use crate::system::spaces::continuous_2d::P2; @@ -60,22 +60,24 @@ impl ToSvg for HexPosition { [25.045, 128.0], [256.0, 0.0], [486.955, 128.0], [486.955, 384.0], [256.0, 512.0], [25.045, 384.0] ]; + let a = 256.0; + // let a = 400.0; let b = points.map(|x| [ - (x[0] / 512.0), - (x[1] / 512.0)] + (x[0] / a), + (x[1] / a)] ); let c = b.map(|p| format!("{},{}", p[0], p[1])).join(" "); let cartesian = self.to_cartesian(); - Box::new(Rectangle::new() + Box::new(Polygon::new() .set("fill", format!("rgb({}, {}, {})", colour.r, colour.g, colour.b)) - .set("x", cartesian[0]) - .set("y", cartesian[1])) + .set("points", c) + .set("transform", format!("translate({}, {})", cartesian[0], cartesian[1]))) } } -pub fn compute_max_size(positions: &[P]) -> f32 { +pub fn compute_max_size(positions: &[P]) -> f32 { let mut positions = positions.iter().map(P::to_cartesian); let mut maximums: Vec = positions.next().unwrap(); @@ -90,8 +92,8 @@ pub fn compute_max_size(positions: &[P]) -> f32 { } fn render(args: &RenderCli) where P: DeserializeOwned + ToSvg { - let positions = read::(&args.path, args.format); - let max_size = compute_max_size(&positions); + let positions = read::

(&args.path, args.format); + let max_size = compute_max_size(&positions) + 10.0; let mut svg = svg::Document::new() .set("width", max_size) @@ -118,5 +120,6 @@ pub(crate) fn main(args: &RenderCli) { match args.space { Space::Grid2D => render::(args), Space::Continuous2D => render::(args), + Space::Hex => render::(args), } } diff --git a/src/tools_cli.rs b/src/tools_cli.rs index 9d4c17e..5d90ba0 100644 --- a/src/tools_cli.rs +++ b/src/tools_cli.rs @@ -34,7 +34,8 @@ enum ToolsCli { #[derive(clap::ValueEnum, Clone, Debug, Copy)] enum Space { Grid2D, - Continuous2D + Continuous2D, + Hex, } #[derive(Debug, Args)] @@ -75,8 +76,7 @@ fn main() -> anyhow::Result<()> { match args { ToolsCli::Render(cli) => tools::render::main(&cli), ToolsCli::BoxCount(cli) => tools::boxcount::main(&cli), - ToolsCli::DataAnalysis(cli) => { - } + ToolsCli::DataAnalysis(cli) => tools::analysis::main(&cli), } Ok(())