This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

✨ Angle::random, Region.split and a few more new features

+91 -7
+1 -1
examples/dna-analysis-machine/src/main.rs
··· 61 61 } 62 62 .filled(Fill::Hatches( 63 63 Color::White, 64 - Angle(45.0), 64 + Angle::from_degrees(45.0), 65 65 (i + 5) as f32 / 10.0, 66 66 0.25, 67 67 ))
+14 -1
src/geometry/angle.rs
··· 1 1 /// Angle, stored in degrees 2 2 #[derive(Debug, Clone, Copy, Default)] 3 - pub struct Angle(pub f32); 3 + pub struct Angle(pub(crate) f32); 4 4 5 5 impl Angle { 6 6 pub const TURN: Self = Angle(360.0); 7 7 8 + pub fn from_degrees(degrees: f32) -> Self { 9 + Self(degrees) 10 + } 11 + 12 + pub fn from_radians(radians: f32) -> Self { 13 + Self(radians * Self::TURN.0 / std::f32::consts::TAU) 14 + } 15 + 8 16 pub fn degrees(&self) -> f32 { 9 17 self.0 10 18 } ··· 20 28 21 29 pub fn without_turns(&self) -> Self { 22 30 Self(self.0 % Self::TURN.0) 31 + } 32 + 33 + pub fn cos_sin(&self) -> (f32, f32) { 34 + let rad = self.radians(); 35 + (rad.cos(), rad.sin()) 23 36 } 24 37 } 25 38
+4
src/geometry/axis.rs
··· 1 + pub enum Axis { 2 + Horizontal, 3 + Vertical, 4 + }
+2
src/geometry/mod.rs
··· 1 1 pub mod angle; 2 + pub mod axis; 2 3 pub mod point; 3 4 pub mod region; 4 5 5 6 pub use angle::Angle; 7 + pub use axis::Axis; 6 8 pub use point::Point; 7 9 pub use region::{Containable, Region};
+18
src/geometry/point.rs
··· 3 3 4 4 use crate::Region; 5 5 6 + use super::Angle; 7 + 6 8 #[cfg_attr(feature = "web", wasm_bindgen)] 7 9 #[derive(Debug, Clone, Copy, Default, PartialEq)] 8 10 pub struct Point(pub usize, pub usize); ··· 40 42 41 43 pub fn distances(&self, other: &Point) -> (usize, usize) { 42 44 (self.0.abs_diff(other.0) + 1, self.1.abs_diff(other.1) + 1) 45 + } 46 + 47 + pub fn rotated(&self, around: &Point, angle: Angle) -> Point { 48 + let (dx, dy) = ( 49 + self.0 as f32 - around.0 as f32, 50 + self.1 as f32 - around.1 as f32, 51 + ); 52 + 53 + let (cos, sin) = angle.cos_sin(); 54 + let new_x = dx * cos - dy * sin; 55 + let new_y = dx * sin + dy * cos; 56 + 57 + Point( 58 + (new_x + around.0 as f32) as usize, 59 + (new_y + around.1 as f32) as usize, 60 + ) 43 61 } 44 62 } 45 63
+27
src/geometry/region.rs
··· 4 4 #[cfg(feature = "web")] 5 5 use wasm_bindgen::prelude::*; 6 6 7 + use super::Axis; 8 + 7 9 #[cfg_attr(feature = "web", wasm_bindgen)] 8 10 #[derive(Debug, Clone, Default, Copy)] 9 11 pub struct Region { ··· 347 349 pub fn mirrored_height_range(&self) -> std::ops::RangeInclusive<i32> { 348 350 let h = self.height() as i32; 349 351 -h..=h 352 + } 353 + 354 + pub fn split(&self, along: Axis) -> (Region, Region) { 355 + match along { 356 + Axis::Horizontal => ( 357 + Region { 358 + start: self.start, 359 + end: Point(self.end.0, self.end.1 / 2), 360 + }, 361 + Region { 362 + start: Point(self.start.0, self.end.1 / 2), 363 + end: self.end, 364 + }, 365 + ), 366 + Axis::Vertical => ( 367 + Region { 368 + start: self.start, 369 + end: Point(self.end.0 / 2, self.end.1), 370 + }, 371 + Region { 372 + start: Point(self.end.0 / 2, self.start.1), 373 + end: self.end, 374 + }, 375 + ), 376 + } 350 377 } 351 378 } 352 379
+7
src/graphics/color.rs
··· 148 148 } 149 149 } 150 150 151 + #[cfg(not(feature = "web"))] 152 + impl Default for ColorMapping { 153 + fn default() -> Self { 154 + ColorMapping::default() 155 + } 156 + } 157 + 151 158 impl ColorMapping { 152 159 pub fn from_cli_args(args: &Vec<String>) -> ColorMapping { 153 160 let mut colormap: HashMap<String, String> = HashMap::new();
+2 -2
src/graphics/layer.rs
··· 12 12 } 13 13 14 14 impl Layer { 15 - pub fn new(name: &str) -> Self { 15 + pub fn new(name: impl Display) -> Self { 16 16 Layer { 17 17 object_sizes: ObjectSizes::default(), 18 18 objects: HashMap::new(), 19 - name: name.to_string(), 19 + name: format!("{}", name), 20 20 _render_cache: None, 21 21 hidden: false, 22 22 }
+1 -1
src/lib.rs
··· 29 29 #[cfg(feature = "vst")] 30 30 pub mod vst; 31 31 32 - pub use geometry::{Angle, Containable, Point, Region}; 32 + pub use geometry::{Angle, Axis, Containable, Point, Region}; 33 33 pub use graphics::{ 34 34 Canvas, Color, ColorMapping, ColoredObject, Fill, Filter, FilterType, Layer, 35 35 LineSegment, Object, ObjectSizes, Transformation,
+9
src/random/angle.rs
··· 1 + use crate::Angle; 2 + 3 + impl Angle { 4 + /// Generate a random angle in degrees 5 + pub fn random() -> Self { 6 + let angle = rand::random::<f32>() * 360.0; 7 + Self(angle) 8 + } 9 + }
+5 -1
src/random/canvas.rs
··· 8 8 } 9 9 10 10 pub fn random_object(&self) -> Object { 11 + self.random_object_within(&self.world_region) 12 + } 13 + 14 + pub fn random_object_within(&self, region: &Region) -> Object { 11 15 Object::random( 12 - &self.world_region, 16 + region, 13 17 self.object_sizes.default_line_width, 14 18 self.polygon_vertices_range.clone(), 15 19 )
-1
src/random/layer.rs
··· 1 -
+1
src/random/mod.rs
··· 1 + pub mod angle; 1 2 pub mod canvas; 2 3 pub mod color; 3 4 pub mod fill;