main
Elnu 1 year ago
parent 3960d6e721
commit 37da862c9f

@ -24,14 +24,21 @@ enum 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 row_count = ((dimensions.width - padding * 2.0) / grid) as u32;
(0..count)
.map(|i| (
grid * (i % row_count).into() + padding,
grid * (i / row_count).into() + padding,
))
.map(|i| {
(
grid * (i % row_count).into() + padding,
grid * (i / row_count).into() + padding,
)
})
.collect()
}

@ -1,15 +1,15 @@
use super::SVGUnit;
use derive_more::From;
use lazy_static::lazy_static;
use regex::Regex;
use std::cmp::Ordering;
use std::fmt;
use std::num::ParseFloatError;
use std::str::FromStr;
use std::{
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;
#[derive(Debug, Clone, Copy)]

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

Loading…
Cancel
Save