MuseScore  3.4
Music composition and notation
skyline.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2018 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __SKYLINE_H__
14 #define __SKYLINE_H__
15 
16 namespace Ms {
17 
18 #ifndef NDEBUG
19 #define DEBUG_SKYLINE // enable skyline debugging
20 #endif
21 
22 class Segment;
23 class Shape;
24 
25 //---------------------------------------------------------
26 // SkylineSegment
27 //---------------------------------------------------------
28 
30  qreal x;
31  qreal y;
32  qreal w;
33 
34  SkylineSegment(qreal _x, qreal _y, qreal _w) : x(_x), y(_y), w(_w) {}
35  };
36 
37 //---------------------------------------------------------
38 // SkylineLine
39 //---------------------------------------------------------
40 
41 class SkylineLine {
42  const bool north;
43  std::vector<SkylineSegment> seg;
44  typedef std::vector<SkylineSegment>::iterator SegIter;
45  typedef std::vector<SkylineSegment>::const_iterator SegConstIter;
46 
47  SegIter insert(SegIter i, qreal x, qreal y, qreal w);
48  void append(qreal x, qreal y, qreal w);
49  SegIter find(qreal x);
50  SegConstIter find(qreal x) const;
51 
52  public:
53  SkylineLine(bool n) : north(n) {}
54  void add(const Shape& s);
55  void add(const QRectF& r);
56  void add(qreal x, qreal y, qreal w);
57  void clear() { seg.clear(); }
58  void paint(QPainter&) const;
59  void dump() const;
60  qreal minDistance(const SkylineLine&) const;
61  qreal max() const;
62  bool valid(const SkylineSegment& s) const;
63  bool isNorth() const { return north; }
64 
65  SegIter begin() { return seg.begin(); }
66  SegConstIter begin() const { return seg.begin(); }
67  SegIter end() { return seg.end(); }
68  SegConstIter end() const { return seg.end(); }
69  };
70 
71 //---------------------------------------------------------
72 // Skyline
73 //---------------------------------------------------------
74 
75 class Skyline {
78 
79  public:
80  Skyline() : _north(true), _south(false) {}
81 
82  void clear();
83  void add(const Shape& s);
84  void add(const QRectF& r);
85 
86  qreal minDistance(const Skyline&) const;
87 
88  SkylineLine& north() { return _north; }
89  SkylineLine& south() { return _south; }
90  const SkylineLine& north() const { return _north; }
91  const SkylineLine& south() const { return _south; }
92 
93  void paint(QPainter&) const;
94  void dump(const char*, bool north = false) const;
95  };
96 
97 } // namespace Ms
98 
99 #endif
100 
std::vector< SkylineSegment >::const_iterator SegConstIter
Definition: skyline.h:45
SkylineLine & north()
Definition: skyline.h:88
qreal w
Definition: skyline.h:32
SkylineLine _south
Definition: skyline.h:77
SkylineLine _north
Definition: skyline.h:76
SegIter end()
Definition: skyline.h:67
Definition: skyline.h:41
SkylineLine(bool n)
Definition: skyline.h:53
const SkylineLine & north() const
Definition: skyline.h:90
SegConstIter begin() const
Definition: skyline.h:66
const SkylineLine & south() const
Definition: skyline.h:91
SegConstIter end() const
Definition: skyline.h:68
Definition: aeolus.cpp:26
Definition: skyline.h:75
SkylineLine & south()
Definition: skyline.h:89
std::vector< SkylineSegment >::iterator SegIter
Definition: skyline.h:44
Definition: skyline.h:29
const bool north
Definition: skyline.h:42
qreal x
Definition: skyline.h:30
Definition: shape.h:42
std::vector< SkylineSegment > seg
Definition: skyline.h:43
void clear()
Definition: skyline.h:57
SkylineSegment(qreal _x, qreal _y, qreal _w)
Definition: skyline.h:34
bool isNorth() const
Definition: skyline.h:63
qreal y
Definition: skyline.h:31
SegIter begin()
Definition: skyline.h:65
Skyline()
Definition: skyline.h:80