author | unC0Rr |
Sun, 02 Feb 2025 22:30:49 +0100 | |
changeset 16109 | 2fc37552b587 |
parent 16108 | 65c017453e83 |
permissions | -rw-r--r-- |
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 | 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 | 5 |
|
15947 | 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 | 12 |
} |
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 | 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 | 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 | 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 | 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 | 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 | 136 |
pub weight: u8, |
15949 | 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 | 144 |
Self { |
15945 | 145 |
image: Rc::new(image), |
16106 | 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 | 183 |
} |
184 |
} |
|
185 |
||
186 |
pub fn mirrored(&self) -> Self { |
|
187 |
Self { |
|
188 |
image: self.image.clone(), |
|
16106 | 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 | 198 |
} |
199 |
} |
|
200 |
||
201 |
pub fn flipped(&self) -> Self { |
|
202 |
Self { |
|
203 |
image: self.image.clone(), |
|
16106 | 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 | 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 | 228 |
} |
229 |
} |
|
15945 | 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 | 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 | 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 | 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 | 258 |
} |
259 |
} |
|
15947 | 260 |
|
15954 | 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 | 264 |
} |
15948
9bd828451d77
Fix several issues with transformations, more work on getting generated image
unC0Rr
parents:
15947
diff
changeset
|
265 |
|
15954 | 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 | 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 | 291 |
} |
15948
9bd828451d77
Fix several issues with transformations, more work on getting generated image
unC0Rr
parents:
15947
diff
changeset
|
292 |
Transform::Rotate90(_) => { |
15949 | 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 | 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 | 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 | 309 |
} |
15945 | 310 |
|
311 |
#[cfg(test)] |
|
15947 | 312 |
mod tests { |
313 |
use super::*; |
|
314 |
||
315 |
#[test] |
|
316 |
fn test_edge_new() { |
|
317 |
let edge = Edge::new(1, true); |
|
318 |
assert_eq!(edge.id, 1); |
|
319 |
assert_eq!(edge.symmetrical, true); |
|
320 |
assert_eq!(edge.reverse, false); |
|
321 |
} |
|
322 |
||
323 |
#[test] |
|
324 |
fn test_edge_reversed() { |
|
325 |
let edge = Edge::new(1, true); |
|
326 |
let reversed = edge.reversed(); |
|
327 |
assert_eq!(reversed.id, edge.id); |
|
328 |
assert_eq!(reversed.symmetrical, edge.symmetrical); |
|
329 |
assert_eq!(reversed.reverse, false); |
|
330 |
||
331 |
let edge = Edge::new(1, false); |
|
332 |
let reversed = edge.reversed(); |
|
333 |
assert_eq!(reversed.id, edge.id); |
|
334 |
assert_eq!(reversed.symmetrical, edge.symmetrical); |
|
335 |
assert_eq!(reversed.reverse, true); |
|
336 |
} |
|
337 |
||
338 |
#[test] |
|
339 |
fn test_edge_equality() { |
|
340 |
let edge1 = Edge::new(1, true); |
|
341 |
let edge2 = Edge::new(1, true); |
|
342 |
assert_eq!(edge1, edge2); |
|
343 |
||
344 |
let edge1 = Edge::new(1, false); |
|
345 |
let edge2 = Edge::new(1, false); |
|
346 |
assert_eq!(edge1, edge2); |
|
347 |
||
348 |
let edge1 = Edge::new(1, false); |
|
349 |
let edge2 = Edge::new(2, false); |
|
350 |
assert_ne!(edge1, edge2); |
|
351 |
} |
|
352 |
||
353 |
#[test] |
|
354 |
fn test_edge_equality_with_reverse() { |
|
355 |
let edge1 = Edge::new(1, true); |
|
356 |
let edge2 = edge1.reversed(); |
|
357 |
assert_eq!(edge1, edge2); |
|
358 |
||
359 |
let edge1 = Edge::new(1, false); |
|
360 |
let edge2 = edge1.reversed(); |
|
361 |
assert_ne!(edge1, edge2); |
|
362 |
||
363 |
let edge1 = Edge::new(1, true); |
|
364 |
let edge2 = edge1.reversed().reversed(); |
|
365 |
assert_eq!(edge1, edge2); |
|
366 |
} |
|
367 |
} |