Add from/to_vec method for Point_ and Point3_
MODIFY
src/manual/core/point.rs
src/manual/core/point.rs
@@ -2,7 +2,7 @@ use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use num::{NumCast, ToPrimitive};
-use crate::core::{Rect_, Size_, ValidRectType, ValidSizeType};
+use crate::core::{Rect_, Size_, ValidRectType, ValidSizeType, ValidVecType, Vec2};
valid_types!(ValidPointType, i32, i64, f32, f64);
@@ -20,6 +20,11 @@ impl<T: ValidPointType> Point_<T> {
Self { x, y }
}
+ #[inline]
+ pub fn from_vec2(vec: Vec2<T>) -> Self where T: ValidVecType {
+ Self::new(vec[0], vec[1])
+ }
+
#[inline]
pub fn from_size(sz: Size_<T>) -> Self where T: ValidSizeType {
Self::new(sz.width, sz.height)
@@ -64,6 +69,11 @@ impl<T: ValidPointType> Point_<T> {
pub fn to<D: ValidPointType + 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) -> Vec2<T> where T: ValidVecType {
+ Vec2::from([self.x, self.y])
+ }
}
impl<T> Add for Point_<T>

MODIFY
src/manual/core/point3.rs
src/manual/core/point3.rs
@@ -68,6 +68,11 @@ impl<T: ValidPoint3Type> Point3_<T> {
pub fn to<D: ValidPoint3Type + 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) -> Vec3<T> where T: ValidVecType {
+ Vec3::from([self.x, self.y, self.z])
+ }
}
impl<T> Add for Point3_<T>

MODIFY
tests/point.rs
tests/point.rs
-use opencv::core::{Point, Point2d, Point2f, Point2l, Size2l, Point2i};
+use opencv::core::{Point, Point2d, Point2f, Point2i, Point2l, Size2l, Vec2d};
#[test]
fn point_add() {
@@ -99,4 +99,7 @@ fn point_conv() {
assert_eq!(Point2f::new(1.2, 2.3), ptf.to::<f32>().unwrap());
let pti = Point2i::new(1, 2);
assert_eq!(Point2f::new(1., 2.), pti.to::<f32>().unwrap());
+
+ let vec = Vec2d::from([10., 20.]);
+ assert_eq!(vec, Point2d::from_vec2(vec).to_vec2());
}

MODIFY
tests/point3.rs
tests/point3.rs
-use opencv::core::{Point2d, Point3d, Point3f, Point3i};
+use opencv::core::{Point2d, Point3d, Point3f, Point3i, Vec3d};
#[test]
fn point3_add() {
@@ -100,4 +100,7 @@ fn point3_conv() {
assert_eq!(Point3f::new(1.2, 2.3, 3.4), ptf.to::<f32>().unwrap());
let pti = Point3i::new(1, 2, 3);
assert_eq!(Point3f::new(1., 2., 3.), pti.to::<f32>().unwrap());
+
+ let vec = Vec3d::from([10., 20., 30.]);
+ assert_eq!(vec, Point3d::from_vec3(vec).to_vec3());
}

Add from/to_vec method for Point_ and Point3_