getter and setter of vector

This commit is contained in:
shenjack 2023-03-28 23:36:15 +08:00
parent f45c4ffa7e
commit e9307dc1a3
2 changed files with 65 additions and 1 deletions

View File

@ -38,11 +38,21 @@ cd src
## roadmap
- [ ] `pyglet.sprite.Sprite` patch (doing)
- [ ] `pyglet.sprite.Sprite` patch
- [ ] `pyglet.math.Vec2` patch (doing)
- [ ] main Calculate protocol
- [ ] other protocols
- [ ] `pyglet.math.Vec3` patch (doing)
- [ ] main Calculate protocol
- [ ] other protocols
- [ ] `pyglet.math.Vec4` patch (doing)
- [ ] main Calculate protocol
- [ ] other protocols
- [ ] `pyglet.math.Mat3(tuple)` patch (doing)
- [ ] main Calculate protocol
- [ ] other protocols
- [ ] `pyglet.math.Mat4(tuple)` patch (doing)
- [ ] main Calculate protocol
- [ ] other protocols

View File

@ -98,6 +98,28 @@ pub mod python_class {
fn __repr__(&self) -> String {
return format!("Vector2_rs({}, {})", self.data.x, self.data.y);
}
// gettter and setter
#[getter]
fn get_x(&self) -> f64 {
return self.data.x;
}
#[getter]
fn get_y(&self) -> f64 {
return self.data.y;
}
#[setter]
fn set_x(&mut self, x: f64) {
self.data.x = x;
}
#[setter]
fn set_y(&mut self, y: f64) {
self.data.y = y;
}
}
#[pymethods]
@ -145,6 +167,38 @@ pub mod python_class {
self.data.x, self.data.y, self.data.z
);
}
// 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;
}
#[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;
}
}
#[pymethods]