some more test
This commit is contained in:
parent
e9307dc1a3
commit
035ad7bf3e
@ -11,20 +11,20 @@ pub mod macros {}
|
||||
pub mod vector {
|
||||
use std::ops::{Add, Div, Mul, Sub};
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialOrd)]
|
||||
pub struct Vector2 {
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialOrd)]
|
||||
pub struct Vector3 {
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
pub z: f64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
|
||||
#[derive(Debug, Clone, Copy, PartialOrd)]
|
||||
pub struct Vector4 {
|
||||
pub x: f64,
|
||||
pub y: f64,
|
||||
@ -73,6 +73,12 @@ pub mod vector {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Vector2 {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.x == other.x && self.y == other.y
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Vector3 {
|
||||
type Output = Self;
|
||||
|
||||
@ -105,6 +111,12 @@ pub mod vector {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Vector3 {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.x == other.x && self.y == other.y && self.z == other.z
|
||||
}
|
||||
}
|
||||
|
||||
impl Add for Vector4 {
|
||||
type Output = Self;
|
||||
|
||||
@ -157,6 +169,12 @@ pub mod vector {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for Vector4 {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.x == other.x && self.y == other.y && self.z == other.z && self.w == other.w
|
||||
}
|
||||
}
|
||||
|
||||
impl VectorTrait for Vector2 {
|
||||
fn len(&self) -> i8 {
|
||||
return 2;
|
||||
|
@ -95,11 +95,15 @@ pub mod python_class {
|
||||
};
|
||||
}
|
||||
|
||||
fn __eq__(&self, other: &Self) -> bool {
|
||||
return self.data == other.data;
|
||||
}
|
||||
|
||||
fn __repr__(&self) -> String {
|
||||
return format!("Vector2_rs({}, {})", self.data.x, self.data.y);
|
||||
}
|
||||
|
||||
// gettter and setter
|
||||
// getter and setter
|
||||
|
||||
#[getter]
|
||||
fn get_x(&self) -> f64 {
|
||||
@ -161,6 +165,10 @@ pub mod python_class {
|
||||
};
|
||||
}
|
||||
|
||||
fn __eq__(&self, other: &Self) -> bool {
|
||||
return self.data == other.data;
|
||||
}
|
||||
|
||||
fn __repr__(&self) -> String {
|
||||
return format!(
|
||||
"Vector3_rs({}, {}, {})",
|
||||
@ -240,11 +248,57 @@ pub mod python_class {
|
||||
};
|
||||
}
|
||||
|
||||
fn __eq__(&self, other: &Self) -> bool {
|
||||
return self.data == other.data;
|
||||
}
|
||||
|
||||
fn __repr__(&self) -> String {
|
||||
return format!(
|
||||
"Vector4_rs({}, {}, {}, {})",
|
||||
self.data.x, self.data.y, self.data.z, self.data.w
|
||||
);
|
||||
}
|
||||
|
||||
// getter and setter
|
||||
|
||||
#[getter]
|
||||
fn get_x(&self) -> f64 {
|
||||
return self.data.x;
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn get_y(&self) -> f64 {
|
||||
return self.data.y;
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn get_z(&self) -> f64 {
|
||||
return self.data.z;
|
||||
}
|
||||
|
||||
#[getter]
|
||||
fn get_w(&self) -> f64 {
|
||||
return self.data.w;
|
||||
}
|
||||
|
||||
#[setter]
|
||||
fn set_x(&mut self, x: f64) {
|
||||
self.data.x = x;
|
||||
}
|
||||
|
||||
#[setter]
|
||||
fn set_y(&mut self, y: f64) {
|
||||
self.data.y = y;
|
||||
}
|
||||
|
||||
#[setter]
|
||||
fn set_z(&mut self, z: f64) {
|
||||
self.data.z = z;
|
||||
}
|
||||
|
||||
#[setter]
|
||||
fn set_w(&mut self, w: f64) {
|
||||
self.data.w = w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,6 +48,8 @@ class TestVector(unittest.TestCase):
|
||||
print(f"{vec3=} {vec3_1=}")
|
||||
print(f"{vec4=} {vec4_1=}")
|
||||
|
||||
self.assertEqual(vec2 + vec2_1, Vector2_rs(vec2.x + vec2_1.x, vec2.y + vec2_1.y))
|
||||
|
||||
print(f"{vec2 + vec2_1=}")
|
||||
print(f"{vec3 + vec3_1=}")
|
||||
print(f"{vec4 + vec4_1=}")
|
||||
|
Loading…
Reference in New Issue
Block a user