This commit is contained in:
parent
596b2a509f
commit
9fe0337c9d
@ -15,7 +15,6 @@ impl VectorStorage {
|
|||||||
impl<P: GriddedPosition> Storage<P> for VectorStorage {
|
impl<P: GriddedPosition> Storage<P> for VectorStorage {
|
||||||
fn is_occupied(&self, position: &P) -> bool {
|
fn is_occupied(&self, position: &P) -> bool {
|
||||||
let i = position.linear_index(self.grid_size);
|
let i = position.linear_index(self.grid_size);
|
||||||
println!("{i}");
|
|
||||||
return self.backing[i];
|
return self.backing[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ use num_traits::Signed;
|
|||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use svg::Node;
|
use svg::Node;
|
||||||
use svg::node::element::{Circle, Rectangle};
|
use svg::node::element::{Circle, Polygon, Rectangle};
|
||||||
use crate::{RenderCli, Space};
|
use crate::{RenderCli, Space};
|
||||||
use crate::system::{GriddedPosition, Position};
|
use crate::system::{GriddedPosition, Position};
|
||||||
use crate::system::spaces::continuous_2d::P2;
|
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]
|
[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| [
|
let b = points.map(|x| [
|
||||||
(x[0] / 512.0),
|
(x[0] / a),
|
||||||
(x[1] / 512.0)]
|
(x[1] / a)]
|
||||||
);
|
);
|
||||||
|
|
||||||
let c = b.map(|p| format!("{},{}", p[0], p[1])).join(" ");
|
let c = b.map(|p| format!("{},{}", p[0], p[1])).join(" ");
|
||||||
|
|
||||||
let cartesian = self.to_cartesian();
|
let cartesian = self.to_cartesian();
|
||||||
Box::new(Rectangle::new()
|
Box::new(Polygon::new()
|
||||||
.set("fill", format!("rgb({}, {}, {})", colour.r, colour.g, colour.b))
|
.set("fill", format!("rgb({}, {}, {})", colour.r, colour.g, colour.b))
|
||||||
.set("x", cartesian[0])
|
.set("points", c)
|
||||||
.set("y", cartesian[1]))
|
.set("transform", format!("translate({}, {})", cartesian[0], cartesian[1])))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compute_max_size<P: GriddedPosition>(positions: &[P]) -> f32 {
|
pub fn compute_max_size<P: Position>(positions: &[P]) -> f32 {
|
||||||
let mut positions = positions.iter().map(P::to_cartesian);
|
let mut positions = positions.iter().map(P::to_cartesian);
|
||||||
let mut maximums: Vec<f32> = positions.next().unwrap();
|
let mut maximums: Vec<f32> = positions.next().unwrap();
|
||||||
|
|
||||||
@ -90,8 +92,8 @@ pub fn compute_max_size<P: GriddedPosition>(positions: &[P]) -> f32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render<P: Position>(args: &RenderCli) where P: DeserializeOwned + ToSvg {
|
fn render<P: Position>(args: &RenderCli) where P: DeserializeOwned + ToSvg {
|
||||||
let positions = read::<Grid2D>(&args.path, args.format);
|
let positions = read::<P>(&args.path, args.format);
|
||||||
let max_size = compute_max_size(&positions);
|
let max_size = compute_max_size(&positions) + 10.0;
|
||||||
|
|
||||||
let mut svg = svg::Document::new()
|
let mut svg = svg::Document::new()
|
||||||
.set("width", max_size)
|
.set("width", max_size)
|
||||||
@ -118,5 +120,6 @@ pub(crate) fn main(args: &RenderCli) {
|
|||||||
match args.space {
|
match args.space {
|
||||||
Space::Grid2D => render::<Grid2D>(args),
|
Space::Grid2D => render::<Grid2D>(args),
|
||||||
Space::Continuous2D => render::<P2>(args),
|
Space::Continuous2D => render::<P2>(args),
|
||||||
|
Space::Hex => render::<HexPosition>(args),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,8 @@ enum ToolsCli {
|
|||||||
#[derive(clap::ValueEnum, Clone, Debug, Copy)]
|
#[derive(clap::ValueEnum, Clone, Debug, Copy)]
|
||||||
enum Space {
|
enum Space {
|
||||||
Grid2D,
|
Grid2D,
|
||||||
Continuous2D
|
Continuous2D,
|
||||||
|
Hex,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Args)]
|
#[derive(Debug, Args)]
|
||||||
@ -75,8 +76,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
match args {
|
match args {
|
||||||
ToolsCli::Render(cli) => tools::render::main(&cli),
|
ToolsCli::Render(cli) => tools::render::main(&cli),
|
||||||
ToolsCli::BoxCount(cli) => tools::boxcount::main(&cli),
|
ToolsCli::BoxCount(cli) => tools::boxcount::main(&cli),
|
||||||
ToolsCli::DataAnalysis(cli) => {
|
ToolsCli::DataAnalysis(cli) => tools::analysis::main(&cli),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user