rust/landgen/src/wavefront_collapse/tile_image.rs
author unC0Rr
Sun, 02 Feb 2025 22:30:49 +0100
changeset 16109 2fc37552b587
parent 16108 65c017453e83
permissions -rw-r--r--
Introduce hard match option for edges to reduce backtracking
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,
16109
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    11
    hard_match: bool,
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    12
}
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
    13
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    14
impl<I: PartialEq + Clone> Edge<I> {
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15951
diff changeset
    15
    #[inline]
16109
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    16
    pub fn new(id: I, symmetrical: bool, hard_match: bool) -> Self {
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    17
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    18
            id,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    19
            symmetrical,
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    20
            reverse: false,
16109
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    21
            hard_match,
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    22
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    23
    }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    24
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15951
diff changeset
    25
    #[inline]
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    26
    pub fn reversed(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    27
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    28
            id: self.id.clone(),
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    29
            symmetrical: self.symmetrical,
15951
5f00829c55ec Refactor landgen package structure
unC0Rr
parents: 15950
diff changeset
    30
            reverse: !self.symmetrical && !self.reverse,
16109
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    31
            hard_match: self.hard_match,
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    32
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
    33
    }
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    34
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15951
diff changeset
    35
    #[inline]
16109
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    36
    pub fn hard_match(&self) -> bool {
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    37
        self.hard_match
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    38
    }
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    39
2fc37552b587 Introduce hard match option for edges to reduce backtracking
unC0Rr
parents: 16108
diff changeset
    40
    #[inline]
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
    41
    pub fn is_compatible(&self, other: &Self) -> bool {
15949
659c92124c26 Fix some bugs
unC0Rr
parents: 15948
diff changeset
    42
        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
    43
    }
15946
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
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    46
impl Edge<String> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    47
    pub fn name(&self) -> String {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    48
        if self.reverse {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    49
            self.id.chars().rev().collect()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    50
        } else {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    51
            self.id.clone()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    52
        }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    53
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    54
}
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    55
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    56
#[derive(PartialEq, Clone, Debug)]
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    57
pub struct EdgeSet<I: PartialEq + Clone>([Edge<I>; 4]);
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    58
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    59
impl<I: PartialEq + Clone> EdgeSet<I> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    60
    pub fn new(edge_set: [Edge<I>; 4]) -> Self {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    61
        Self(edge_set)
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    62
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    63
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    64
    pub fn top(&self) -> &Edge<I> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    65
        &self.0[0]
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    66
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    67
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    68
    pub fn right(&self) -> &Edge<I> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    69
        &self.0[1]
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    70
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    71
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    72
    pub fn bottom(&self) -> &Edge<I> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    73
        &self.0[2]
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    74
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    75
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    76
    pub fn left(&self) -> &Edge<I> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    77
        &self.0[3]
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    78
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    79
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    80
    pub fn mirrored(&self) -> Self {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    81
        Self([
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    82
            self.0[0].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    83
            self.0[3].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    84
            self.0[2].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    85
            self.0[1].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    86
        ])
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    87
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    88
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    89
    pub fn flipped(&self) -> Self {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    90
        Self([
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    91
            self.0[2].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    92
            self.0[1].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    93
            self.0[0].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    94
            self.0[3].reversed(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    95
        ])
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    96
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    97
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    98
    pub fn rotated90(&self) -> Self {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
    99
        Self([
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   100
            self.0[3].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   101
            self.0[0].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   102
            self.0[1].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   103
            self.0[2].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   104
        ])
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   105
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   106
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   107
    pub fn rotated180(&self) -> Self {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   108
        Self([
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   109
            self.0[2].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   110
            self.0[3].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   111
            self.0[0].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   112
            self.0[1].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   113
        ])
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   114
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   115
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   116
    pub fn rotated270(&self) -> Self {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   117
        Self([
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   118
            self.0[1].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   119
            self.0[2].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   120
            self.0[3].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   121
            self.0[0].clone(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   122
        ])
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   123
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   124
}
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   125
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   126
#[derive(PartialEq, Clone, Debug)]
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   127
pub enum MatchSide {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   128
    OnTop,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   129
    OnRight,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   130
    OnBottom,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   131
    OnLeft,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   132
}
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   133
#[derive(Clone)]
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   134
pub struct TileImage<T, I: PartialEq + Clone> {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   135
    image: Rc<Vec2D<T>>,
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   136
    pub weight: u8,
15949
659c92124c26 Fix some bugs
unC0Rr
parents: 15948
diff changeset
   137
    pub transform: Transform,
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   138
    edges: EdgeSet<I>,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   139
    anti_match: [u64; 4],
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   140
}
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   141
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   142
impl<T: Copy, I: PartialEq + Clone> TileImage<T, I> {
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   143
    pub fn new(image: Vec2D<T>, weight: u8, edges: EdgeSet<I>, anti_match: [u64; 4]) -> Self {
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   144
        Self {
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   145
            image: Rc::new(image),
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   146
            weight,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   147
            transform: Transform::default(),
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   148
            edges,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   149
            anti_match,
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   150
        }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   151
    }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   152
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   153
    pub fn is_compatible(&self, other: &Self, direction: MatchSide) -> bool {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   154
        match direction {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   155
            MatchSide::OnTop => {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   156
                self.anti_match[0] & other.anti_match[2] == 0
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   157
                    && self
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   158
                        .edge_set()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   159
                        .top()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   160
                        .is_compatible(other.edge_set().bottom())
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   161
            }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   162
            MatchSide::OnRight => {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   163
                self.anti_match[1] & other.anti_match[3] == 0
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   164
                    && self
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   165
                        .edge_set()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   166
                        .right()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   167
                        .is_compatible(other.edge_set().left())
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   168
            }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   169
            MatchSide::OnBottom => {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   170
                self.anti_match[2] & other.anti_match[0] == 0
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   171
                    && self
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   172
                        .edge_set()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   173
                        .bottom()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   174
                        .is_compatible(other.edge_set().top())
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   175
            }
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   176
            MatchSide::OnLeft => {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   177
                self.anti_match[3] & other.anti_match[1] == 0
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   178
                    && self
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   179
                        .edge_set()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   180
                        .left()
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   181
                        .is_compatible(other.edge_set().right())
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   182
            }
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   183
        }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   184
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   185
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   186
    pub fn mirrored(&self) -> Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   187
        Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   188
            image: self.image.clone(),
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   189
            weight: self.weight,
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   190
            transform: self.transform.mirror(),
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   191
            edges: self.edges.mirrored(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   192
            anti_match: [
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   193
                self.anti_match[0],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   194
                self.anti_match[3],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   195
                self.anti_match[2],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   196
                self.anti_match[1],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   197
            ],
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   198
        }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   199
    }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   200
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   201
    pub fn flipped(&self) -> Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   202
        Self {
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   203
            image: self.image.clone(),
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   204
            weight: self.weight,
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   205
            transform: self.transform.flip(),
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   206
            edges: self.edges.flipped(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   207
            anti_match: [
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   208
                self.anti_match[2],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   209
                self.anti_match[1],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   210
                self.anti_match[0],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   211
                self.anti_match[3],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   212
            ],
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   213
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   214
    }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   215
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   216
    pub fn rotated90(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   217
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   218
            image: self.image.clone(),
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   219
            weight: self.weight,
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   220
            transform: self.transform.rotate90(),
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   221
            edges: self.edges.rotated90(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   222
            anti_match: [
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   223
                self.anti_match[3],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   224
                self.anti_match[0],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   225
                self.anti_match[1],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   226
                self.anti_match[2],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   227
            ],
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   228
        }
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   229
    }
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   230
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   231
    pub fn rotated180(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   232
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   233
            image: self.image.clone(),
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   234
            weight: self.weight,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   235
            transform: self.transform.rotate180(),
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   236
            edges: self.edges.rotated180(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   237
            anti_match: [
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   238
                self.anti_match[2],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   239
                self.anti_match[3],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   240
                self.anti_match[0],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   241
                self.anti_match[1],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   242
            ],
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   243
        }
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   244
    }
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   245
15946
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   246
    pub fn rotated270(&self) -> Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   247
        Self {
e82de0410da5 Rework how rules are defined, add transformations for tiles
unC0Rr
parents: 15945
diff changeset
   248
            image: self.image.clone(),
16106
aba25f4e4645 Implement configurable weight for tiles
unC0Rr
parents: 15954
diff changeset
   249
            weight: self.weight,
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   250
            transform: self.transform.rotate270(),
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   251
            edges: self.edges.rotated270(),
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   252
            anti_match: [
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   253
                self.anti_match[1],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   254
                self.anti_match[2],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   255
                self.anti_match[3],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   256
                self.anti_match[0],
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   257
            ],
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   258
        }
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   259
    }
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   260
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15951
diff changeset
   261
    #[inline]
16108
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   262
    pub fn edge_set(&self) -> &EdgeSet<I> {
65c017453e83 Add anti_match feature, log some info when cannot satisfy rules
unC0Rr
parents: 16106
diff changeset
   263
        &self.edges
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   264
    }
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   265
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15951
diff changeset
   266
    #[inline]
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   267
    pub fn size(&self) -> Size {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   268
        match self.transform {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   269
            Transform::Rotate0(_) => self.image.size(),
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   270
            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
   271
        }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   272
    }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   273
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15951
diff changeset
   274
    #[inline]
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   275
    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
   276
        match self.transform {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   277
            Transform::Rotate0(_) => {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   278
                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
   279
                    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
   280
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   281
                    row
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   282
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   283
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   284
                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
   285
                    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
   286
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   287
                    column
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   288
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   289
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   290
                self.image.get(image_row, image_column)
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   291
            }
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   292
            Transform::Rotate90(_) => {
15949
659c92124c26 Fix some bugs
unC0Rr
parents: 15948
diff changeset
   293
                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
   294
                    column
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   295
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   296
                    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
   297
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   298
15949
659c92124c26 Fix some bugs
unC0Rr
parents: 15948
diff changeset
   299
                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
   300
                    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
   301
                } else {
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   302
                    row
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   303
                };
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   304
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   305
                self.image.get(image_row, image_column)
15950
168f44ef9b67 Extract tile loading into separate method
unC0Rr
parents: 15949
diff changeset
   306
            }
15948
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   307
        }
9bd828451d77 Fix several issues with transformations, more work on getting generated image
unC0Rr
parents: 15947
diff changeset
   308
    }
15943
c5684cc62de8 Switch to Vec2D in wavefront algorithm
unC0Rr
parents:
diff changeset
   309
}
15945
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   310
8f093b1b18bc Add loading of tiles from png
unC0Rr
parents: 15943
diff changeset
   311
#[cfg(test)]
15947
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   312
mod tests {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   313
    use super::*;
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   314
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   315
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   316
    fn test_edge_new() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   317
        let edge = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   318
        assert_eq!(edge.id, 1);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   319
        assert_eq!(edge.symmetrical, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   320
        assert_eq!(edge.reverse, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   321
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   322
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   323
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   324
    fn test_edge_reversed() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   325
        let edge = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   326
        let reversed = edge.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   327
        assert_eq!(reversed.id, edge.id);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   328
        assert_eq!(reversed.symmetrical, edge.symmetrical);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   329
        assert_eq!(reversed.reverse, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   330
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   331
        let edge = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   332
        let reversed = edge.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   333
        assert_eq!(reversed.id, edge.id);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   334
        assert_eq!(reversed.symmetrical, edge.symmetrical);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   335
        assert_eq!(reversed.reverse, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   336
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   337
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   338
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   339
    fn test_edge_equality() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   340
        let edge1 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   341
        let edge2 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   342
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   343
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   344
        let edge1 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   345
        let edge2 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   346
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   347
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   348
        let edge1 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   349
        let edge2 = Edge::new(2, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   350
        assert_ne!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   351
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   352
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   353
    #[test]
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   354
    fn test_edge_equality_with_reverse() {
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   355
        let edge1 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   356
        let edge2 = edge1.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   357
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   358
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   359
        let edge1 = Edge::new(1, false);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   360
        let edge2 = edge1.reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   361
        assert_ne!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   362
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   363
        let edge1 = Edge::new(1, true);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   364
        let edge2 = edge1.reversed().reversed();
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   365
        assert_eq!(edge1, edge2);
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   366
    }
60b5639cc3a5 Add WIP for generation of rules
unC0Rr
parents: 15946
diff changeset
   367
}