libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNPoint2DDouble.cpp
Go to the documentation of this file.
1 /* Copyright 2008-2016 INSA Lyon, CoReNum, ENS-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNPoint2DDouble.cpp
19  * \author Yann LEYDIER
20  */
21 
23 #include <CRNData/CRNDataFactory.h>
24 #include <CRNException.h>
25 #include <CRNi18n.h>
26 
27 using namespace crn;
28 
39 {
40  if (el.GetName() != "Point2DDouble")
41  {
42  throw ExceptionInvalidArgument(StringUTF8("void Point2DDouble::Deserialize(xml::Element &el): ") +
43  _("Wrong XML element."));
44  }
45 
46  double x = el.GetAttribute<double>("x", false); // may throw
47  double y = el.GetAttribute<double>("y", false); // may throw
48  X = x;
49  Y = y;
50 }
51 
59 {
60  xml::Element el(parent.PushBackElement("Point2DDouble"));
61 
62  el.SetAttribute("x", X);
63  el.SetAttribute("y", Y);
64 
65  return el;
66 }
67 
76 {
77  double cos_theta = theta.Cos();
78  double sin_theta = theta.Sin();
79 
80  return Point2DDouble(X * cos_theta - Y * sin_theta, X * sin_theta + Y * cos_theta);
81 }
82 
84  CRN_DATA_FACTORY_REGISTER(U"Point2DDouble", Point2DDouble)
85  Cloner::Register<Point2DDouble>();
86 CRN_END_CLASS_CONSTRUCTOR(Point2DDouble)
87 
xml::Element Serialize(xml::Element &parent) const
Dumps the object to an XML element. Unsafe.
A 2D point class.
XML element.
Definition: CRNXml.h:135
Point2DDouble MakeRotation(Angle< Radian > theta) const
Rotation for single point.
StringUTF8 GetName() const
Gets the label of the element.
Definition: CRNXml.h:146
#define _(String)
Definition: CRNi18n.h:51
#define CRN_END_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
Definition: CRNObject.h:198
A convenience class for angles units.
#define CRN_DATA_FACTORY_REGISTER(elemname, classname)
Registers a class to the data factory.
double Sin() const noexcept
Computes sine.
void SetAttribute(const StringUTF8 &name, const StringUTF8 &value)
Sets the value of an attribute.
Definition: CRNXml.cpp:595
double Cos() const noexcept
Computes cosine.
T GetAttribute(const StringUTF8 &name, bool silent=true) const
Gets an attribute.
Definition: CRNXml.h:219
A character string class.
Definition: CRNStringUTF8.h:49
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
Definition: CRNXml.cpp:355
void Deserialize(xml::Element &el)
Initializes the object from an XML element. Unsafe.
Invalid argument error (e.g.: nullptr pointer)
Definition: CRNException.h:107
#define CRN_BEGIN_CLASS_CONSTRUCTOR(classname)
Defines a class constructor.
Definition: CRNObject.h:185
Point2DDouble() noexcept
Default constructor.