--- a/rust/landgen/Cargo.toml Sun Oct 28 23:09:35 2018 +0100
+++ b/rust/landgen/Cargo.toml Sun Oct 28 23:24:04 2018 +0100
@@ -5,3 +5,4 @@
[dependencies]
integral-geometry = { path = "../integral-geometry" }
+land2d = { path = "../land2d" }
--- a/rust/landgen/src/lib.rs Sun Oct 28 23:09:35 2018 +0100
+++ b/rust/landgen/src/lib.rs Sun Oct 28 23:24:04 2018 +0100
@@ -1,6 +1,20 @@
-mod outline;
+mod template_based;
extern crate integral_geometry;
+extern crate land2d;
+
+struct LandGenerationParameters<T> {
+ zero: T,
+ basic: T,
+}
+
+trait LandGenerator {
+ fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>(
+ &self,
+ parameters: LandGenerationParameters<T>,
+ random_numbers: &mut I,
+ ) -> land2d::Land2D<T>;
+}
#[cfg(test)]
mod tests {
--- a/rust/landgen/src/outline.rs Sun Oct 28 23:09:35 2018 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-use integral_geometry::Point;
-
-pub struct Outline {
- points: Vec<Point>,
-}
-
-fn check_intersect(
- segment1_start: &Point,
- segment1_end: &Point,
- segment2_start: &Point,
- segment2_end: &Point,
-) -> bool {
- let dm: i32 = (segment2_end.y - segment2_start.y) * (segment1_end.x - segment1_start.x)
- - (segment2_end.x - segment2_start.x) * (segment1_end.y - segment1_start.y);
-
- if dm == 0 {
- return false;
- }
-
- let c1: i32 = (segment2_end.x - segment2_start.x) * (segment1_start.y - segment2_start.y)
- - (segment2_end.y - segment2_start.y) * (segment1_start.x - segment2_start.x);
-
- if dm > 0 {
- if (c1 < 0) || (c1 > dm) {
- return false;
- }
- } else {
- if (c1 > 0) || (c1 < dm) {
- return false;
- }
- }
-
- let c2: i32 = (segment1_end.x - segment2_start.x) * (segment1_start.y - segment2_start.y)
- - (segment1_end.y - segment2_start.y) * (segment1_start.x - segment2_start.x);
-
- if dm > 0 {
- if (c2 < 0) || (c2 > dm) {
- return false;
- }
- } else {
- if (c2 > 0) || (c2 < dm) {
- return false;
- }
- }
-
- true
-}
-
-impl Outline {
- fn check_intersects_self_at_index(&self, index: usize) -> bool {
- if index <= 0 || index > self.points.len() {
- return false;
- }
-
- for i in 1..=self.points.len() - 3 {
- if i <= index - 1 || i >= index + 2 {
- if i != index - 1 && check_intersect(
- &self.points[index],
- &self.points[index - 1],
- &self.points[i],
- &self.points[i - 1],
- ) {
- return true;
- }
- if i != index + 2 && check_intersect(
- &self.points[index],
- &self.points[index + 1],
- &self.points[i],
- &self.points[i - 1],
- ) {
- return true;
- }
- }
- }
-
- false
- }
-}
-
-#[cfg(test)]
-#[test]
-fn intersection() {
- let p1 = Point { x: 0, y: 0 };
- let p2 = Point { x: 0, y: 10 };
- let p3 = Point { x: -5, y: 5 };
- let p4 = Point { x: 5, y: 5 };
- let p5 = Point { x: 5, y: 16 };
-
- assert!(check_intersect(&p1, &p2, &p3, &p4));
- assert!(!check_intersect(&p1, &p2, &p3, &p5));
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rust/landgen/src/template_based.rs Sun Oct 28 23:24:04 2018 +0100
@@ -0,0 +1,55 @@
+use integral_geometry::Point;
+use land2d::Land2D;
+use LandGenerationParameters;
+use LandGenerator;
+
+struct OutlineTemplate {
+ islands: Vec<Vec<Point>>,
+ fill_points: Vec<Point>,
+ width: usize,
+ height: usize,
+ can_flip: bool,
+ can_invert: bool,
+ can_mirror: bool,
+ is_negative: bool,
+}
+
+struct TemplatedLandGenerator {
+ outline_template: OutlineTemplate,
+}
+
+impl OutlineTemplate {}
+
+impl TemplatedLandGenerator {
+ fn new(outline_template: OutlineTemplate) -> Self {
+ Self { outline_template }
+ }
+}
+
+impl LandGenerator for TemplatedLandGenerator {
+ fn generate_land<T: Copy + PartialEq, I: Iterator<Item = u32>>(
+ &self,
+ parameters: LandGenerationParameters<T>,
+ random_numbers: &mut I,
+ ) -> Land2D<T> {
+ let mut pa = Vec::new();
+
+ for island in &self.outline_template.islands {
+ let mut island_points = Vec::new();
+
+ for p in island {
+ island_points.push(p);
+ }
+
+ pa.push(island_points);
+ }
+
+ let mut land = Land2D::new(
+ self.outline_template.width,
+ self.outline_template.height,
+ parameters.basic,
+ );
+
+ land
+ }
+}