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