~qeef/bcar

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH 1/2] Add parking slot skeleton

Details
Message ID
<20200728102907.16290-1-jiri.vlasak.2@cvut.cz>
DKIM signature
pass
Download raw message
Patch: +40 -0
---
 src/lib.rs   |  3 +++
 src/pslot.rs | 37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
 create mode 100644 src/pslot.rs

diff --git a/src/lib.rs b/src/lib.rs
index dc3cb87..3b018b6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -11,6 +11,9 @@ pub use crate::properties::Size;
mod bcar;
pub use crate::bcar::BCar;

mod pslot;
pub use crate::pslot::PSlot;

#[cfg(test)]
mod tests {
    use super::*;
diff --git a/src/pslot.rs b/src/pslot.rs
new file mode 100644
index 0000000..5f3426d
--- /dev/null
+++ b/src/pslot.rs
@@ -0,0 +1,37 @@
//! Parking slot type and related methods

use crate::geometry::Point;

/// Parking slot structure.
///
///
/// Examples
/// ========
///
/// ```
/// let p1 = bcar::Point::new(0.0, 0.0);
/// let p2 = bcar::Point::new(0.0, -1.0);
/// let p3 = bcar::Point::new(2.0, -1.0);
/// let p4 = bcar::Point::new(2.0, 0.0);
/// let ps = bcar::PSlot::new([p1, p2, p3, p4]);
/// assert_eq!(ps, bcar::PSlot::default());
/// ```
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct PSlot {
    pub border: [Point; 4],
}

impl PSlot {
    pub fn new(border: [Point; 4]) -> PSlot {
        PSlot {border}
    }

    pub fn default() -> PSlot {
        PSlot {border: [
            Point::new(0.0, 0.0),
            Point::new(0.0, -1.0),
            Point::new(2.0, -1.0),
            Point::new(2.0, 0.0),
        ]}
    }
}
-- 
2.20.1

[PATCH 2/2] Refactor constructors

Details
Message ID
<20200728102907.16290-2-jiri.vlasak.2@cvut.cz>
In-Reply-To
<20200728102907.16290-1-jiri.vlasak.2@cvut.cz> (view parent)
DKIM signature
pass
Download raw message
Patch: +29 -14
---
 src/pslot.rs | 43 +++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/pslot.rs b/src/pslot.rs
index 5f3426d..ac02656 100644
--- a/src/pslot.rs
+++ b/src/pslot.rs
@@ -9,12 +9,16 @@ use crate::geometry::Point;
/// ========
///
/// ```
/// let p1 = bcar::Point::new(0.0, 0.0);
/// let p2 = bcar::Point::new(0.0, -1.0);
/// let p3 = bcar::Point::new(2.0, -1.0);
/// let p4 = bcar::Point::new(2.0, 0.0);
/// let ps = bcar::PSlot::new([p1, p2, p3, p4]);
/// assert_eq!(ps, bcar::PSlot::default());
/// let ps = bcar::PSlot::new_phwl(bcar::Point::new(0.0, 0.0), 0.0, 1.0, 2.0);
/// let def_ps = bcar::PSlot::default();
/// assert!(ps.border[0].x - def_ps.border[0].x < 0.00001);
/// assert!(ps.border[0].y - def_ps.border[0].y < 0.00001);
/// assert!(ps.border[1].x - def_ps.border[1].x < 0.00001);
/// assert!(ps.border[1].y - def_ps.border[1].y < 0.00001);
/// assert!(ps.border[2].x - def_ps.border[2].x < 0.00001);
/// assert!(ps.border[2].y - def_ps.border[2].y < 0.00001);
/// assert!(ps.border[3].x - def_ps.border[3].x < 0.00001);
/// assert!(ps.border[3].y - def_ps.border[3].y < 0.00001);
/// ```
#[derive(Copy, Clone, PartialEq, Debug)]
pub struct PSlot {
@@ -22,16 +26,27 @@ pub struct PSlot {
}

impl PSlot {
    pub fn new(border: [Point; 4]) -> PSlot {
        PSlot {border}
    /// Return new parking slot
    ///
    /// Arguments
    /// ---------
    ///
    /// - `p` -- Parking slot first point.
    /// - `h` -- Parking slot heading.
    /// - `w` -- Parking slot width.
    /// - `l` -- Parking slot length
    pub fn new_phwl(p: Point, h: f64, w: f64, l: f64) -> PSlot {
        let pi = std::f64::consts::PI;
        let p2 = Point::new(
            p.x + w*(h - pi/2.0).cos(),
            p.y + w*(h - pi/2.0).sin()
        );
        let p3 = Point::new(p2.x + l*h.cos(), p2.y + l*h.sin());
        let p4 = Point::new(p.x + l*h.cos(), p.y + l*h.sin());
        PSlot {border: [p, p2, p3, p4]}
    }

    pub fn default() -> PSlot {
        PSlot {border: [
            Point::new(0.0, 0.0),
            Point::new(0.0, -1.0),
            Point::new(2.0, -1.0),
            Point::new(2.0, 0.0),
        ]}
        PSlot::new_phwl(Point::default(), 0.0, 1.0, 2.0)
    }
}
-- 
2.20.1
Reply to thread Export thread (mbox)