/usr/include/magics/SegmentJoiner.h is in libmagics++-dev 2.18.15-5.
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 | /*
* (C) Copyright 1996-2012 ECMWF.
*
* This software is licensed under the terms of the Apache Licence Version 2.0
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
* In applying this licence, ECMWF does not waive the privileges and immunities
* granted to it by virtue of its status as an intergovernmental organisation nor
* does it submit to any jurisdiction.
*/
// File Segmenter.h
// Baudouin Raoult - ECMWF Aug 02
#ifndef SegmentJoiner_H
#define SegmentJoiner_H
#include "marsmachine.h"
#include "MagExceptions.h"
#include <cmath>
struct Point {
double x_;
double y_;
Point(double x = 0, double y = 0):
x_(x), y_(y)
{
}
friend bool operator ==(const Point& a,const Point& b)
{
return (a.x_ == b.x_) && (a.y_ == b.y_);
}
friend ostream& operator <<(ostream& s,const Point& p)
{
return s << "(" << p.x_ << "," << p.y_ << ")";
}
};
struct Segment {
bool ok_;
Point from_;
Point to_;
unsigned long phash_;
vector<Segment*> before_; // Index of segment before in polyline
vector<Segment*> after_;// Index of segment after in polyline
Segment* fnext_; // Next is the "from" hash table, in case of collisions
Segment* tnext_; // Next is the "to" hash table, in case of collisions
unsigned long fhash_; // Hash value of the "from_" point
unsigned long thash_; // Hash value of the "to_" point
Segment(const Point& from, const Point& to):
ok_(true), from_(from), to_(to), before_(0), after_(0), fnext_(0), tnext_(0){}
bool cancels(const Segment& other) const
{ return from_ == other.to_ && to_ == other.from_; }
friend ostream& operator <<(ostream& s,const Segment& p)
{ return s << "[from=" << p.from_ << ",to=" << p.to_ << "]"; }
double crossProduct(const Segment& other) const
{
double ux = to_.x_ - from_.x_;
double uy = to_.y_ - from_.y_;
double vx = other.to_.x_ - other.from_.x_;
double vy = other.to_.y_ - other.from_.y_;
return ux*vy-uy*vx;
}
bool colinear(const Segment& other) const
{
return fabs(crossProduct(other)) < 1e-10;
}
};
inline void reserve_(vector<Segment>& v,size_t s) { v.reserve(s); }
inline void reserve_(list<Segment>& v,size_t s) { }
inline void reserve_(deque<Segment>& v,size_t s) { }
class SegmentJoiner {
public:
typedef deque<Segment> SegList;
// -- Contructors
SegmentJoiner(): dirty_(false) {}
// -- Destructor
~SegmentJoiner() {}
// -- Methods
void reserve(size_t size)
{
reserve_(segments_,size);
}
size_t size() const
{ return segments_.size(); }
void push_back(const Segment& s)
{
if(!(s.from_ == s.to_))
segments_.push_back(s);
}
void push_back(const Point& from, const Point& to)
{ segments_.push_back(Segment(from,to)); }
void push_back(double x1, double y1, double x2, double y2)
{ segments_.push_back(Segment(Point(x1,y1),Point(x2,y2))); }
// Call this one...
double computePolygonLines(vector<vector<Point> >& result);
double computeSegmentLines(list<deque<Segment> >& result);
double punchHoles(vector<vector<Point> >& result);
static double area(const vector<Point>& );
static bool isHole(const vector<Point>& p) { return area(p) < 0; }
static bool pointInPoly(const Point&,const vector<Point>& p);
static void check(list<deque<Segment> >& lines);
private:
// No copy allowed
SegmentJoiner(const SegmentJoiner&);
SegmentJoiner& operator=(const SegmentJoiner&);
// -- Members
SegList segments_;
bool dirty_;
};
#endif
|