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

MODIFY
src/manual/core/point3.rs
src/manual/core/point3.rs
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
-use num_traits::{NumCast, ToPrimitive, Zero};
+use num_traits::{NumCast, NumOps, ToPrimitive, Zero};
use crate::{
- core::{Point_, ValidVecType, VecN},
+ core::{ValidVecType, VecN},
opencv_type_simple_generic,
};
-valid_types!(ValidPoint3Type: i32, f32, f64);
-
#[repr(C)]
#[derive(Copy, Clone, Debug, Default, PartialEq, PartialOrd)]
/// [docs.opencv.org](https://docs.opencv.org/master/df/d6c/classcv_1_1Point3__.html)
-pub struct Point3_<T: ValidPoint3Type> {
+pub struct Point3_<T> {
pub x: T,
pub y: T,
pub z: T,
}
-impl<T: ValidPoint3Type> Point3_<T> {
+impl<T> Point3_<T> {
#[inline]
pub fn new(x: T, y: T, z: T) -> Self {
Self { x, y, z }
@@ -26,7 +24,8 @@ impl<T: ValidPoint3Type> Point3_<T> {
#[inline]
pub fn from_vec3(vec: VecN<T, 3>) -> Self where T: ValidVecType {
- Self::new(vec[0], vec[1], vec[2])
+ let [x, y, z] = vec.0;
+ Self::new(x, y, z)
}
#[inline]
@@ -35,7 +34,7 @@ impl<T: ValidPoint3Type> Point3_<T> {
}
#[inline]
- pub fn cross(self, pt: Point3_<T>) -> Point3_<T> {
+ pub fn cross(self, pt: Self) -> Self where T: NumOps + Copy {
Self::new(
self.y * pt.z - self.z * pt.y,
self.z * pt.x - self.x * pt.z,
@@ -44,12 +43,12 @@ impl<T: ValidPoint3Type> Point3_<T> {
}
#[inline]
- pub fn dot(self, pt: Point3_<T>) -> T {
+ pub fn dot(self, pt: Self) -> T where T: NumOps {
self.x * pt.x + self.y * pt.y + self.z * pt.z
}
#[inline]
- pub fn ddot(self, pt: Point3_<T>) -> f64 where f64: From<T> {
+ pub fn ddot(self, pt: Self) -> f64 where f64: From<T> {
let self_x: f64 = From::from(self.x);
let self_y: f64 = From::from(self.y);
let self_z: f64 = From::from(self.z);
@@ -68,46 +67,37 @@ impl<T: ValidPoint3Type> Point3_<T> {
}
#[inline]
- pub fn to<D: ValidPoint3Type + NumCast>(self) -> Option<Point3_<D>> where T: ToPrimitive {
+ pub fn to<D: NumCast>(self) -> Option<Point3_<D>> where T: ToPrimitive {
Some(Point3_::new(D::from(self.x)?, D::from(self.y)?, D::from(self.z)?))
}
#[inline]
- pub fn to_vec3(&self) -> VecN<T, 3> where T: ValidVecType {
+ pub fn to_vec3(self) -> VecN<T, 3> where T: ValidVecType {
VecN::<_, 3>::from([self.x, self.y, self.z])
}
}
-opencv_type_simple_generic! { Point3_<ValidPoint3Type> }
+opencv_type_simple_generic! { Point3_<Copy> }
-impl<T> Add for Point3_<T>
- where
- T: ValidPoint3Type + AddAssign,
-{
- type Output = Point3_<T>;
+impl<T> Add for Point3_<T> where Self: AddAssign {
+ type Output = Self;
- fn add(mut self, rhs: Point3_<T>) -> Self::Output {
+ fn add(mut self, rhs: Self) -> Self::Output {
self += rhs;
self
}
}
-impl<T> Sub for Point3_<T>
- where
- T: ValidPoint3Type + SubAssign,
-{
- type Output = Point3_<T>;
+impl<T> Sub for Point3_<T> where Self: SubAssign {
+ type Output = Self;
- fn sub(mut self, rhs: Point3_<T>) -> Self::Output {
+ fn sub(mut self, rhs: Self) -> Self::Output {
self -= rhs;
self
}
}
-impl<T> Mul<T> for Point3_<T>
- where
- T: ValidPoint3Type + MulAssign
-{
- type Output = Point3_<T>;
+impl<T> Mul<T> for Point3_<T> where Self: MulAssign<T> {
+ type Output = Self;
fn mul(mut self, rhs: T) -> Self::Output {
self *= rhs;
@@ -115,11 +105,8 @@ impl<T> Mul<T> for Point3_<T>
}
}
-impl<T> Div<T> for Point3_<T>
- where
- T: ValidPoint3Type + DivAssign
-{
- type Output = Point3_<T>;
+impl<T> Div<T> for Point3_<T> where Self: DivAssign<T> {
+ type Output = Self;
fn div(mut self, rhs: T) -> Self::Output {
self /= rhs;
@@ -127,10 +114,7 @@ impl<T> Div<T> for Point3_<T>
}
}
-impl<T> AddAssign for Point3_<T>
- where
- T: ValidPoint3Type + AddAssign,
-{
+impl<T: AddAssign> AddAssign for Point3_<T> {
fn add_assign(&mut self, rhs: Point3_<T>) {
self.x += rhs.x;
self.y += rhs.y;
@@ -138,10 +122,7 @@ impl<T> AddAssign for Point3_<T>
}
}
-impl<T> SubAssign for Point3_<T>
- where
- T: ValidPoint3Type + SubAssign,
-{
+impl<T: SubAssign> SubAssign for Point3_<T> {
fn sub_assign(&mut self, rhs: Point3_<T>) {
self.x -= rhs.x;
self.y -= rhs.y;
@@ -149,10 +130,7 @@ impl<T> SubAssign for Point3_<T>
}
}
-impl<T> MulAssign<T> for Point3_<T>
- where
- T: ValidPoint3Type + MulAssign
-{
+impl<T: MulAssign + Copy> MulAssign<T> for Point3_<T> {
fn mul_assign(&mut self, rhs: T) {
self.x *= rhs;
self.y *= rhs;
@@ -160,10 +138,7 @@ impl<T> MulAssign<T> for Point3_<T>
}
}
-impl<T> DivAssign<T> for Point3_<T>
- where
- T: ValidPoint3Type + DivAssign
-{
+impl<T: DivAssign + Copy> DivAssign<T> for Point3_<T> {
fn div_assign(&mut self, rhs: T) {
self.x /= rhs;
self.y /= rhs;

Drop ValidPoint3Type requirement