require additonally NumAssign + PartialOrd + Default trait on generic types for Rect_ et al
MODIFY
src/manual/core.rs
src/manual/core.rs
@@ -7,7 +7,7 @@ pub use self::vec::*;
macro_rules! valid_types {
($trait: ident, $($rust_type: ty),+) => {
/// This sealed trait is implemented for types that are valid to use in corresponding context
- pub trait $trait: Copy + private::Sealed {}
+ pub trait $trait: ::num::traits::NumAssign + PartialOrd + Default + Copy + private::Sealed {}
mod private {
pub trait Sealed {}

MODIFY
src/manual/core/point.rs
src/manual/core/point.rs
@@ -7,7 +7,7 @@ use crate::core::{Rect_, Size_, ValidRectType, ValidSizeType};
valid_types!(ValidPointType, i32, i64, f32, f64);
#[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq)]
+#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
/// [docs.opencv.org](https://docs.opencv.org/master/db/d4e/classcv_1_1Point__.html)
pub struct Point_<T: ValidPointType> {
pub x: T,
@@ -35,7 +35,7 @@ impl<T: ValidPointType> Point_<T> {
}
#[inline]
- pub fn dot(self, pt: Point_<T>) -> T where T: Mul<Output=T> + Add<Output=T> {
+ pub fn dot(self, pt: Point_<T>) -> T {
self.x * pt.x + self.y * pt.y
}
@@ -49,7 +49,7 @@ impl<T: ValidPointType> Point_<T> {
}
#[inline]
- pub fn inside(self, rect: Rect_<T>) -> bool where T: ValidRectType + Add<Output=T> + PartialOrd {
+ pub fn inside(self, rect: Rect_<T>) -> bool where T: ValidRectType {
rect.contains(self)
}
@@ -66,12 +66,6 @@ impl<T: ValidPointType> Point_<T> {
}
}
-impl<T: ValidPointType + Default> Default for Point_<T> {
- fn default() -> Self {
- Self { x: Default::default(), y: Default::default() }
- }
-}
-
impl<T> Add for Point_<T>
where
T: ValidPointType + AddAssign,

MODIFY
src/manual/core/rect.rs
src/manual/core/rect.rs
use std::{
fmt,
- ops::{Add, AddAssign, Mul, Sub, SubAssign},
+ ops::{Add, AddAssign, Sub, SubAssign},
};
-use num::{NumCast, ToPrimitive, Zero};
+use num::{NumCast, ToPrimitive};
use crate::core::{Point_, RotatedRect, Size_, ValidPointType, ValidSizeType};
@@ -20,7 +20,7 @@ fn partial_max<T: PartialOrd>(a: T, b: T) -> T {
}
#[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq)]
+#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
/// [docs.opencv.org](https://docs.opencv.org/master/d2/d44/classcv_1_1Rect__.html)
pub struct Rect_<T: ValidRectType> {
pub x: T,
@@ -41,7 +41,7 @@ impl<T: ValidRectType> Rect_<T> {
}
#[inline]
- pub fn from_points(pt1: Point_<T>, pt2: Point_<T>) -> Self where T: ValidPointType + PartialOrd + Sub<Output=T> {
+ pub fn from_points(pt1: Point_<T>, pt2: Point_<T>) -> Self where T: ValidPointType {
let x = partial_min(pt1.x, pt2.x);
let y = partial_min(pt1.y, pt2.y);
Self::new(x, y, partial_max(pt1.x, pt2.x) - x, partial_max(pt1.y, pt2.y) - y)
@@ -53,7 +53,7 @@ impl<T: ValidRectType> Rect_<T> {
}
#[inline]
- pub fn br(&self) -> Point_<T> where T: ValidPointType + Add<Output=T> {
+ pub fn br(&self) -> Point_<T> where T: ValidPointType {
Point_::new(self.x + self.width, self.y + self.height)
}
@@ -63,17 +63,17 @@ impl<T: ValidRectType> Rect_<T> {
}
#[inline]
- pub fn area(&self) -> T where T: Mul<Output=T> {
+ pub fn area(&self) -> T {
self.width * self.height
}
#[inline]
- pub fn empty(&self) -> bool where T: Zero + PartialOrd {
+ pub fn empty(&self) -> bool {
self.width <= T::zero() || self.height <= T::zero()
}
#[inline]
- pub fn contains(&self, pt: Point_<T>) -> bool where T: ValidPointType + Add<Output=T> + PartialOrd {
+ pub fn contains(&self, pt: Point_<T>) -> bool where T: ValidPointType {
self.x <= pt.x && pt.x < self.x + self.width && self.y <= pt.y && pt.y < self.y + self.height
}
@@ -83,12 +83,6 @@ impl<T: ValidRectType> Rect_<T> {
}
}
-impl<T: ValidRectType + Default> Default for Rect_<T> {
- fn default() -> Self {
- Self { x: Default::default(), y: Default::default(), width: Default::default(), height: Default::default() }
- }
-}
-
impl<P, R> Add<Point_<P>> for Rect_<R>
where
P: ValidPointType,

MODIFY
src/manual/core/size.rs
src/manual/core/size.rs
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
-use num::{NumCast, ToPrimitive, Zero};
+use num::{NumCast, ToPrimitive};
use crate::core::{Point_, ValidPointType};
valid_types!(ValidSizeType, i32, i64, f32, f64);
#[repr(C)]
-#[derive(Copy, Clone, Debug, PartialEq)]
+#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
/// [docs.opencv.org](https://docs.opencv.org/master/d6/d50/classcv_1_1Size__.html)
pub struct Size_<T: ValidSizeType> {
pub width: T,
@@ -26,12 +26,12 @@ impl<T: ValidSizeType> Size_<T> {
}
#[inline]
- pub fn area(self) -> T where T: Mul<Output=T> {
+ pub fn area(self) -> T {
self.width * self.height
}
#[inline]
- pub fn empty(self) -> bool where T: Zero + PartialOrd {
+ pub fn empty(self) -> bool {
self.width <= T::zero() || self.height <= T::zero()
}
@@ -41,12 +41,6 @@ impl<T: ValidSizeType> Size_<T> {
}
}
-impl<T: ValidSizeType + Default> Default for Size_<T> {
- fn default() -> Self {
- Self { width: Default::default(), height: Default::default() }
- }
-}
-
impl<T> Add for Size_<T>
where
T: ValidSizeType + AddAssign,

require additonally NumAssign + PartialOrd + Default trait on generic types for Rect_ et al