isogeometric_analysis/core/
size.rs

1/*
2 * Project: Approximation and Finite Elements in Isogeometric Problems
3 * Author:  Luca Carlon
4 * Date:    2021.11.01
5 *
6 * Copyright (c) 2021 Luca Carlon. All rights reserved.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 3 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Lesser General Public License for more details.
17 * 
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 */
22
23///
24/// Size represents a size with width and height.
25///
26#[derive(Debug)]
27pub struct Size {
28    pub width: usize,
29    pub height: usize
30}
31
32impl Size {
33    ///
34    /// Determines if width or height or both are zero.
35    /// 
36    pub fn is_empty(&self) -> bool {
37        if self.width <= 0 || self.height <= 0 { true } else { false }
38    }
39}
40
41impl PartialEq for Size {
42    fn eq(&self, other: &Self) -> bool {
43        self.width == other.width && self.height == other.height
44    }
45}
46
47#[cfg(test)]
48mod tests {
49    use crate::core::Size;
50
51    #[test]
52    fn test_empty() {
53        assert_eq!(Size {
54            width: 0,
55            height: 0
56        }.is_empty(), true);
57    }
58
59    #[test]
60    fn test_equality() {
61        assert_eq!(Size {
62            width: 10,
63            height: 20
64        }, Size {
65            width: 10,
66            height: 20
67        });
68
69        assert_ne!(Size {
70            width: 10,
71            height: 20
72        }, Size {
73            width: 11,
74            height: 20
75        });
76    }
77}