Module genotype::param_set[][src]

Helper structs to easily represent collections of related parameters.

Examples

// represents a length in space in a single dimension
struct Length(Param);

struct Cuboid(ParamSet3d<Length>);

impl RangedParam for Length {
  fn range(&self) -> (Param, Param) {
      (0.0, 10.0)
  }

  // ...
}

// delegates to ParamSet
impl ParamHolder for Cuboid {
  fn param_count(&self) -> usize {
      self.0.param_count()
  }

  fn get_param(&mut self, index: usize) -> &mut RangedParam {
      match index {
          0...2 => self.0.get_param(index),
          _ => panic!("Bad index"),
      }
  }
}

let cuboid = Cuboid(ParamSet3d::new(
  Length(0.25), Length(0.5), Length(0.75))
);

let (x, y, z) = cuboid.0.components_scaled();
assert!((x - 2.5).abs() < 0.00001);
assert!((y - 5.0).abs() < 0.00001);
assert!((z - 7.5).abs() < 0.00001);

Structs

ParamSet2d

A 2D parameter set containing x and y.

ParamSet3d

A 3D parameter set containing x, y and z fields.

Traits

ParamSet

Represents a collection of related parameters.