Drop ValidSizeType requirement
MODIFY
src/manual/core/data_type.rs
src/manual/core/data_type.rs
-use crate::core::{self, Point3_, Point_, Rect_, Size_, ValidSizeType, VecN};
+use crate::core::{self, Point3_, Point_, Rect_, Size_, VecN};
#[inline]
pub const fn CV_MAT_DEPTH(flags: i32) -> i32 {
@@ -89,7 +89,7 @@ impl<T: DataType> DataType for Point3_<T> {
fn channels() -> i32 { 3 }
}
-impl<T: ValidSizeType + DataType> DataType for Size_<T> {
+impl<T: DataType> DataType for Size_<T> {
#[inline]
fn depth() -> i32 { T::depth() }
@@ -115,6 +115,6 @@ impl<T: DataType> private::Sealed for Point_<T> {}
impl<T: DataType> private::Sealed for Point3_<T> {}
-impl<T: ValidSizeType + DataType> private::Sealed for Size_<T> {}
+impl<T: DataType> private::Sealed for Size_<T> {}
impl<T: DataType> private::Sealed for Rect_<T> {}

MODIFY
src/manual/core/point.rs
src/manual/core/point.rs
@@ -3,7 +3,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use num_traits::{NumCast, NumOps, ToPrimitive};
use crate::{
- core::{Rect_, Size_, ValidSizeType, ValidVecType, VecN},
+ core::{Rect_, Size_, ValidVecType, VecN},
opencv_type_simple_generic,
};
@@ -28,7 +28,7 @@ impl<T> Point_<T> {
}
#[inline]
- pub fn from_size(sz: Size_<T>) -> Self where T: ValidSizeType {
+ pub fn from_size(sz: Size_<T>) -> Self {
Self::new(sz.width, sz.height)
}

MODIFY
src/manual/core/rect.rs
src/manual/core/rect.rs
@@ -6,7 +6,7 @@ use std::{
use num_traits::{NumCast, NumOps, ToPrimitive, Zero};
use crate::{
- core::{Point_, prelude::*, RotatedRect, Size_, ValidSizeType},
+ core::{Point_, prelude::*, RotatedRect, Size_},
opencv_type_simple_generic,
};
@@ -37,7 +37,7 @@ impl<T> Rect_<T> {
}
#[inline]
- pub fn from_point_size(pt: Point_<T>, sz: Size_<T>) -> Self where T: ValidSizeType {
+ pub fn from_point_size(pt: Point_<T>, sz: Size_<T>) -> Self {
Self::new(pt.x, pt.y, sz.width, sz.height)
}
@@ -59,7 +59,7 @@ impl<T> Rect_<T> {
}
#[inline]
- pub fn size(&self) -> Size_<T> where T: ValidSizeType {
+ pub fn size(&self) -> Size_<T> where T: Copy {
Size_::new(self.width, self.height)
}
@@ -104,7 +104,7 @@ impl<P, R> Sub<Point_<P>> for Rect_<R> where Self: SubAssign<Point_<P>> {
}
}
-impl<S: ValidSizeType, R> Add<Size_<S>> for Rect_<R> where Self: AddAssign<Size_<S>> {
+impl<S, R> Add<Size_<S>> for Rect_<R> where Self: AddAssign<Size_<S>> {
type Output = Self;
fn add(mut self, rhs: Size_<S>) -> Self::Output {
@@ -113,7 +113,7 @@ impl<S: ValidSizeType, R> Add<Size_<S>> for Rect_<R> where Self: AddAssign<Size_
}
}
-impl<S: ValidSizeType, R> Sub<Size_<S>> for Rect_<R> where Self: SubAssign<Size_<S>> {
+impl<S, R> Sub<Size_<S>> for Rect_<R> where Self: SubAssign<Size_<S>> {
type Output = Self;
fn sub(mut self, rhs: Size_<S>) -> Self::Output {
@@ -154,14 +154,14 @@ impl<P, R: SubAssign<P>> SubAssign<Point_<P>> for Rect_<R> {
}
}
-impl<S: ValidSizeType, R: AddAssign<S>> AddAssign<Size_<S>> for Rect_<R> {
+impl<S, R: AddAssign<S>> AddAssign<Size_<S>> for Rect_<R> {
fn add_assign(&mut self, rhs: Size_<S>) {
self.width += rhs.width;
self.height += rhs.height;
}
}
-impl<S: ValidSizeType, R: SubAssign<S>> SubAssign<Size_<S>> for Rect_<R> {
+impl<S, R: SubAssign<S>> SubAssign<Size_<S>> for Rect_<R> {
fn sub_assign(&mut self, rhs: Size_<S>) {
self.width -= rhs.width;
self.height -= rhs.height;

MODIFY
src/manual/core/size.rs
src/manual/core/size.rs
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
-use num_traits::{NumCast, ToPrimitive};
+use num_traits::{NumCast, ToPrimitive, Zero};
use crate::{
core::Point_,
opencv_type_simple_generic,
};
-valid_types!(ValidSizeType: i32, i64, f32, f64);
-
#[repr(C)]
#[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 struct Size_<T> {
pub width: T,
pub height: T,
}
-impl<T: ValidSizeType> Size_<T> {
+impl<T> Size_<T> {
#[inline]
pub fn new(width: T, height: T) -> Self {
Self { width, height }
@@ -29,52 +27,43 @@ impl<T: ValidSizeType> Size_<T> {
}
#[inline]
- pub fn area(self) -> T {
+ pub fn area(self) -> T where T: Mul<Output=T> {
self.width * self.height
}
#[inline]
- pub fn empty(self) -> bool {
+ pub fn empty(self) -> bool where T: PartialOrd + Zero {
self.width <= T::zero() || self.height <= T::zero()
}
#[inline]
- pub fn to<D: ValidSizeType + NumCast>(self) -> Option<Size_<D>> where T: ToPrimitive {
+ pub fn to<D: NumCast>(self) -> Option<Size_<D>> where T: ToPrimitive {
Some(Size_ { width: D::from(self.width)?, height: D::from(self.height)? })
}
}
-opencv_type_simple_generic! { Size_<ValidSizeType> }
+opencv_type_simple_generic! { Size_<Copy> }
-impl<T> Add for Size_<T>
- where
- T: ValidSizeType + AddAssign,
-{
- type Output = Size_<T>;
+impl<T> Add for Size_<T> where Self: AddAssign {
+ type Output = Self;
- fn add(mut self, rhs: Size_<T>) -> Self::Output {
+ fn add(mut self, rhs: Self) -> Self::Output {
self += rhs;
self
}
}
-impl<T> Sub for Size_<T>
- where
- T: ValidSizeType + SubAssign,
-{
- type Output = Size_<T>;
+impl<T> Sub for Size_<T> where Self: SubAssign {
+ type Output = Self;
- fn sub(mut self, rhs: Size_<T>) -> Self::Output {
+ fn sub(mut self, rhs: Self) -> Self::Output {
self -= rhs;
self
}
}
-impl<T> Mul<T> for Size_<T>
- where
- T: ValidSizeType + MulAssign
-{
- type Output = Size_<T>;
+impl<T> Mul<T> for Size_<T> where Self: MulAssign<T> {
+ type Output = Self;
fn mul(mut self, rhs: T) -> Self::Output {
self *= rhs;
@@ -82,11 +71,8 @@ impl<T> Mul<T> for Size_<T>
}
}
-impl<T> Div<T> for Size_<T>
- where
- T: ValidSizeType + DivAssign
-{
- type Output = Size_<T>;
+impl<T> Div<T> for Size_<T> where Self: DivAssign<T> {
+ type Output = Self;
fn div(mut self, rhs: T) -> Self::Output {
self /= rhs;
@@ -94,40 +80,28 @@ impl<T> Div<T> for Size_<T>
}
}
-impl<T> AddAssign for Size_<T>
- where
- T: ValidSizeType + AddAssign,
-{
- fn add_assign(&mut self, rhs: Size_<T>) {
+impl<T: AddAssign> AddAssign for Size_<T> {
+ fn add_assign(&mut self, rhs: Self) {
self.width += rhs.width;
self.height += rhs.height;
}
}
-impl<T> SubAssign for Size_<T>
- where
- T: ValidSizeType + SubAssign,
-{
- fn sub_assign(&mut self, rhs: Size_<T>) {
+impl<T: SubAssign> SubAssign for Size_<T> {
+ fn sub_assign(&mut self, rhs: Self) {
self.width -= rhs.width;
self.height -= rhs.height;
}
}
-impl<T> MulAssign<T> for Size_<T>
- where
- T: ValidSizeType + MulAssign
-{
+impl<T: MulAssign + Copy> MulAssign<T> for Size_<T> {
fn mul_assign(&mut self, rhs: T) {
self.width *= rhs;
self.height *= rhs;
}
}
-impl<T> DivAssign<T> for Size_<T>
- where
- T: ValidSizeType + DivAssign
-{
+impl<T: DivAssign + Copy> DivAssign<T> for Size_<T> {
fn div_assign(&mut self, rhs: T) {
self.width /= rhs;
self.height /= rhs;

Drop ValidSizeType requirement