MuseScore/libmscore/shape.h

76 lines
2.2 KiB
C
Raw Normal View History

2016-01-04 14:48:58 +01:00
//=============================================================================
// 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
2016-01-04 14:48:58 +01:00
class Segment;
//---------------------------------------------------------
// Shape
//---------------------------------------------------------
2016-02-06 22:03:43 +01:00
class Shape : std::vector<QRectF> {
2016-01-04 14:48:58 +01:00
public:
Shape() {}
2016-07-20 12:45:34 +02:00
Shape(const QRectF& r) { add(r); }
2016-01-04 14:48:58 +01:00
void draw(QPainter*) const;
2016-02-06 22:03:43 +01:00
void add(const Shape& s) { insert(end(), s.begin(), s.end()); }
void add(const QRectF& r) { push_back(r); }
2016-03-18 14:35:15 +01:00
void remove(const QRectF&);
void remove(const Shape&);
2016-01-04 14:48:58 +01:00
void translate(const QPointF&);
Shape translated(const QPointF&) const;
qreal minHorizontalDistance(const Shape&) const;
qreal minVerticalDistance(const Shape&) const;
qreal left() const;
qreal right() const;
qreal top() const;
qreal bottom() const;
2016-02-06 22:03:43 +01:00
int size() const { return std::vector<QRectF>::size(); }
bool empty() const { return std::vector<QRectF>::empty(); }
void clear() { std::vector<QRectF>::clear(); }
2016-01-04 14:48:58 +01:00
#ifdef DEBUG_SHAPES
void dump(const char*) const;
#endif
};
2016-06-09 13:56:30 +02:00
//---------------------------------------------------------
// 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 (reduces layout from 116
return (b > c) && (a < d);
}
2016-01-04 14:48:58 +01:00
#ifdef DEBUG_SHAPES
extern void testShapes();
#endif
} // namespace Ms
#endif