fern_sim: Updated.

pull/13/head
Jim Blandy 3 years ago
parent 002cb75b78
commit bdd175151c

@ -1,6 +1,7 @@
[package] [package]
name = "fern_sim" name = "fern_sim"
version = "0.1.0" version = "0.1.0"
edition = "2018"
authors = ["You <you@example.com>"] authors = ["You <you@example.com>"]
license = "MIT" license = "MIT"
homepage = "https://fernsim.example.com/" homepage = "https://fernsim.example.com/"

@ -1,12 +0,0 @@
//! The simulation of biological cells, which is as low-level as we go.
pub struct Cell {
x: f64,
y: f64
}
impl Cell {
pub fn distance_from_origin(&self) -> f64 {
f64::hypot(self.x, self.y)
}
}

@ -1,7 +1,9 @@
//! Simulate the growth of ferns, from the level of //! Simulate the growth of ferns, from the level of
//! individual cells on up. //! individual cells on up.
pub mod cells; #![warn(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
pub mod plant_structures; pub mod plant_structures;
pub mod simulation; pub mod simulation;
pub mod spores; pub mod spores;

@ -2,5 +2,5 @@
//! Simulation of individual leaves (for the formation of leaves, see `stem`). //! Simulation of individual leaves (for the formation of leaves, see `stem`).
pub struct Leaf { pub struct Leaf {
x: bool pub x: bool
} }

@ -43,3 +43,17 @@ impl Fern {
self.stems.iter().all(|s| !s.furled) self.stems.iter().all(|s| !s.furled)
} }
} }
/// Create and return a [`VascularPath`] which represents the path of
/// nutrients from the given [`Root`][r] to the given [`Leaf`](leaves::Leaf).
///
/// [r]: roots::Root
pub fn trace_path(leaf: &leaves::Leaf, root: &roots::Root) -> VascularPath {
VascularPath { from: leaf.x, to: root.x }
}
#[doc(alias = "route")]
pub struct VascularPath {
pub from: bool,
pub to: bool,
}

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
pub struct Root { pub struct Root {
x: bool pub x: bool
} }
pub type RootSet = Vec<Root>; pub type RootSet = Vec<Root>;

@ -3,6 +3,10 @@
//! the feathery leaf structure that's the most immediately recognizable //! the feathery leaf structure that's the most immediately recognizable
//! property of ferns. //! property of ferns.
// in plant_structures/stems.rs
pub mod xylem;
pub mod phloem;
pub struct Stem { pub struct Stem {
pub furled: bool pub furled: bool
} }

@ -0,0 +1,6 @@
//! Structures for distributing the products of photosynthesis.
/// Tissue for translocating sucrose and other photosynthesis products.
pub struct Phloem {
pub flow_rate: f32,
}

@ -0,0 +1,6 @@
//! Structures for bringing nutrients from roots up to other parts of the plant.
/// Vascular tissue for transporting water and nutrients from the roots.
pub struct Xylem {
pub flow_rate: f32,
}

@ -4,7 +4,7 @@
use std::fs::File; use std::fs::File;
use std::time::Duration; use std::time::Duration;
use plant_structures::{Fern, FernType}; use crate::plant_structures::{Fern, FernType};
/// The simulated universe. /// The simulated universe.
pub struct Terrarium { pub struct Terrarium {

@ -2,27 +2,46 @@
//! Fern reproduction. //! Fern reproduction.
use cells::Cell; use cells::{Cell, Gene};
/// A cell made by an adult fern. It disperses on the wind as part of /// A cell made by an adult fern. It disperses on the wind as part of
/// the fern life cycle. A spore grows into a prothallus -- a whole /// the fern life cycle. A spore grows into a prothallus -- a whole
/// separate organism, up to 5mm across -- which produces a zygote, /// separate organism, up to 5mm across -- which produces the zygote
/// which becomes a new fern. (Plant sex is complicated.) /// that grows into a new fern. (Plant sex is complicated.)
pub struct Spore { pub struct Spore {
x: bool size: f64
}
/// A compartment, usually on the bottom of a leaf, where spores form.
pub struct Sporangium {
x: bool
} }
/// Simulate the production of a spore by meiosis. /// Simulate the production of a spore by meiosis.
pub fn produce_spore(factory: &mut Sporangium) -> Spore { pub fn produce_spore(factory: &mut Sporangium) -> Spore {
Spore { x: false } Spore { size: 1.0 }
}
/// Extract the genes in a particular spore.
pub(crate) fn genes(spore: &Spore) -> Vec<Gene> {
todo!()
} }
/// Mix genes to prepare for meiosis (part of interphase). /// Mix genes to prepare for meiosis (part of interphase).
fn recombine(parent: &mut Cell) { fn recombine(parent: &mut Cell) {
todo!()
} }
pub struct Sporangium;
mod cells {
//! The simulation of biological cells, which is as low-level as we go.
pub struct Cell {
x: f64,
y: f64
}
impl Cell {
pub fn distance_from_origin(&self) -> f64 {
f64::hypot(self.x, self.y)
}
}
pub struct Gene;
}

@ -1,6 +1,8 @@
// tests/unfurl.rs - Fiddleheads unfurl in sunlight // tests/unfurl.rs - Fiddleheads unfurl in sunlight
extern crate fern_sim; #![warn(rust_2018_idioms)]
#![allow(elided_lifetimes_in_paths)]
use fern_sim::Terrarium; use fern_sim::Terrarium;
use std::time::Duration; use std::time::Duration;

Loading…
Cancel
Save