Line data Source code
1 : /*
2 : * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Sebastian Reiter
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #ifndef __H__UG__shapes_impl__
34 : #define __H__UG__shapes_impl__
35 :
36 : #include "shapes.h"
37 :
38 : namespace ug{
39 :
40 : template <class vector_t>
41 : bool Sphere<vector_t>::contains_point(const vector_t& p) const
42 : {
43 : return VecDistanceSq(center, p) <= sq(radius);
44 : }
45 :
46 : template <class vector_t>
47 : bool Sphere<vector_t>::intersects(const Sphere& sphere) const
48 : {
49 : return VecDistanceSq(center, sphere.center)
50 : <= sq(radius + sphere.radius);
51 : }
52 :
53 :
54 :
55 : template <class vector_t>
56 : AABox<vector_t>::AABox(const vector_t* points, size_t numPoints)
57 : {
58 : if(numPoints < 1){
59 : VecSet(min, 0);
60 : VecSet(max, 0);
61 : return;
62 : }
63 :
64 : min = max = points[0];
65 :
66 : for(size_t i = 1; i < numPoints; ++i){
67 : const vector_t& p = points[i];
68 : for(size_t j = 0; j < vector_t::Size; ++j){
69 : min[j] = std::min(min[j], p[j]);
70 : max[j] = std::max(max[j], p[j]);
71 : }
72 : }
73 : }
74 :
75 : template <class vector_t>
76 0 : AABox<vector_t>::AABox(const AABox& b1, const AABox& b2)
77 : {
78 0 : for(size_t j = 0; j < vector_t::Size; ++j){
79 0 : min[j] = std::min(b1.min[j], b2.min[j]);
80 0 : max[j] = std::max(b1.max[j], b2.max[j]);
81 : }
82 0 : }
83 :
84 : template <class vector_t>
85 : AABox<vector_t>::AABox(const Sphere<vector_t>& s)
86 : {
87 : vector_t vrad;
88 : SetVec(vrad, s.radius);
89 : VecSubtract(min, s.center, vrad);
90 : VecAdd(max, s.center, vrad);
91 : }
92 :
93 : template <class vector_t>
94 0 : AABox<vector_t>::AABox(const AABox& b, const vector_t& v)
95 : {
96 0 : for(size_t j = 0; j < vector_t::Size; ++j){
97 0 : min[j] = std::min(b.min[j], v[j]);
98 0 : max[j] = std::max(b.max[j], v[j]);
99 : }
100 0 : }
101 :
102 : template <class vector_t>
103 : vector_t AABox<vector_t>::center() const
104 : {
105 : vector_t v;
106 : VecAdd(v, max, min);
107 : VecScale(v, v, 0.5);
108 : return v;
109 : }
110 :
111 : template <class vector_t>
112 : vector_t AABox<vector_t>::extension() const
113 : {
114 : vector_t v;
115 : VecSubtract(v, max, min);
116 : return v;
117 : }
118 :
119 : template <class vector_t>
120 : bool AABox<vector_t>::contains_point(const vector_t& point) const
121 : {
122 : return BoxBoundProbe(point, min, max);
123 : }
124 :
125 : template <class vector_t>
126 0 : bool AABox<vector_t>::overlaps_line(const vector_t& point1, const vector_t& point2) const
127 : {
128 : vector_t lmin, lmax;
129 : lmin = lmax = point1;
130 0 : for (size_t i = 0; i < vector_t::Size; i++) {
131 0 : lmin[i] = std::min(lmin[i], point2[i]);
132 0 : lmax[i] = std::max(lmax[i], point2[i]);
133 : }
134 0 : return BoxBoxIntersection(lmin, lmax, min, max);
135 : }
136 :
137 : }// end of namespace
138 :
139 : #endif
|