rust/integral-geometry/src/lib.rs
branchui-scaling
changeset 15663 d92eeb468dad
parent 15384 1c6d5656157c
child 15751 a4558e2be08c
--- a/rust/integral-geometry/src/lib.rs	Wed Jul 31 23:14:27 2019 +0200
+++ b/rust/integral-geometry/src/lib.rs	Fri Jul 03 23:51:47 2020 +0200
@@ -45,7 +45,7 @@
 
     #[inline]
     pub fn integral_norm(self) -> u32 {
-        let sqr = (self.x as u64).pow(2) + (self.y as u64).pow(2);
+        let sqr = (self.x as u64).wrapping_pow(2) + (self.y as u64).wrapping_pow(2);
         integral_sqrt(sqr) as u32
     }
 
@@ -171,6 +171,14 @@
     pub fn contains(&self, other: Self) -> bool {
         self.width >= other.width && self.height >= other.height
     }
+
+    #[inline]
+    pub fn join(&self, other: Self) -> Self {
+        Self {
+            width: max(self.width, other.width),
+            height: max(self.height, other.height)
+        }
+    }
 }
 
 #[derive(PartialEq, Eq, Clone, Copy, Debug)]