rust_3d/
ray_2d.rs

1/*
2Copyright 2017 Martin Buck
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"),
6to deal in the Software without restriction, including without limitation the
7rights to use, copy, modify, merge, publish, distribute, sublicense,
8and/or sell copies of the Software, and to permit persons to whom the Software
9is furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall
12be included all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
20OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21*/
22
23//! Ray2D, a ray within 2D space
24
25use std::fmt;
26
27use crate::*;
28
29//------------------------------------------------------------------------------
30
31#[derive(Debug, PartialEq, PartialOrd, Ord, Eq, Clone, Hash)]
32/// Ray2D, a ray within 2D space
33pub struct Ray2D {
34    pub line: Line2D,
35}
36
37impl Ray2D {
38    /// Creates a new Ray2D from a Line2D
39    pub fn new(line: Line2D) -> Self {
40        Ray2D { line }
41    }
42}
43
44impl IsMovable2D for Ray2D {
45    fn move_by(&mut self, x: f64, y: f64) {
46        self.line.move_by(x, y);
47    }
48}
49
50impl fmt::Display for Ray2D {
51    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
52        self.line.fmt(f)
53    }
54}