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