Mercator
TerrainMod_impl.h
1 // This file may be redistributed and modified only under the terms of
2 // the GNU General Public License (See COPYING for details).
3 // Copyright (C) 2003 Damien McGinnes, Alistair Riddoch
4 
5 #ifndef MERCATOR_TERRAIN_MOD_IMPL_H
6 #define MERCATOR_TERRAIN_MOD_IMPL_H
7 
8 #include <Mercator/TerrainMod.h>
9 
10 #include <Mercator/Segment.h>
11 
12 namespace Mercator {
13 
14 template <template <int> class Shape>
15 ShapeTerrainMod<Shape>::ShapeTerrainMod(const Shape<2> &s) : m_shape(s)
16 {
17  m_box = m_shape.boundingBox();
18 }
19 
20 
21 template <template <int> class Shape> ShapeTerrainMod<Shape>::~ShapeTerrainMod()
22 {
23 }
24 
25 template <template <int> class Shape>
26 bool ShapeTerrainMod<Shape>::checkIntersects(const Segment& s) const
27 {
28  return WFMath::Intersect(m_shape, s.getRect(), false) ||
29  WFMath::Contains(s.getRect(), m_shape.getCorner(0), false);
30 }
31 
32 template <template <int> class Shape>
33 void ShapeTerrainMod<Shape>::setShape(const Shape<2> & s)
34 {
35  m_shape = s;
36  m_box = m_shape.boundingBox();
37 }
38 
39 template <template <int> class Shape> LevelTerrainMod<Shape>::~LevelTerrainMod()
40 {
41 }
42 
43 template <template <int> class Shape>
44 void LevelTerrainMod<Shape>::apply(float &point, int x, int y) const
45 {
46  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
47  point = m_level;
48  }
49 }
50 
51 template <template <int> class Shape>
53 {
54  return new LevelTerrainMod<Shape>(m_level, this->m_shape);
55 }
56 
57 template <template <int> class Shape>
58 void LevelTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
59 {
61  m_level = level;
62 }
63 
64 template <template <int> class Shape> AdjustTerrainMod<Shape>::~AdjustTerrainMod()
65 {
66 }
67 
68 template <template <int> class Shape>
69 void AdjustTerrainMod<Shape>::apply(float &point, int x, int y) const
70 {
71  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
72  point += m_dist;
73  }
74 }
75 
76 template <template <int> class Shape>
78 {
79  return new AdjustTerrainMod<Shape>(m_dist, this->m_shape);
80 }
81 
82 template <template <int> class Shape>
83 void AdjustTerrainMod<Shape>::setShape(float dist, const Shape<2> & s)
84 {
86  m_dist = dist;
87 }
88 
89 template <template <int> class Shape> SlopeTerrainMod<Shape>::~SlopeTerrainMod()
90 {
91 }
92 
93 template <template <int> class Shape>
94 void SlopeTerrainMod<Shape>::apply(float &point, int x, int y) const
95 {
96  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
97  point = m_level + (this->m_shape.getCenter()[0] - x) * m_dx
98  + (this->m_shape.getCenter()[1] - y) * m_dy;
99  }
100 }
101 
102 template <template <int> class Shape>
104 {
105  return new SlopeTerrainMod<Shape>(m_level, m_dx, m_dy, this->m_shape);
106 }
107 
108 template <template <int> class Shape>
109 void SlopeTerrainMod<Shape>::setShape(float level, float dx, float dy, const Shape<2> & s)
110 {
112  m_level = level;
113  m_dx = dx;
114  m_dy = dy;
115 }
116 
117 
118 template <template <int> class Shape> CraterTerrainMod<Shape>::~CraterTerrainMod()
119 {
120 }
121 
122 template <template <int> class Shape>
123 void CraterTerrainMod<Shape>::apply(float &point, int x, int y) const
124 {
125  if (Contains(this->m_shape,WFMath::Point<2>(x,y),true)) {
126  point += m_level;
127  }
128 }
129 
130 template <template <int> class Shape>
132 {
133  return new CraterTerrainMod<Shape>(m_level, this->m_shape);
134 }
135 
136 template <template <int> class Shape>
137 void CraterTerrainMod<Shape>::setShape(float level, const Shape<2> & s)
138 {
140  m_level = level;
141 }
142 
143 
144 } //namespace Mercator
145 
146 #endif // MERCATOR_TERRAIN_MOD_IMPL_H