author | unC0Rr |
Sun, 02 Feb 2025 17:47:54 +0100 | |
changeset 16108 | 65c017453e83 |
parent 16106 | aba25f4e4645 |
child 16109 | 2fc37552b587 |
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, |
15943 | 11 |
} |
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 | 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 | 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 | 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 | 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 | 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 | 128 |
pub weight: u8, |
15949 | 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 | 136 |
Self { |
15945 | 137 |
image: Rc::new(image), |
16106 | 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 | 175 |
} |
176 |
} |
|
177 |
||
178 |
pub fn mirrored(&self) -> Self { |
|
179 |
Self { |
|
180 |
image: self.image.clone(), |
|
16106 | 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 | 190 |
} |
191 |
} |
|
192 |
||
193 |
pub fn flipped(&self) -> Self { |
|
194 |
Self { |
|
195 |
image: self.image.clone(), |
|
16106 | 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 | 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 | 220 |
} |
221 |
} |
|
15945 | 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 | 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 | 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 | 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 | 250 |
} |
251 |
} |
|
15947 | 252 |
|
15954 | 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 | 256 |
} |
15948
9bd828451d77
Fix several issues with transformations, more work on getting generated image
unC0Rr
parents:
15947
diff
changeset
|
257 |
|
15954 | 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 | 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 | 283 |
} |
15948
9bd828451d77
Fix several issues with transformations, more work on getting generated image
unC0Rr
parents:
15947
diff
changeset
|
284 |
Transform::Rotate90(_) => { |
15949 | 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 | 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 | 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 | 301 |
} |
15945 | 302 |
|
303 |
#[cfg(test)] |
|
15947 | 304 |
mod tests { |
305 |
use super::*; |
|
306 |
||
307 |
#[test] |
|
308 |
fn test_edge_new() { |
|
309 |
let edge = Edge::new(1, true); |
|
310 |
assert_eq!(edge.id, 1); |
|
311 |
assert_eq!(edge.symmetrical, true); |
|
312 |
assert_eq!(edge.reverse, false); |
|
313 |
} |
|
314 |
||
315 |
#[test] |
|
316 |
fn test_edge_reversed() { |
|
317 |
let edge = Edge::new(1, true); |
|
318 |
let reversed = edge.reversed(); |
|
319 |
assert_eq!(reversed.id, edge.id); |
|
320 |
assert_eq!(reversed.symmetrical, edge.symmetrical); |
|
321 |
assert_eq!(reversed.reverse, false); |
|
322 |
||
323 |
let edge = Edge::new(1, false); |
|
324 |
let reversed = edge.reversed(); |
|
325 |
assert_eq!(reversed.id, edge.id); |
|
326 |
assert_eq!(reversed.symmetrical, edge.symmetrical); |
|
327 |
assert_eq!(reversed.reverse, true); |
|
328 |
} |
|
329 |
||
330 |
#[test] |
|
331 |
fn test_edge_equality() { |
|
332 |
let edge1 = Edge::new(1, true); |
|
333 |
let edge2 = Edge::new(1, true); |
|
334 |
assert_eq!(edge1, edge2); |
|
335 |
||
336 |
let edge1 = Edge::new(1, false); |
|
337 |
let edge2 = Edge::new(1, false); |
|
338 |
assert_eq!(edge1, edge2); |
|
339 |
||
340 |
let edge1 = Edge::new(1, false); |
|
341 |
let edge2 = Edge::new(2, false); |
|
342 |
assert_ne!(edge1, edge2); |
|
343 |
} |
|
344 |
||
345 |
#[test] |
|
346 |
fn test_edge_equality_with_reverse() { |
|
347 |
let edge1 = Edge::new(1, true); |
|
348 |
let edge2 = edge1.reversed(); |
|
349 |
assert_eq!(edge1, edge2); |
|
350 |
||
351 |
let edge1 = Edge::new(1, false); |
|
352 |
let edge2 = edge1.reversed(); |
|
353 |
assert_ne!(edge1, edge2); |
|
354 |
||
355 |
let edge1 = Edge::new(1, true); |
|
356 |
let edge2 = edge1.reversed().reversed(); |
|
357 |
assert_eq!(edge1, edge2); |
|
358 |
} |
|
359 |
} |