main
Elnu 1 year ago
parent 3960d6e721
commit 37da862c9f

@ -24,14 +24,21 @@ enum Error {
Template(askama::Error), Template(askama::Error),
} }
fn positions(size: SVGMeasure, padding: SVGMeasure, dimensions: &DocumentDimensions, count: u32) -> Vec<(SVGMeasure, SVGMeasure)> { fn positions(
size: SVGMeasure,
padding: SVGMeasure,
dimensions: &DocumentDimensions,
count: u32,
) -> Vec<(SVGMeasure, SVGMeasure)> {
let grid = size + padding; let grid = size + padding;
let row_count = ((dimensions.width - padding * 2.0) / grid) as u32; let row_count = ((dimensions.width - padding * 2.0) / grid) as u32;
(0..count) (0..count)
.map(|i| ( .map(|i| {
grid * (i % row_count).into() + padding, (
grid * (i / row_count).into() + padding, grid * (i % row_count).into() + padding,
)) grid * (i / row_count).into() + padding,
)
})
.collect() .collect()
} }

@ -1,15 +1,15 @@
use super::SVGUnit; use super::SVGUnit;
use derive_more::From;
use lazy_static::lazy_static;
use regex::Regex;
use std::cmp::Ordering; use std::cmp::Ordering;
use std::fmt; use std::fmt;
use std::num::ParseFloatError; use std::num::ParseFloatError;
use std::str::FromStr; use std::str::FromStr;
use std::{ use std::{
fmt::Display, fmt::Display,
ops::{Add, Div, Mul, Sub, Rem}, ops::{Add, Div, Mul, Rem, Sub},
}; };
use lazy_static::lazy_static;
use regex::Regex;
use derive_more::From;
use strum::ParseError; use strum::ParseError;
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]

@ -1,8 +1,7 @@
use strum_macros::{Display, EnumString, IntoStaticStr}; use strum_macros::{Display, EnumString, IntoStaticStr};
/// https://oreillymedia.github.io/Using_SVG/guide/units.html /// https://oreillymedia.github.io/Using_SVG/guide/units.html
#[derive(Clone, Copy, PartialEq, Eq, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Debug, Display, EnumString, IntoStaticStr)]
#[derive(Display, EnumString, IntoStaticStr)]
pub enum SVGUnit { pub enum SVGUnit {
/// Pixel units, directly equivalent to SVG user units. /// Pixel units, directly equivalent to SVG user units.
#[strum(serialize = "px")] #[strum(serialize = "px")]

Loading…
Cancel
Save