LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
size_2d.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_GEOM_SIZE2D_H
33#define RCSC_GEOM_SIZE2D_H
34
35#include <ostream>
36#include <cmath>
37
38namespace rcsc {
39
44class Size2D {
45private:
47 double M_length;
48
50 double M_width;
51
52public:
53
58 : M_length( 0.0 ),
59 M_width( 0.0 )
60 { }
61
67 Size2D( const double length,
68 const double width )
69 : M_length( std::fabs( length ) ),
70 M_width( std::fabs( width ) )
71 { }
72
79 const Size2D & assign( const double length,
80 const double width )
81 {
82 M_length = std::fabs( length );
83 M_width = std::fabs( width );
84 return *this;
85 }
86
92 const Size2D & setLength( const double length )
93 {
94 M_length = std::fabs( length );
95 return *this;
96 }
97
103 const Size2D & setWidth( const double width )
104 {
105 M_width = std::fabs( width );
106 return *this;
107 }
108
113 double length() const
114 {
115 return M_length;
116 }
117
122 double width() const
123 {
124 return M_width;
125 }
126
131 double diagonal() const
132 {
133 return std::sqrt( length() * length()
134 + width() * width() );
135 }
136
142 std::ostream & print( std::ostream & os ) const
143 {
144 os << "(" << length() << ", " << width() << ")";
145 return os;
146 }
147
148};
149
150} // end of namespace
151
152#endif
2D size definition class
Definition: size_2d.h:44
const Size2D & assign(const double length, const double width)
assign new range directly.
Definition: size_2d.h:79
double length() const
get the value of X range
Definition: size_2d.h:113
const Size2D & setWidth(const double width)
set new Y range
Definition: size_2d.h:103
Size2D()
default constructor.
Definition: size_2d.h:57
std::ostream & print(std::ostream &os) const
output values to stream.
Definition: size_2d.h:142
double diagonal() const
get the length of diagonal line
Definition: size_2d.h:131
double width() const
get the value of Y range
Definition: size_2d.h:122
Size2D(const double length, const double width)
constructor with variables
Definition: size_2d.h:67
const Size2D & setLength(const double length)
set new X range
Definition: size_2d.h:92