1
// Copyright (C) 2012 Anders Logg
3
// This file is part of DOLFIN.
5
// DOLFIN 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.
10
// DOLFIN 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.
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
18
// Modified by Johannes Ring, 2012
19
// Modified by Benjamin Kehlet, 2012
21
// First added: 2012-04-12
22
// Last changed: 2012-11-12
25
#include <dolfin/math/basic.h>
27
#include "CSGPrimitives2D.h"
29
using namespace dolfin;
31
//-----------------------------------------------------------------------------
33
//-----------------------------------------------------------------------------
34
Circle::Circle(double x0, double x1, double r, std::size_t fragments)
35
: _x0(x0), _x1(x1), _r(r), _fragments(fragments)
39
dolfin_error("CSGPrimitives2D.cpp",
41
"Circle with center (%f, %f) has zero or negative radius",
46
dolfin_error("CSGPrimitives2D.cpp",
48
"Unable to create circle with less than 3 fragments");
52
//-----------------------------------------------------------------------------
53
std::string Circle::str(bool verbose) const
59
s << "<Circle at (" << _x0 << ", " << _x1 << ") with radius " << _r << ">";
64
<< _x0 << ", " << _x1 << ", " << _r << ")";
69
//-----------------------------------------------------------------------------
71
//-----------------------------------------------------------------------------
72
Ellipse::Ellipse(double x0, double x1, double a, double b, std::size_t fragments)
73
: _x0(x0), _x1(x1), _a(a), _b(b), _fragments(fragments)
75
if (_a < DOLFIN_EPS || _b < DOLFIN_EPS)
77
dolfin_error("CSGPrimitives2D.cpp",
79
"Ellipse with center (%f, %f) has invalid semi-axis",
84
dolfin_error("CSGPrimitives2D.cpp",
86
"Unable to create ellipse with less than 3 fragments");
90
//-----------------------------------------------------------------------------
91
std::string Ellipse::str(bool verbose) const
97
s << "<Ellipse at (" << _x0 << ", " << _x1 << ") with horizontal semi-axis "
98
<< _a << " and vertical semi-axis " << _b << ">";
103
<< _x0 << ", " << _x1 << ", " << _a << ", " << _b << ")";
108
//-----------------------------------------------------------------------------
110
//-----------------------------------------------------------------------------
111
Rectangle::Rectangle(double x0, double x1, double y0, double y1)
112
: _x0(x0), _x1(x1), _y0(y0), _y1(y1)
114
if (near(x0, y0) || near(x1, y1))
116
dolfin_error("CSGPrimitives2D.cpp",
118
"Rectangle with corner (%f, %f) and (%f, %f) degenerated",
122
//-----------------------------------------------------------------------------
123
std::string Rectangle::str(bool verbose) const
129
s << "<Rectangle with first corner at (" << _x0 << ", " << _x1 << ") "
130
<< "and second corner at (" << _y0 << ", " << _y1 << ")>";
135
<< _x0 << ", " << _x1 << ", " << _y0 << ", " << _y1 << ")";
140
//-----------------------------------------------------------------------------
142
//-----------------------------------------------------------------------------
143
Polygon::Polygon(const std::vector<Point>& vertices)
144
: _vertices(vertices)
146
if (_vertices.size() < 3)
148
dolfin_error("CSGPrimitives2D.cpp",
150
"Polygon should have at least three vertices");
153
//-----------------------------------------------------------------------------
154
std::string Polygon::str(bool verbose) const
160
s << "<Polygon with vertices ";
161
std::vector<Point>::const_iterator p;
162
for (p = _vertices.begin(); p != _vertices.end(); ++p)
164
s << "(" << p->x() << ", " << p->y() << ")";
165
if ((p != _vertices.end()) && (p + 1 != _vertices.end()))
173
std::vector<Point>::const_iterator p;
174
for (p = _vertices.begin(); p != _vertices.end(); ++p)
176
s << "(" << p->x() << ", " << p->y() << ")";
177
if ((p != _vertices.end()) && (p + 1 != _vertices.end()))
185
//-----------------------------------------------------------------------------