File: Sphere.cc

package info (click to toggle)
python-demgengeo 1.4-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,000 kB
  • sloc: cpp: 13,449; python: 1,260; makefile: 304; sh: 90
file content (114 lines) | stat: -rw-r--r-- 2,350 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/////////////////////////////////////////////////////////////
//                                                         //
// Copyright (c) 2007-2017 by The University of Queensland //
// Centre for Geoscience Computing                         //
// http://earth.uq.edu.au/centre-geoscience-computing      //
//                                                         //
// Primary Business: Brisbane, Queensland, Australia       //
// Licensed under the Open Software License version 3.0    //
// http://www.apache.org/licenses/LICENSE-2.0              //
//                                                         //
/////////////////////////////////////////////////////////////

#include "Sphere.h"

// --- System includes ---
#include <cmath>

using std::sqrt;

double Sphere::NearZero=1e-8;
int Sphere::s_output_style=0;
unsigned int Sphere::s_current_id=0;

/*!
  construct "invalid" Sphere
*/
Sphere::Sphere()
{
  m_valid=false;
  m_id=0;
  m_tag=0;
}

/*!
  construct valid Sphere

  \param center the center of the circle
  \param rad the radius
*/
Sphere::Sphere(const Vector3& center,double rad)
{
  m_center=center;
  m_rad=rad;
  m_valid=true;
  m_id=Sphere::s_current_id;
  Sphere::s_current_id++;
  m_tag=0;
}

/*!
  copy constructor

  \param S the original
*/
Sphere::Sphere(const Sphere& S)
{
  m_center=S.m_center;
  m_rad=S.m_rad;
  m_valid=S.m_valid;
  m_id=S.m_id;
  m_tag=S.m_tag; 
}

/*!
  get distance between given point and the surface of the Sphere

  \param P the point
*/
double  Sphere::getDist(const Vector3& P) const
{
  return (P-m_center).norm()-m_rad;
}


/*!
  Set id of sphere. If higher than current_id, increase current_id
  accordingly

  \param i the new id of the sphere
*/
void Sphere::setId(int i)
{
  m_id=i;
  if(i>s_current_id) {
    s_current_id=i;
  }
}

/*!
  Set output style

  \param style the output style: 0=Debug, 1=.geo
*/
void Sphere::SetOutputStyle(int style)
{
  Sphere::s_output_style=style;
}

ostream& operator << (ostream& ost, const Sphere& S)
{
  if(Sphere::s_output_style==0){
    if(S.m_valid){
      ost << S.m_center << " | " << S.m_rad << " |  " << S.m_id; 
    } else {
      ost << "invalid Sphere";
    }
  } else if (Sphere::s_output_style==1){
    if(S.m_valid){
      ost << S.m_center << " "  << S.m_rad << " " << S.m_id << " " << S.m_tag;
    } 
  }
  
  return ost;
}