open_dis_rust/common/world_coordinate.rs
1// open-dis-rust - Rust implementation of the IEEE 1278.1-2012 Distributed Interactive
2// Simulation (DIS) application protocol
3// Copyright (C) 2023 Cameron Howell
4//
5// Licensed under the BSD 2-Clause License
6
7use bytes::{Buf, BufMut, BytesMut};
8
9#[derive(Copy, Clone, Debug, Default)]
10/// Implemented according to IEEE 1278.1-2012 §6.2.98
11pub struct WorldCoordinate {
12 /// The coordinate value along the X-axis which passes through the prime meridian at the equator
13 pub x_coordinate: f64,
14 /// The coordinate value along the Y-axis which passes through 90°E longitude at the equator
15 pub y_coordinate: f64,
16 /// The coordinate value along the Z-axis which passes through the North Pole
17 pub z_coordinate: f64,
18}
19
20impl WorldCoordinate {
21 /// Create a new `WorldCoordinate`
22 ///
23 /// # Examples
24 ///
25 /// Instantiating a new `WorldCoordinate`:
26 /// ```
27 /// use open_dis_rust::common::world_coordinate::WorldCoordinate;
28 /// let mut world_coordinate = WorldCoordinate::default();
29 /// ```
30 ///
31 #[must_use]
32 pub fn new(x: f64, y: f64, z: f64) -> Self {
33 WorldCoordinate {
34 x_coordinate: x,
35 y_coordinate: y,
36 z_coordinate: z,
37 }
38 }
39
40 pub fn serialize(&self, buf: &mut BytesMut) {
41 buf.put_f64(self.x_coordinate);
42 buf.put_f64(self.y_coordinate);
43 buf.put_f64(self.z_coordinate);
44 }
45
46 pub fn decode(buf: &mut BytesMut) -> WorldCoordinate {
47 WorldCoordinate {
48 x_coordinate: buf.get_f64(),
49 y_coordinate: buf.get_f64(),
50 z_coordinate: buf.get_f64(),
51 }
52 }
53}