1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libcola - A library providing force-directed network layout using the
5  *           stress-majorization method subject to separation constraints.
6  *
7  * Copyright (C) 2014  Monash University
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  * See the file LICENSE.LGPL distributed with the library.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18  *
19  * Author(s):  Michael Wybrow
20  *
21 */
22 
23 #ifndef LIBCOLA_BOX_H
24 #define LIBCOLA_BOX_H
25 
26 #include <cstdio>
27 
28 #include "libvpsc/rectangle.h"
29 
30 
31 namespace cola {
32 
33 /**
34  * @brief A box consisting of four edge values for representing padding or
35  *        margins for rectangles.
36  */
37 class Box
38 {
39     public:
40         /**
41          * @brief Constructs a padding or margin box consisting of a value for
42          *        each edge.
43          *
44          * Values should be nonnegative.
45          *
46          * @param[in] xMin  Minimum horizontal value.
47          * @param[in] xMax  Maximum horizontal value.
48          * @param[in] yMin  Minimum vertical value.
49          * @param[in] yMax  Maximum vertical value.
50          */
51         Box(double xMin, double xMax, double yMin, double yMax);
52         /**
53          * @brief Constructs a padding or margin box consisting of a value for
54          *        each edge.
55          *
56          * Values should be nonnegative.
57          *
58          * @param[in] all   The value to be used for all four edges.
59          */
60         Box(double all);
61         /**
62          * @brief Constructs an empty padding or margin box.
63          */
64         Box();
65         ~Box();
66 
67         bool empty(void) const;
68         double min(size_t dim) const;
69         double max(size_t dim) const;
70         void outputCode(FILE *fp) const;
71         vpsc::Rectangle rectangleByApplyingBox(
72                 const vpsc::Rectangle rectangle) const;
73 
74    private:
75         static double nonNegative(double value);
76 
77         double m_min[2];
78         double m_max[2];
79 };
80 
81 } // namespace cola
82 #endif
83