~corrado-maurini/dolfin/tao

« back to all changes in this revision

Viewing changes to dolfin/generation/CSGPrimitives2D.cpp

  • Committer: corrado maurini
  • Date: 2012-12-18 12:16:08 UTC
  • mfrom: (6685.78.207 trunk)
  • Revision ID: corrado.maurini@upmc.fr-20121218121608-nk82ly9jgsld9u84
updating with trunk, fix uint in TAO solver and hacking the check for tao FindTAO.cmake

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2012 Anders Logg
 
2
//
 
3
// This file is part of DOLFIN.
 
4
//
 
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.
 
9
//
 
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.
 
14
//
 
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/>.
 
17
//
 
18
// Modified by Johannes Ring, 2012
 
19
// Modified by Benjamin Kehlet, 2012
 
20
//
 
21
// First added:  2012-04-12
 
22
// Last changed: 2012-11-12
 
23
 
 
24
#include <sstream>
 
25
#include <dolfin/math/basic.h>
 
26
 
 
27
#include "CSGPrimitives2D.h"
 
28
 
 
29
using namespace dolfin;
 
30
 
 
31
//-----------------------------------------------------------------------------
 
32
// Circle
 
33
//-----------------------------------------------------------------------------
 
34
Circle::Circle(double x0, double x1, double r, std::size_t fragments)
 
35
  : _x0(x0), _x1(x1), _r(r), _fragments(fragments)
 
36
{
 
37
  if (_r < DOLFIN_EPS)
 
38
  {
 
39
    dolfin_error("CSGPrimitives2D.cpp",
 
40
                 "create circle",
 
41
                 "Circle with center (%f, %f) has zero or negative radius",
 
42
                 _x0, _x1);
 
43
  }
 
44
  if (_fragments < 3)
 
45
  {
 
46
    dolfin_error("CSGPrimitives2D.cpp",
 
47
                 "create circle",
 
48
                 "Unable to create circle with less than 3 fragments");
 
49
 
 
50
  }
 
51
}
 
52
//-----------------------------------------------------------------------------
 
53
std::string Circle::str(bool verbose) const
 
54
{
 
55
  std::stringstream s;
 
56
 
 
57
  if (verbose)
 
58
  {
 
59
    s << "<Circle at (" << _x0 << ", " << _x1 << ") with radius " << _r << ">";
 
60
  }
 
61
  else
 
62
  {
 
63
    s << "Circle("
 
64
      << _x0 << ", " << _x1 << ", " << _r << ")";
 
65
  }
 
66
 
 
67
  return s.str();
 
68
}
 
69
//-----------------------------------------------------------------------------
 
70
// Ellipse
 
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)
 
74
{
 
75
  if (_a < DOLFIN_EPS || _b < DOLFIN_EPS)
 
76
  {
 
77
    dolfin_error("CSGPrimitives2D.cpp",
 
78
                 "create ellipse",
 
79
                 "Ellipse with center (%f, %f) has invalid semi-axis",
 
80
                 _x0, _x1);
 
81
  }
 
82
  if (_fragments < 3)
 
83
  {
 
84
    dolfin_error("CSGPrimitives2D.cpp",
 
85
                 "create ellipse",
 
86
                 "Unable to create ellipse with less than 3 fragments");
 
87
 
 
88
  }
 
89
}
 
90
//-----------------------------------------------------------------------------
 
91
std::string Ellipse::str(bool verbose) const
 
92
{
 
93
  std::stringstream s;
 
94
 
 
95
  if (verbose)
 
96
  {
 
97
    s << "<Ellipse at (" << _x0 << ", " << _x1 << ") with horizontal semi-axis "
 
98
      << _a << " and vertical semi-axis " << _b << ">";
 
99
  }
 
100
  else
 
101
  {
 
102
    s << "Ellipse("
 
103
      << _x0 << ", " << _x1 << ", " << _a << ", " << _b << ")";
 
104
  }
 
105
 
 
106
  return s.str();
 
107
}
 
108
//-----------------------------------------------------------------------------
 
109
// Rectangle
 
110
//-----------------------------------------------------------------------------
 
111
Rectangle::Rectangle(double x0, double x1, double y0, double y1)
 
112
  : _x0(x0), _x1(x1), _y0(y0), _y1(y1)
 
113
{
 
114
  if (near(x0, y0) || near(x1, y1))
 
115
  {
 
116
    dolfin_error("CSGPrimitives2D.cpp",
 
117
                 "create rectangle",
 
118
                 "Rectangle with corner (%f, %f) and (%f, %f) degenerated",
 
119
                 x0, x1, y0, y1);
 
120
  }
 
121
}
 
122
//-----------------------------------------------------------------------------
 
123
std::string Rectangle::str(bool verbose) const
 
124
{
 
125
  std::stringstream s;
 
126
 
 
127
  if (verbose)
 
128
  {
 
129
    s << "<Rectangle with first corner at (" << _x0 << ", " << _x1 << ") "
 
130
      << "and second corner at (" << _y0 << ", " << _y1 << ")>";
 
131
  }
 
132
  else
 
133
  {
 
134
    s << "Rectangle("
 
135
      << _x0 << ", " << _x1 << ", " << _y0 << ", " << _y1 << ")";
 
136
  }
 
137
 
 
138
  return s.str();
 
139
}
 
140
//-----------------------------------------------------------------------------
 
141
// Polygon
 
142
//-----------------------------------------------------------------------------
 
143
Polygon::Polygon(const std::vector<Point>& vertices)
 
144
  : _vertices(vertices)
 
145
{
 
146
  if (_vertices.size() < 3)
 
147
  {
 
148
    dolfin_error("CSGPrimitives2D.cpp",
 
149
                 "create polygon",
 
150
                 "Polygon should have at least three vertices");
 
151
  }
 
152
}
 
153
//-----------------------------------------------------------------------------
 
154
std::string Polygon::str(bool verbose) const
 
155
{
 
156
  std::stringstream s;
 
157
 
 
158
  if (verbose)
 
159
  {
 
160
    s << "<Polygon with vertices ";
 
161
    std::vector<Point>::const_iterator p;
 
162
    for (p = _vertices.begin(); p != _vertices.end(); ++p)
 
163
    {
 
164
      s << "(" << p->x() << ", " << p->y() << ")";
 
165
      if ((p != _vertices.end()) && (p + 1 != _vertices.end()))
 
166
        s << ", ";
 
167
    }
 
168
    s << ">";
 
169
  }
 
170
  else
 
171
  {
 
172
    s << "Polygon(";
 
173
    std::vector<Point>::const_iterator p;
 
174
    for (p = _vertices.begin(); p != _vertices.end(); ++p)
 
175
    {
 
176
      s << "(" << p->x() << ", " << p->y() << ")";
 
177
      if ((p != _vertices.end()) && (p + 1 != _vertices.end()))
 
178
        s << ", ";
 
179
    }
 
180
    s << ")";
 
181
  }
 
182
 
 
183
  return s.str();
 
184
}
 
185
//-----------------------------------------------------------------------------