fix atlas.insert
authoralfadur
Wed, 27 Mar 2019 22:10:46 +0300
changeset 14746 19d30d96d7d6
parent 14745 fbd385a1bcf4
child 14747 75ff5c643004
fix atlas.insert
rust/integral-geometry/src/lib.rs
rust/lib-hedgewars-engine/src/render/atlas.rs
--- a/rust/integral-geometry/src/lib.rs	Wed Mar 27 09:52:08 2019 -0400
+++ b/rust/integral-geometry/src/lib.rs	Wed Mar 27 22:10:46 2019 +0300
@@ -311,7 +311,7 @@
 impl Rect {
     pub const EMPTY: Self = Self {
         top_left: Point::ZERO,
-        bottom_right: Point::ZERO,
+        bottom_right: Point::diag(-1),
     };
 
     #[inline]
@@ -454,9 +454,9 @@
     #[inline]
     pub fn with_margins(&self, left: i32, right: i32, top: i32, bottom: i32) -> Self {
         Self::from_box(
-            self.left() + left,
+            self.left() - left,
             self.right() + right,
-            self.top() + top,
+            self.top() - top,
             self.bottom() + bottom,
         )
     }
--- a/rust/lib-hedgewars-engine/src/render/atlas.rs	Wed Mar 27 09:52:08 2019 -0400
+++ b/rust/lib-hedgewars-engine/src/render/atlas.rs	Wed Mar 27 22:10:46 2019 +0300
@@ -3,15 +3,15 @@
 
 #[derive(PartialEq, Eq, PartialOrd, Ord, Clone)]
 struct Fit {
-    short_size: u32,
-    long_size: u32,
+    short_side: u32,
+    long_side: u32,
 }
 
 impl Fit {
     fn new() -> Self {
         Self {
-            short_size: u32::max_value(),
-            long_size: u32::max_value(),
+            short_side: u32::max_value(),
+            long_side: u32::max_value(),
         }
     }
 
@@ -20,8 +20,8 @@
             let x_leftover = container.width - size.width;
             let y_leftover = container.height - size.height;
             Some(Self {
-                short_size: min(x_leftover, y_leftover) as u32,
-                long_size: max(x_leftover, y_leftover) as u32,
+                short_side: min(x_leftover, y_leftover) as u32,
+                long_side: max(x_leftover, y_leftover) as u32,
             })
         } else {
             None
@@ -278,9 +278,12 @@
             let mut atlas = Atlas::new(container.size());
             let inserted: Vec<_> = rects.iter().filter_map(|TestRect(size)| atlas.insert(*size)).collect();
 
-            assert!(inserted.iter().all(|r| container.contains_rect(r)));
+            let mut inserted_pairs = inserted.iter().zip(&inserted);
 
-            assert_eq!(inserted.len(), rects.len());
+            assert!(inserted.iter().all(|r| container.contains_rect(r)));
+            assert!(inserted_pairs.all(|(r1, r2)| r1 == r2 || r1 != r2 && r1.intersects(r2)));
+
+            assert(inserted.len(), rects.len());
             assert_eq!(sum_area(&inserted), sum_area(&rects));
         }
     }