open_dis_rust/common/
linear_acceleration.rs

1//     open-dis-rust - Rust implementation of the IEEE-1278.1 Distributed Interactive Simulation
2//     Copyright (C) 2023 Cameron Howell
3//
4//     Licensed under the BSD-2-Clause License
5
6use bytes::{Buf, BufMut, BytesMut};
7
8#[derive(Copy, Clone, Debug, Default)]
9pub struct LinearAcceleration {
10    pub first_vector_component: f32,
11    pub second_vector_component: f32,
12    pub third_vector_component: f32,
13}
14
15impl LinearAcceleration {
16    #[must_use]
17    pub fn new(x: f32, y: f32, z: f32) -> Self {
18        LinearAcceleration {
19            first_vector_component: x,
20            second_vector_component: y,
21            third_vector_component: z,
22        }
23    }
24
25    pub fn serialize(&self, buf: &mut BytesMut) {
26        buf.put_f32(self.first_vector_component);
27        buf.put_f32(self.second_vector_component);
28        buf.put_f32(self.third_vector_component);
29    }
30
31    pub fn decode(buf: &mut BytesMut) -> LinearAcceleration {
32        LinearAcceleration {
33            first_vector_component: buf.get_f32(),
34            second_vector_component: buf.get_f32(),
35            third_vector_component: buf.get_f32(),
36        }
37    }
38}