This file is indexed.

/usr/include/CGAL/Straight_2.h is in libcgal-dev 4.7-4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
// Copyright (c) 2000  
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel).  All rights reserved. 
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// 
//
// Author(s)     : Geert-Jan Giezeman


#ifndef CGAL_STRAIGHT_2_H
#define CGAL_STRAIGHT_2_H

#include <CGAL/Line_2_Line_2_intersection.h>
#include <CGAL/squared_distance_utils.h>
#include <CGAL/Kernel/global_functions_internal_2.h>

namespace CGAL {

namespace internal {

class Straight_2_base_ {
public:
    enum states {EMPTY, POINT, SEGMENT, RAY, LINE};
    enum bound_states {NO_UNBOUNDED=0, MIN_UNBOUNDED=1, MAX_UNBOUNDED=2,
                        BOTH_UNBOUNDED = 3, LINE_EMPTY = 4};
protected:
                            Straight_2_base_() ;
    int                     main_dir_;  // support_ is x or y directed (0/1).
    int                     dir_sign_;  // sign of main direction coord.
    unsigned int            bound_state_; // 0, 1, 2, 3, 4.
public:
    unsigned int            bound_state() const {return bound_state_;}
};

template <class K>
class Straight_2_: public Straight_2_base_ {
public:
                            Straight_2_() ;
                            Straight_2_(typename K::Point_2 const &point) ;
                            Straight_2_(typename K::Line_2 const &line) ;
                            Straight_2_(typename K::Ray_2 const &ray) ;
                            Straight_2_(typename K::Ray_2 const &ray,bool cooriented) ;
                            Straight_2_(typename K::Segment_2 const &seg) ;
    void                    cut_right_off(typename K::Line_2 const & cutter) ;
    int                     collinear_order(typename K::Point_2 const & p1,
                                            typename K::Point_2 const &p2) const ;
    void                    current(typename K::Line_2 &line) const;
    void                    current(typename K::Ray_2 &ray) const;
    void                    current(typename K::Segment_2 &seg) const;
    void                    current(typename K::Point_2 &point) const;
    states                  current_state() const;
    bool                    operator==(const Straight_2_<K>&) const;
    bool                    operator!=(const Straight_2_<K>&other) const
                { return !(*this == other);}
protected:
    typename K::Line_2          support_;   // The supporting line.
    typename K::Point_2         min_;
    typename K::Point_2         max_;
};



inline
Straight_2_base_::
Straight_2_base_()
{
    bound_state_ = LINE_EMPTY;
}

template <class K>
Straight_2_base_::states
Straight_2_<K>::
current_state() const
{
    switch (bound_state_) {
    case BOTH_UNBOUNDED:
        return LINE;
    case MIN_UNBOUNDED:
    case MAX_UNBOUNDED:
        return RAY;
    case NO_UNBOUNDED:
        return (collinear_order(min_, max_) == 0) ? POINT : SEGMENT;
    case LINE_EMPTY:
    default:
        return EMPTY;
    }
}

template <class K>
Straight_2_<K>::
Straight_2_()
{
    bound_state_ = LINE_EMPTY;
}

template <class K>
Straight_2_<K>::
Straight_2_(typename K::Line_2 const &line)
{
    support_ = line;
    typename K::Vector_2 const &dir = support_.direction().to_vector();
    main_dir_ = (CGAL_NTS abs(dir.x()) > CGAL_NTS abs(dir.y()) ) ? 0 : 1;
    dir_sign_ =
        CGAL_NTS sign(support_.direction().to_vector().cartesian(main_dir_));
    bound_state_ = BOTH_UNBOUNDED;
}

template <class K>
Straight_2_<K>::
Straight_2_(typename K::Point_2 const &point)
{
  typedef typename K::Direction_2 Direction_2;
  typedef typename K::Line_2 Line_2;
    support_ = Line_2(point, Direction_2(K::RT(1), K::RT(0)));
    main_dir_ = 0;
    dir_sign_ = 1;
    bound_state_ = NO_UNBOUNDED;
    min_ = point;
    max_ = point;
}

template <class K>
Straight_2_<K>::
Straight_2_(typename K::Ray_2 const &ray)
{
    support_ = ray.supporting_line();
    typename K::Vector_2 const &dir = ray.direction().to_vector();
    main_dir_ = (CGAL_NTS abs(dir.x()) > CGAL_NTS abs(dir.y()) ) ? 0 : 1;
    dir_sign_ =
        CGAL_NTS sign(support_.direction().to_vector().cartesian(main_dir_));
    bound_state_ = MAX_UNBOUNDED;
    min_ = ray.source();
}

template <class K>
Straight_2_<K>::
Straight_2_(typename K::Ray_2 const &ray_,bool cooriented)
{
        typename K::Ray_2 const &ray = cooriented ? ray_ : ray_.opposite();
        support_ = ray.supporting_line();
        /* the supporting line is cooriented with the input ray iff
        cooriented is true */
    typename K::Vector_2 const &dir = ray.direction().to_vector();
    main_dir_ = (CGAL_NTS abs(dir.x()) > CGAL_NTS abs(dir.y()) ) ? 0 : 1;
    dir_sign_ =
        CGAL_NTS sign(support_.direction().to_vector().cartesian(main_dir_));
    if (cooriented)
        {
            bound_state_ = MAX_UNBOUNDED;
                min_ = ray.source();
        }
        else
        {
                bound_state_ = MIN_UNBOUNDED;
                max_ = ray.source();
        }
}

template <class K>
Straight_2_<K>::
Straight_2_(typename K::Segment_2 const &seg)
{
    support_ = seg.supporting_line();
    typename K::Vector_2 const &dir = support_.direction().to_vector();
    main_dir_ = (CGAL_NTS abs(dir.x()) > CGAL_NTS abs(dir.y()) ) ? 0 : 1;
    dir_sign_ =
        CGAL_NTS sign(support_.direction().to_vector().cartesian(main_dir_));
    bound_state_ = NO_UNBOUNDED;
    min_ = seg.source();
    max_ = seg.target();
}


template <class K>
void
Straight_2_<K>::
current(typename K::Line_2 &line) const
{
    CGAL_kernel_assertion(bound_state_ == BOTH_UNBOUNDED);
    line = support_;
}

template <class K>
void
Straight_2_<K>::
current(typename K::Ray_2 &ray) const
{
  typedef typename K::Ray_2 Ray_2;
    CGAL_kernel_assertion(bound_state_ == MIN_UNBOUNDED
                        || bound_state_ == MAX_UNBOUNDED);
    if (bound_state_ == MIN_UNBOUNDED) {
        ray = Ray_2(max_, -support_.direction());
    } else {
        ray = Ray_2(min_, support_.direction());
    }
}

template <class K>
void
Straight_2_<K>::
current(typename K::Segment_2 &seg) const
{
  typedef typename K::Segment_2 Segment_2;
    CGAL_kernel_assertion(bound_state_ == NO_UNBOUNDED
                && collinear_order(min_, max_) != 0);
    seg = Segment_2(min_, max_);
}

template <class K>
void
Straight_2_<K>::
current(typename K::Point_2 &pt) const
{
    CGAL_kernel_assertion(bound_state_ == NO_UNBOUNDED
                && collinear_order(min_, max_) == 0);
    pt = min_;
}


template <class K>
bool Straight_2_<K>::operator==(const Straight_2_<K>& s) const
{
  typedef Straight_2_<K> Straight_2;
  //    enum bound_states {NO_UNBOUNDED=0, MIN_UNBOUNDED=1, MAX_UNBOUNDED=2,
  //                    BOTH_UNBOUNDED = 3, LINE_EMPTY = 4};
  if (bound_state_!=s.bound_state()) return false;
  if (bound_state_==Straight_2::LINE_EMPTY) return true; // empty
  if (support_!=s.support_)
    return false; // on different lines, even if both are points.
  switch (bound_state_)
    {
    case Straight_2::NO_UNBOUNDED:
      return min_==s.min_ && max_==s.max_;
    case Straight_2::MAX_UNBOUNDED:
      return min_==s.min_;
    case Straight_2::MIN_UNBOUNDED:
      return max_==s.max_;
    case Straight_2::BOTH_UNBOUNDED:
      return true;
    }
  return false;
}




template <class K>
int
sign_of_cross(typename K::Direction_2 const &dir1,
	      typename K::Direction_2 const &dir2,
	      const K&)
{
    return static_cast<int>(internal::orientation(dir1.to_vector(),
                                               dir2.to_vector(), K()));
}

template <class K>
void
Straight_2_<K>::
cut_right_off(typename K::Line_2 const & cutter)
// cut off any part of this straight that is to the right of the cutter.
{
    if (bound_state_ == LINE_EMPTY)
        return;
    Line_2_Line_2_pair<K> pair(&support_, &cutter);
    switch (pair.intersection_type()) {
    case Line_2_Line_2_pair<K>::NO_INTERSECTION:
        if (cutter.has_on_negative_side(support_.point()))
            bound_state_ = LINE_EMPTY;
        break;
    case Line_2_Line_2_pair<K>::LINE:
        break;
    case Line_2_Line_2_pair<K>::POINT:
        typename K::Point_2 ispoint = pair.intersection_point();
        bool new_point = false;
        switch (sign_of_cross(support_.direction(), cutter.direction(), K())) {
        case -1: // new minimum.
            if (bound_state_ & MIN_UNBOUNDED) {
                new_point = true;
                bound_state_ ^= MIN_UNBOUNDED;  // exclusive or removes flag.
            } else {
                if (collinear_order(ispoint, min_) == -1)
                    new_point = true;
            }
            if (new_point) {
                if (!(bound_state_ & MAX_UNBOUNDED)
                    && collinear_order(ispoint, max_) == -1)
                    bound_state_ = LINE_EMPTY;
                else
                    min_ = ispoint;
            }
            break;
        case 0: // should not happen
            CGAL_kernel_warning_msg(false, "Internal CGAL error.");
            break;
        case 1: // new maximum
            if (bound_state_ & MAX_UNBOUNDED) {
                new_point = true;
                bound_state_ ^= MAX_UNBOUNDED;  // exclusive or removes flag.
            } else {
                if (collinear_order(ispoint, max_) == 1)
                    new_point = true;
            }
            if (new_point) {
                if (!(bound_state_ & MIN_UNBOUNDED)
                    && collinear_order(ispoint, min_) == 1)
                    bound_state_ = LINE_EMPTY;
                else
                    max_ = ispoint;
            }
            break;
        }
        break;
    }
}

template <class K>
int
Straight_2_<K>::
collinear_order(typename K::Point_2 const &pt1, typename K::Point_2 const & pt2) const
// Compare two points on the support_ line.
// If the second point lies in the direction of the direction vector from
// the first point, the result is 1.
// Other results are -1 (other side) and 0 (coincidence).
{
  typename K::Construct_cartesian_const_iterator_2 construct_cccit;
  typename K::Cartesian_const_iterator_2 ccit1 = construct_cccit(pt1) + main_dir_;
  typename K::Cartesian_const_iterator_2 ccit2 = construct_cccit(pt2) + main_dir_;
    int diffsign;
    diffsign = CGAL_NTS sign(*ccit2 - *ccit1);
    if (diffsign == 0)
        return 0;
    return (diffsign == dir_sign_) ? 1 : -1;
}

} // namespace internal

} //namespace CGAL






#endif