File: shape.h

package info (click to toggle)
musescore3 3.2.3%2Bdfsg2-11
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 210,672 kB
  • sloc: cpp: 291,093; xml: 200,238; sh: 3,779; ansic: 1,447; python: 393; makefile: 240; perl: 82; pascal: 79
file content (117 lines) | stat: -rw-r--r-- 3,453 bytes parent folder | download | duplicates (4)
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
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2016 Werner Schweer
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2
//  as published by the Free Software Foundation and appearing in
//  the file LICENCE.GPL
//=============================================================================

#ifndef __SHAPE_H__
#define __SHAPE_H__

namespace Ms {

#ifndef NDEBUG
// #define DEBUG_SHAPES    // enable shape debugging
#endif

class Segment;

//---------------------------------------------------------
//   ShapeElement
//---------------------------------------------------------

struct ShapeElement : public QRectF {
#ifndef NDEBUG
      const char* text;
      void dump() const;
      ShapeElement(const QRectF& f, const char* t = 0) : QRectF(f), text(t) {}
#else
      ShapeElement(const QRectF& f) : QRectF(f) {}
#endif
      };

//---------------------------------------------------------
//   Shape
//---------------------------------------------------------

class Shape : public std::vector<ShapeElement> {
// class Shape : std::vector<ShapeElement> {
   public:
      enum HorizontalSpacingType {
            SPACING_GENERAL = 0,
            SPACING_LYRICS,
            SPACING_HARMONY,
            };

      Shape() {}
#ifndef NDEBUG
      Shape(const QRectF& r, const char* s = 0) { add(r, s); }
#else
      Shape(const QRectF& r) { add(r); }
#endif
      void add(const Shape& s)            { insert(end(), s.begin(), s.end()); }
#ifndef NDEBUG
      void add(const QRectF& r, const char* t = 0);
#else
      void add(const QRectF& r)           { push_back(r); }
#endif
      void remove(const QRectF&);
      void remove(const Shape&);

      void addHorizontalSpacing(HorizontalSpacingType type, qreal left, qreal right);

      void translate(const QPointF&);
      void translateX(qreal);
      void translateY(qreal);
      Shape translated(const QPointF&) const;

      qreal minHorizontalDistance(const Shape&) const;
      qreal minVerticalDistance(const Shape&) const;
      qreal topDistance(const QPointF&) const;
      qreal bottomDistance(const QPointF&) const;
      qreal left() const;
      qreal right() const;
      qreal top() const;
      qreal bottom() const;

      size_t size() const { return std::vector<ShapeElement>::size();  }
      bool empty() const  { return std::vector<ShapeElement>::empty(); }
      void clear()        { std::vector<ShapeElement>::clear();        }

      bool contains(const QPointF&) const;
      bool intersects(const QRectF& rr) const;
      bool intersects(const Shape&) const;
      void paint(QPainter&) const;

#ifndef NDEBUG
      void dump(const char*) const;
#endif
      };

//---------------------------------------------------------
//   intersects
//---------------------------------------------------------

inline static bool intersects(qreal a, qreal b, qreal c, qreal d)
      {
      // return (a >= c && a < d) || (b >= c && b < d) || (a < c && b >= b);
      // return (std::max(a,b) > std::min(c,d)) && (std::min(a,b) < std::max(c,d));
      // if we can assume a <= b and c <= d
      if (a == b || c == d)   // zero height
            return false;
      return (b > c) && (a < d);
      }

#ifdef DEBUG_SHAPES
extern void testShapes();
#endif

} // namespace Ms

#endif