Aleph-w  1.9
General library for algorithms and data structures
segment.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 # ifndef SEGMENT_H
28 # define SEGMENT_H
29 
30 # include "point.H"
31 //# include "points_utils.H"
32 
33 class Segment
34 {
35 
36  const Point * a;
37  const Point * b;
38 
39 public:
40 
41  Segment() : a(nullptr), b(nullptr)
42  {
43  /* empty */
44  }
45 
46  Segment(const Point * __a, const Point * __b) : a(__a), b(__b)
47  {
48  /* empty */
49  }
50 
51  Segment(const Point & __a, const Point & __b) : a(&__a), b(&__b)
52  {
53  /* empty */
54  }
55 
56  ~Segment()
57  {
58  /* empty */
59  }
60 
61  const bool operator == (const Segment & segment) const
62  {
63  return ((*a == *segment.a and *b == *segment.b) or
64  (*a == *segment.b and *b == *segment.a));
65  }
66 
67  /* Verifica si el segmento intersecta otro segmento */
68  const bool intersect(const Segment & segment) const
69  {
70  return intersectp(*a, *b, *segment.a, *segment.b);
71  }
72 
73  const Point * get_a() { return a ;} //Retorna el punto 'a' del segmento
74 
75  const Point * get_b() { return b; } //Retorna el punto 'b' del segmento
76 
77 
78  /* Recibe la coordenada 'y' de una linea horizontal y devuelve */
79  /* el punto de interseccion con el segmento */
80  Point horiz_line_inter(const Geom_Number & __y)
81  {
82 
83  Geom_Number intersection_x;
84  float m;
85 
86  m = (float)(a->get_y() - b->get_y()) / (float)(a->get_x() - b->get_x());
87 
88  intersection_x = (Geom_Number)((__y - b->get_y())/m + b->get_x());
89 
90  Point intersection_point(intersection_x,__y);
91 
92  return intersection_point;
93  }
94 
95  /* Retorna el punto mas alto entre a y b */
96  const Point * highest_point()
97  {
98 
99  if (a->get_y() > b->get_y())
100  return a;
101  else
102  return b;
103  }
104 
105  /* Retorna el punto mas bajo entre a y b */
106  const Point * lowest_point()
107  {
108  if (a->get_y() < b->get_y())
109  return a;
110  else
111  return b;
112  }
113 };
114 
115 # endif // SEGMENT_H
Definition: point.H:124
Definition: point.H:403
const Geom_Number & get_x() const
Returns x value.
Definition: point.H:189
const Geom_Number & get_y() const
Returns y value.
Definition: point.H:194

Leandro Rabindranath León