mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 10:14:06 +02:00
cleanup sendprop array/vector comparisons
This commit is contained in:
parent
9d38663c79
commit
dfd0b8ae90
2 changed files with 64 additions and 18 deletions
|
|
@ -604,27 +604,17 @@ impl PartialEq for SendPropValue {
|
||||||
(SendPropValue::VectorXY(value1), SendPropValue::Vector(value2)) => {
|
(SendPropValue::VectorXY(value1), SendPropValue::Vector(value2)) => {
|
||||||
value1.x == value2.x && value1.y == value2.y && value2.z == 0.0
|
value1.x == value2.x && value1.y == value2.y && value2.z == 0.0
|
||||||
}
|
}
|
||||||
(SendPropValue::Vector(value1), SendPropValue::Array(value2)) if value2.len() == 3 => {
|
(SendPropValue::Vector(value1), SendPropValue::Array(value2)) => {
|
||||||
SendPropValue::Float(value1.x) == value2[0]
|
value1 == value2.as_slice()
|
||||||
&& SendPropValue::Float(value1.y) == value2[1]
|
|
||||||
&& SendPropValue::Float(value1.z) == value2[2]
|
|
||||||
}
|
}
|
||||||
(SendPropValue::Array(value1), SendPropValue::Vector(value2)) if value1.len() == 3 => {
|
(SendPropValue::Array(value1), SendPropValue::Vector(value2)) => {
|
||||||
SendPropValue::Float(value2.x) == value1[0]
|
value2 == value1.as_slice()
|
||||||
&& SendPropValue::Float(value2.y) == value1[1]
|
|
||||||
&& SendPropValue::Float(value2.z) == value1[2]
|
|
||||||
}
|
}
|
||||||
(SendPropValue::VectorXY(value1), SendPropValue::Array(value2))
|
(SendPropValue::VectorXY(value1), SendPropValue::Array(value2)) => {
|
||||||
if value2.len() == 2 =>
|
value1 == value2.as_slice()
|
||||||
{
|
|
||||||
SendPropValue::Float(value1.x) == value2[0]
|
|
||||||
&& SendPropValue::Float(value1.y) == value2[1]
|
|
||||||
}
|
}
|
||||||
(SendPropValue::Array(value1), SendPropValue::VectorXY(value2))
|
(SendPropValue::Array(value1), SendPropValue::VectorXY(value2)) => {
|
||||||
if value1.len() == 2 =>
|
value2 == value1.as_slice()
|
||||||
{
|
|
||||||
SendPropValue::Float(value2.x) == value1[0]
|
|
||||||
&& SendPropValue::Float(value2.y) == value1[1]
|
|
||||||
}
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::demo::sendprop::SendPropValue;
|
||||||
use bitbuffer::{BitRead, BitWrite};
|
use bitbuffer::{BitRead, BitWrite};
|
||||||
use parse_display::Display;
|
use parse_display::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
@ -24,6 +25,39 @@ impl PartialEq for Vector {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq<[SendPropValue]> for Vector {
|
||||||
|
fn eq(&self, other: &[SendPropValue]) -> bool {
|
||||||
|
match other {
|
||||||
|
&[SendPropValue::Float(x), SendPropValue::Float(y), SendPropValue::Float(z)] => {
|
||||||
|
self.x == x && self.y == y && self.z == z
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_vec_array_eq() {
|
||||||
|
assert!(!Vector {
|
||||||
|
x: 1.0,
|
||||||
|
y: 2.0,
|
||||||
|
z: 3.0,
|
||||||
|
}
|
||||||
|
.eq([SendPropValue::Float(1.0), SendPropValue::Float(2.0)].as_slice()));
|
||||||
|
|
||||||
|
assert!(Vector {
|
||||||
|
x: 1.0,
|
||||||
|
y: 2.0,
|
||||||
|
z: 3.0,
|
||||||
|
}
|
||||||
|
.eq([
|
||||||
|
SendPropValue::Float(1.0),
|
||||||
|
SendPropValue::Float(2.0),
|
||||||
|
SendPropValue::Float(3.0),
|
||||||
|
]
|
||||||
|
.as_slice()));
|
||||||
|
}
|
||||||
|
|
||||||
impl Add for Vector {
|
impl Add for Vector {
|
||||||
type Output = Vector;
|
type Output = Vector;
|
||||||
|
|
||||||
|
|
@ -62,6 +96,28 @@ impl PartialEq for VectorXY {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PartialEq<[SendPropValue]> for VectorXY {
|
||||||
|
fn eq(&self, other: &[SendPropValue]) -> bool {
|
||||||
|
match other {
|
||||||
|
&[SendPropValue::Float(x), SendPropValue::Float(y)] => self.x == x && self.y == y,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_vec_xy_array_eq() {
|
||||||
|
assert!(VectorXY { x: 1.0, y: 2.0 }
|
||||||
|
.eq([SendPropValue::Float(1.0), SendPropValue::Float(2.0)].as_slice()));
|
||||||
|
|
||||||
|
assert!(!VectorXY { x: 1.0, y: 2.0 }.eq([
|
||||||
|
SendPropValue::Float(1.0),
|
||||||
|
SendPropValue::Float(2.0),
|
||||||
|
SendPropValue::Float(3.0)
|
||||||
|
]
|
||||||
|
.as_slice()));
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Vector> for VectorXY {
|
impl From<Vector> for VectorXY {
|
||||||
fn from(vec: Vector) -> Self {
|
fn from(vec: Vector) -> Self {
|
||||||
VectorXY { x: vec.x, y: vec.y }
|
VectorXY { x: vec.x, y: vec.y }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue