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

MODIFY
src/manual/core/point.rs
src/manual/core/point.rs
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
-use num_traits::{NumCast, ToPrimitive};
+use num_traits::{NumCast, NumOps, ToPrimitive};
use crate::{
core::{Rect_, Size_, ValidSizeType, ValidVecType, VecN},
opencv_type_simple_generic,
};
-valid_types!(ValidPointType: i32, i64, f32, f64);
-
#[repr(C)]
#[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 struct Point_<T> {
pub x: T,
pub y: T,
}
-impl<T: ValidPointType> Point_<T> {
+impl<T> Point_<T> {
#[inline]
pub fn new(x: T, y: T) -> Self {
Self { x, y }
}
#[inline]
- pub fn from_vec2(vec: VecN<T, 2>) -> Self where T: ValidVecType {
- Self::new(vec[0], vec[1])
+ pub fn from_vec2(vec: VecN<T, 2>) -> Self {
+ let [x, y] = vec.0;
+ Self::new(x, y)
}
#[inline]
@@ -43,7 +42,7 @@ impl<T: ValidPointType> Point_<T> {
}
#[inline]
- pub fn dot(self, pt: Point_<T>) -> T {
+ pub fn dot(self, pt: Point_<T>) -> T where T: NumOps {
self.x * pt.x + self.y * pt.y
}
@@ -57,7 +56,7 @@ impl<T: ValidPointType> Point_<T> {
}
#[inline]
- pub fn inside(self, rect: Rect_<T>) -> bool {
+ pub fn inside(self, rect: Rect_<T>) -> bool where T: PartialOrd + Add<Output=T> + Copy {
rect.contains(self)
}
@@ -69,47 +68,38 @@ impl<T: ValidPointType> Point_<T> {
}
#[inline]
- pub fn to<D: ValidPointType + NumCast>(self) -> Option<Point_<D>> where T: ToPrimitive {
+ pub fn to<D: NumCast>(self) -> Option<Point_<D>> where T: ToPrimitive {
Some(Point_::new(D::from(self.x)?, D::from(self.y)?))
}
#[inline]
- pub fn to_vec2(&self) -> VecN<T, 2> where T: ValidVecType {
+ pub fn to_vec2(self) -> VecN<T, 2> {
VecN::<_, 2>::from([self.x, self.y])
}
}
-opencv_type_simple_generic! { Point_<ValidPointType> }
+opencv_type_simple_generic! { Point_<Copy> }
-impl<T> Add for Point_<T>
- where
- T: ValidPointType + AddAssign,
-{
- type Output = Point_<T>;
+impl<T> Add for Point_<T> where Self: AddAssign, {
+ type Output = Self;
- fn add(mut self, rhs: Point_<T>) -> Self::Output {
+ fn add(mut self, rhs: Self) -> Self::Output {
self += rhs;
self
}
}
-impl<T> Sub for Point_<T>
- where
- T: ValidPointType + SubAssign,
-{
- type Output = Point_<T>;
+impl<T> Sub for Point_<T> where Self: SubAssign {
+ type Output = Self;
- fn sub(mut self, rhs: Point_<T>) -> Self::Output {
+ fn sub(mut self, rhs: Self) -> Self::Output {
self -= rhs;
self
}
}
-impl<T> Mul<T> for Point_<T>
- where
- T: ValidPointType + MulAssign
-{
- type Output = Point_<T>;
+impl<T> Mul<T> for Point_<T> where Self: MulAssign<T> {
+ type Output = Self;
fn mul(mut self, rhs: T) -> Self::Output {
self *= rhs;
@@ -117,11 +107,8 @@ impl<T> Mul<T> for Point_<T>
}
}
-impl<T> Div<T> for Point_<T>
- where
- T: ValidPointType + DivAssign
-{
- type Output = Point_<T>;
+impl<T> Div<T> for Point_<T> where Self: DivAssign<T> {
+ type Output = Self;
fn div(mut self, rhs: T) -> Self::Output {
self /= rhs;
@@ -129,40 +116,28 @@ impl<T> Div<T> for Point_<T>
}
}
-impl<T> AddAssign for Point_<T>
- where
- T: ValidPointType + AddAssign,
-{
- fn add_assign(&mut self, rhs: Point_<T>) {
+impl<T: AddAssign> AddAssign for Point_<T> {
+ fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
}
}
-impl<T> SubAssign for Point_<T>
- where
- T: ValidPointType + SubAssign,
-{
- fn sub_assign(&mut self, rhs: Point_<T>) {
+impl<T: SubAssign> SubAssign for Point_<T> {
+ fn sub_assign(&mut self, rhs: Self) {
self.x -= rhs.x;
self.y -= rhs.y;
}
}
-impl<T> MulAssign<T> for Point_<T>
- where
- T: ValidPointType + MulAssign
-{
+impl<T: MulAssign + Copy> MulAssign<T> for Point_<T> {
fn mul_assign(&mut self, rhs: T) {
self.x *= rhs;
self.y *= rhs;
}
}
-impl<T> DivAssign<T> for Point_<T>
- where
- T: ValidPointType + DivAssign
-{
+impl<T: DivAssign + Copy> DivAssign<T> for Point_<T> {
fn div_assign(&mut self, rhs: T) {
self.x /= rhs;
self.y /= rhs;

MODIFY
src/manual/core/point3.rs
src/manual/core/point3.rs
@@ -3,7 +3,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use num_traits::{NumCast, ToPrimitive, Zero};
use crate::{
- core::{Point_, ValidPointType, ValidVecType, VecN},
+ core::{Point_, ValidVecType, VecN},
opencv_type_simple_generic,
};
@@ -30,7 +30,7 @@ impl<T: ValidPoint3Type> Point3_<T> {
}
#[inline]
- pub fn from_point(pt: Point_<T>) -> Self where T: ValidPointType + Zero {
+ pub fn from_point(pt: Point_<T>) -> Self where T: Zero {
Self::new(pt.x, pt.y, T::zero())
}

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_, ValidPointType, ValidSizeType},
+ core::{Point_, prelude::*, RotatedRect, Size_, ValidSizeType},
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: ValidPointType + ValidSizeType {
+ pub fn from_point_size(pt: Point_<T>, sz: Size_<T>) -> Self where T: ValidSizeType {
Self::new(pt.x, pt.y, sz.width, sz.height)
}
@@ -49,7 +49,7 @@ impl<T> Rect_<T> {
}
#[inline]
- pub fn tl(&self) -> Point_<T> where T: ValidPointType {
+ pub fn tl(&self) -> Point_<T> where T: Copy {
Point_::new(self.x, self.y)
}
@@ -86,7 +86,7 @@ impl<T> Rect_<T> {
opencv_type_simple_generic! { Rect_<Copy> }
-impl<P: ValidPointType, R> Add<Point_<P>> for Rect_<R> where Self: AddAssign<Point_<P>> {
+impl<P, R> Add<Point_<P>> for Rect_<R> where Self: AddAssign<Point_<P>> {
type Output = Self;
fn add(mut self, rhs: Point_<P>) -> Self::Output {
@@ -95,7 +95,7 @@ impl<P: ValidPointType, R> Add<Point_<P>> for Rect_<R> where Self: AddAssign<Poi
}
}
-impl<P: ValidPointType, R> Sub<Point_<P>> for Rect_<R> where Self: SubAssign<Point_<P>> {
+impl<P, R> Sub<Point_<P>> for Rect_<R> where Self: SubAssign<Point_<P>> {
type Output = Self;
fn sub(mut self, rhs: Point_<P>) -> Self::Output {
@@ -140,14 +140,14 @@ impl<T> BitAnd for Rect_<T> where Rect_<T>: BitAndAssign {
}
}
-impl<P: ValidPointType, R: AddAssign<P>> AddAssign<Point_<P>> for Rect_<R> {
+impl<P, R: AddAssign<P>> AddAssign<Point_<P>> for Rect_<R> {
fn add_assign(&mut self, rhs: Point_<P>) {
self.x += rhs.x;
self.y += rhs.y;
}
}
-impl<P: ValidPointType, R: SubAssign<P>> SubAssign<Point_<P>> for Rect_<R> {
+impl<P, R: SubAssign<P>> SubAssign<Point_<P>> for Rect_<R> {
fn sub_assign(&mut self, rhs: Point_<P>) {
self.x -= rhs.x;
self.y -= rhs.y;

MODIFY
src/manual/core/size.rs
src/manual/core/size.rs
@@ -3,7 +3,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use num_traits::{NumCast, ToPrimitive};
use crate::{
- core::{Point_, ValidPointType},
+ core::Point_,
opencv_type_simple_generic,
};
@@ -24,7 +24,7 @@ impl<T: ValidSizeType> Size_<T> {
}
#[inline]
- pub fn from_point(pt: Point_<T>) -> Self where T: ValidPointType {
+ pub fn from_point(pt: Point_<T>) -> Self {
Self { width: pt.x, height: pt.y }
}

Drop ValidPointType requirement