rust/landgen/src/wavefront_collapse/tile_image.rs
author unC0Rr
Sun, 12 Feb 2023 14:19:02 +0100
branchtransitional_engine
changeset 15948 9bd828451d77
parent 15947 60b5639cc3a5
child 15949 659c92124c26
permissions -rw-r--r--
Fix several issues with transformations, more work on getting generated image
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
     1
use super::transform::Transform;
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
     2
use integral_geometry::Size;
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
     3
use std::rc::Rc;
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
     4
use vec2d::Vec2D;
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
     5
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
     6
#[derive(PartialEq, Clone, Debug)]
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
     7
pub struct Edge<I: PartialEq + Clone> {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
     8
    id: I,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
     9
    symmetrical: bool,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    10
    reverse: bool,
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    11
}
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    12
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    13
impl<I: PartialEq + Clone> Edge<I> {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    14
    pub fn new(id: I, symmetrical: bool) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    15
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    16
            id,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    17
            symmetrical,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    18
            reverse: false,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    19
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    20
    }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    21
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    22
    pub fn reversed(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    23
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    24
            id: self.id.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    25
            symmetrical: self.symmetrical,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    26
            reverse: !self.symmetrical && !self.reverse,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    27
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    28
    }
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    29
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    30
    pub fn is_compatible(&self, other: &Self) -> bool {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    31
        self.id == other.id && (self.reverse != other.reverse || self.symmetrical)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    32
    }
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    33
}
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    34
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    35
#[derive(Clone)]
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    36
pub struct TileImage<T, I: PartialEq + Clone> {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    37
    image: Rc<Vec2D<T>>,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    38
    transform: Transform,
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    39
    top: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    40
    right: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    41
    bottom: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    42
    left: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    43
}
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    44
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    45
impl<T: Copy, I: PartialEq + Clone> TileImage<T, I> {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    46
    pub fn new(
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    47
        image: Vec2D<T>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    48
        top: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    49
        right: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    50
        bottom: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    51
        left: Edge<I>,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    52
    ) -> Self {
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    53
        Self {
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    54
            image: Rc::new(image),
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    55
            transform: Transform::default(),
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    56
            top,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    57
            right,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    58
            bottom,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    59
            left,
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    60
        }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    61
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    62
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    63
    pub fn mirrored(&self) -> Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    64
        Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    65
            image: self.image.clone(),
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    66
            transform: self.transform.mirror(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    67
            top: self.top.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    68
            right: self.left.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    69
            bottom: self.bottom.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    70
            left: self.right.reversed(),
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    71
        }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    72
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    73
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    74
    pub fn flipped(&self) -> Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    75
        Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    76
            image: self.image.clone(),
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    77
            transform: self.transform.flip(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    78
            top: self.bottom.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    79
            right: self.right.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    80
            bottom: self.top.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    81
            left: self.left.reversed(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    82
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    83
    }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    84
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    85
    pub fn rotated90(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    86
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    87
            image: self.image.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    88
            transform: self.transform.rotate90(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    89
            top: self.left.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    90
            right: self.top.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    91
            bottom: self.right.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    92
            left: self.bottom.clone(),
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    93
        }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    94
    }
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
    95
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    96
    pub fn rotated180(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    97
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    98
            image: self.image.clone(),
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    99
            transform: self.transform.rotate180(),
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   100
            top: self.bottom.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   101
            right: self.left.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   102
            bottom: self.top.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   103
            left: self.right.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   104
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   105
    }
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   106
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   107
    pub fn rotated270(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   108
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   109
            image: self.image.clone(),
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   110
            transform: self.transform.rotate270(),
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   111
            top: self.left.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   112
            right: self.top.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   113
            bottom: self.right.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   114
            left: self.bottom.clone(),
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   115
        }
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   116
    }
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   117
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   118
    pub fn right_edge(&self) -> &Edge<I> {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   119
        &self.right
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   120
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   121
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   122
    pub fn bottom_edge(&self) -> &Edge<I> {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   123
        &self.bottom
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   124
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   125
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   126
    pub fn left_edge(&self) -> &Edge<I> {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   127
        &self.left
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   128
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   129
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   130
    pub fn top_edge(&self) -> &Edge<I> {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   131
        &self.top
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   132
    }
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   133
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   134
    pub fn size(&self) -> Size {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   135
        match self.transform {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   136
            Transform::Rotate0(_) => self.image.size(),
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   137
            Transform::Rotate90(_) => Size::new(self.image.size().height, self.image.size().width),
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   138
        }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   139
    }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   140
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   141
    pub fn get(&self, row: usize, column: usize) -> Option<&T> {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   142
        match self.transform {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   143
            Transform::Rotate0(_) => {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   144
                let image_row = if self.transform.is_flipped() {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   145
                    self.image.height().wrapping_sub(1).wrapping_sub(row)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   146
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   147
                    row
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   148
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   149
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   150
                let image_column = if self.transform.is_mirrored() {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   151
                    self.image.width().wrapping_sub(1).wrapping_sub(column)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   152
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   153
                    column
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   154
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   155
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   156
                self.image.get(image_row, image_column)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   157
            },
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   158
            Transform::Rotate90(_) => {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   159
                let image_row = if self.transform.is_flipped() {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   160
                    column
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   161
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   162
                    self.image.height().wrapping_sub(1).wrapping_sub(column)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   163
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   164
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   165
                let image_column = if self.transform.is_mirrored() {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   166
                    self.image.width().wrapping_sub(1).wrapping_sub(row)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   167
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   168
                    row
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   169
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   170
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   171
                self.image.get(image_row, image_column)
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   172
            },
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   173
        }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   174
    }
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   175
}
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   176
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   177
#[cfg(test)]
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   178
mod tests {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   179
    use super::*;
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   180
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   181
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   182
    fn test_edge_new() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   183
        let edge = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   184
        assert_eq!(edge.id, 1);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   185
        assert_eq!(edge.symmetrical, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   186
        assert_eq!(edge.reverse, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   187
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   188
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   189
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   190
    fn test_edge_reversed() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   191
        let edge = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   192
        let reversed = edge.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   193
        assert_eq!(reversed.id, edge.id);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   194
        assert_eq!(reversed.symmetrical, edge.symmetrical);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   195
        assert_eq!(reversed.reverse, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   196
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   197
        let edge = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   198
        let reversed = edge.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   199
        assert_eq!(reversed.id, edge.id);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   200
        assert_eq!(reversed.symmetrical, edge.symmetrical);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   201
        assert_eq!(reversed.reverse, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   202
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   203
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   204
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   205
    fn test_edge_equality() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   206
        let edge1 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   207
        let edge2 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   208
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   209
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   210
        let edge1 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   211
        let edge2 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   212
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   213
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   214
        let edge1 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   215
        let edge2 = Edge::new(2, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   216
        assert_ne!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   217
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   218
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   219
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   220
    fn test_edge_equality_with_reverse() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   221
        let edge1 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   222
        let edge2 = edge1.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   223
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   224
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   225
        let edge1 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   226
        let edge2 = edge1.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   227
        assert_ne!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   228
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   229
        let edge1 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   230
        let edge2 = edge1.reversed().reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   231
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   232
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   233
}