Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_euclidian_graph.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
81# ifndef TPL_EUCLIDIAN_GRAPH_H
82# define TPL_EUCLIDIAN_GRAPH_H
83
84# include <tpl_graph.H>
85# include <point.H>
86# include <ah-errors.H>
87
88namespace Aleph
89{
94 template <typename Node_Info>
95 class Euclidian_Node : public Graph_Node<Node_Info>
96 {
97 public:
99
101
103
104 private:
105 Point position;
106
107 public:
110 {
111 /* Empty */
112 }
113
116 {
117 /* Empty */
118 }
119
122 {
123 /* Empty */
124 }
125
126 Euclidian_Node(const Node_Info & info, const Point & _position)
128 {
129 /* Empty */
130 }
131
133 : Graph_Node<Node_Info>(node), position(node->get_position())
134 {
135 /* Empty */
136 }
137
138 Point &get_position() { return position; }
139
140 const Point &get_position() const { return position; }
141 }; // End class Euclidian_Node
142
143
144 template <typename Arc_Info>
145 class Euclidian_Arc : public Graph_Arc<Arc_Info>
146 {
147 public:
149
151
153
156 {
157 /* Empty */
158 }
159
162 {
163 /* Empty */
164 }
165
166 Euclidian_Arc(void *src, void *tgt, const Arc_Info & info)
167 : Graph_Arc<Arc_Info>(src, tgt, info)
168 {
169 /* Empty */
170 }
171
172 Euclidian_Arc(void *src, void *tgt)
173 : Graph_Arc<Arc_Info>(src, tgt)
174 {
175 /* Empty */
176 }
177 }; // End class Euclidian_Arc
178
179 template <class __Euclidian_Node, class __Euclidian_Arc>
180 class Euclidian_Graph : public List_Graph<__Euclidian_Node, __Euclidian_Arc>
181 {
182 public:
184
186
188
189 typedef typename Node::Node_Type Node_Type;
190
191 typedef typename Arc::Arc_Type Arc_Type;
192
194 {
195 /* Empty */
196 }
197
199 : Graph()
200 {
201 copy_graph(*this,
203 false);
204 }
205
206 Node * insert_node(Node *node) noexcept override
207 {
208 return Graph::insert_node(node);
209 }
210
212 {
213 return insert_node(new Node(info));
214 }
215
216 Node * insert_node(const Point & position)
217 {
218 return insert_node(new Node(position));
219 }
220
221 Node * insert_node(const Node_Type & info, const Point & position)
222 {
223 return insert_node(new Node(info, position));
224 }
225
227 {
228 const Point & src_point = this->get_src_node(arc)->get_position();
229 const Point & tgt_point = this->get_tgt_node(arc)->get_position();
230 return src_point.distance_with(tgt_point);
231 }
232
234 {
235 if (this == &eg)
236 return *this;
237 copy_graph(*this, const_cast<Euclidian_Graph<Node, Arc> &>(eg), false);
238 return *this;
239 }
240
242 {
243 clear_graph(*this);
244 }
245
246 Node * search_node(const Point &);
247 }; // End class Euclidian_Graph
248
249 template <class __Euclidian_Node, class __Euclidian_Arc>
272
273 template <class Node, class Arc>
275 {
276 for (typename Euclidian_Graph<Node, Arc>::Node_Iterator it(*this);
277 it.has_curr(); it.next_ne())
278 {
279 Euclidian_Graph<Node, Arc>::Node *curr = it.get_curr();
280 if (curr->get_position() == point)
281 return curr;
282 }
283 return nullptr;
284 }
285
286 template <class __Euclidian_Graph>
288 {
293
295
298
301
302 public:
310
314 x_scale(1), y_scale(1)
315 {
316 if (graph.get_num_nodes() < 1)
317 return;
318
319 typename __Euclidian_Graph::Node_Iterator itor(graph);
320 points.append(itor.get_curr()->get_position());
322 &points.access(0);
323
324 for (int i = 1; itor.has_curr(); itor.next_ne(), ++i)
325 {
326 const Point & p = itor.get_curr()->get_position();
327 points.append(p);
328 if (p.get_x() < ptr_west_point->get_x())
330 if (p.get_y() > ptr_north_point->get_y())
332 if (p.get_x() > ptr_east_point->get_x())
334 if (p.get_y() < ptr_south_point->get_y())
336 }
337 }
338
340 {
341 /* Empty */
342 }
343
344 Point &add_point(typename __Euclidian_Graph::Node *node)
345 {
346 ah_domain_error_if(node == nullptr) << "node is nullptr";
347 points.append(node->get_position());
348 Point & p = points.top();
349 if (points.size() == 1)
351 &points.access(0);
352 else
353 {
354 if (p.get_x() < ptr_west_point->get_x())
355 ptr_west_point = &p;
356 if (p.get_y() > ptr_north_point->get_y())
357 ptr_north_point = &p;
358 if (p.get_x() > ptr_east_point->get_x())
359 ptr_east_point = &p;
360 if (p.get_y() < ptr_south_point->get_y())
361 ptr_south_point = &p;
362 }
363 return p;
364 }
365
366 const Point &get_west_point() const
367 {
368 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
369 return *ptr_west_point;
370 }
371
372 const Point &get_north_point() const
373 {
374 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
375 return *ptr_north_point;
376 }
377
378 const Point &get_east_point() const
379 {
380 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
381 return *ptr_east_point;
382 }
383
384 const Point &get_south_point() const
385 {
386 ah_logic_error_if(points.size() < 1) << "There are no points on plane";
387 return *ptr_south_point;
388 }
389
391 {
392 if (points.size() < 1)
393 return Geom_Number(0);
394 return ptr_east_point->get_x() - ptr_west_point->get_x();
395 }
396
398 {
399 if (points.size() < 1)
400 return Geom_Number(0);
401 return ptr_north_point->get_y() - ptr_south_point->get_y();
402 }
403
404 const Geom_Number &get_x_node_ratio() const { return x_node_ratio; }
405
410
411 const Geom_Number &get_y_node_ratio() const { return y_node_ratio; }
412
417
418 const Geom_Number &get_x_scale() const { return x_scale; }
419
421
422 const Geom_Number &get_y_scale() const { return y_scale; }
423
425 }; // End class Abstract_Euclidian_Plane
426} // End namespace Aleph
427
428# endif // TPL_EUCLIDIAN_GRAPH_H
Exception handling system with formatted messages for Aleph-w.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
Definition ah-errors.H:522
#define ah_logic_error_if(C)
Throws std::logic_error if condition holds.
Definition ah-errors.H:325
WeightedDigraph::Node Node
const Geom_Number & get_x_node_ratio() const
Point & add_point(typename __Euclidian_Graph::Node *node)
void set_y_node_ratio(const Geom_Number &_y_node_ratio)
const Geom_Number & get_y_node_ratio() const
void set_x_scale(const Geom_Number &_x_scale)
void set_x_node_ratio(const Geom_Number &_x_node_ratio)
const Geom_Number & get_y_scale() const
const Geom_Number & get_x_scale() const
void set_y_scale(const Geom_Number &_y_scale)
Abstract_Euclidian_Plane(__Euclidian_Graph &graph)
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
T & top() const
Return a modifiable reference to the last item of stack.
T & append()
Allocate a new entry to the end of array.
Euclidian_Arc(void *src, void *tgt, const Arc_Info &info)
Euclidian_Arc(void *src, void *tgt)
Euclidian_Arc(const Arc_Info &info)
Euclidian_Digraph(const Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc > &euclidian_digraph)
Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc > & operator=(Euclidian_Digraph< __Euclidian_Node, __Euclidian_Arc > &eg)
Euclidian_Graph(const Euclidian_Graph< Node, Arc > &euclidian_graph)
Node * insert_node(const Point &position)
Geom_Number get_distance(Arc *arc)
Node * insert_node(const Node_Type &info, const Point &position)
Node * insert_node(Node *node) noexcept override
Insertion of a node already allocated.
Euclidian_Graph< Node, Arc > & operator=(Euclidian_Graph< Node, Arc > &eg)
Node * search_node(const Point &)
List_Graph< Node, Arc > Graph
Node * insert_node(const Node_Type &info)
Euclidian_Node(const Point &_position)
const Point & get_position() const
Euclidian_Node(const Node_Info &info, const Point &_position)
Euclidian_Node(Euclidian_Node *node)
Euclidian_Node(const Node_Info &info)
Graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:428
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
Definition tpl_graph.H:524
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
Definition graph-dry.H:731
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
Definition graph-dry.H:737
void clear_graph(GT &g) noexcept
Clean a graph: all its nodes and arcs are removed and freed.
Definition tpl_graph.H:3549
void copy_graph(GT &gtgt, const GT &gsrc, bool cookie_map=false)
Explicit copy of graph.
Definition tpl_graph.H:3567
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
DynList< T > maps(const C &c, Op op)
Classic map operation.
2D point and geometric utilities.
mpq_class Geom_Number
Numeric type used by the geometry module.
Definition point.H:68
Arc of graph implemented with double-linked adjacency lists.
Definition tpl_graph.H:222
Node belonging to a graph implemented with a double linked adjacency list.
Definition tpl_graph.H:121
Generic graph and digraph implementations.