source: ntrip/trunk/BNC/qwt/qwt_pixel_matrix.h@ 10356

Last change on this file since 10356 was 8127, checked in by stoecker, 8 years ago

update qwt and qwtpolar, many QT5 fixes (unfinished)

File size: 2.3 KB
Line 
1/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10#ifndef QWT_PIXEL_MATRIX_H
11#define QWT_PIXEL_MATRIX_H
12
13#include "qwt_global.h"
14#include <qbitarray.h>
15#include <qrect.h>
16
17/*!
18 \brief A bit field corresponding to the pixels of a rectangle
19
20 QwtPixelMatrix is intended to filter out duplicates in an
21 unsorted array of points.
22*/
23class QWT_EXPORT QwtPixelMatrix: public QBitArray
24{
25public:
26 QwtPixelMatrix( const QRect& rect );
27 ~QwtPixelMatrix();
28
29 void setRect( const QRect& rect );
30 QRect rect() const;
31
32 bool testPixel( int x, int y ) const;
33 bool testAndSetPixel( int x, int y, bool on );
34
35 int index( int x, int y ) const;
36
37private:
38 QRect d_rect;
39};
40
41/*!
42 \brief Test if a pixel has been set
43
44 \param x X-coordinate
45 \param y Y-coordinate
46
47 \return true, when pos is outside of rect(), or when the pixel
48 has already been set.
49 */
50inline bool QwtPixelMatrix::testPixel( int x, int y ) const
51{
52 const int idx = index( x, y );
53 return ( idx >= 0 ) ? testBit( idx ) : true;
54}
55
56/*!
57 \brief Set a pixel and test if a pixel has been set before
58
59 \param x X-coordinate
60 \param y Y-coordinate
61 \param on Set/Clear the pixel
62
63 \return true, when pos is outside of rect(), or when the pixel
64 was set before.
65 */
66inline bool QwtPixelMatrix::testAndSetPixel( int x, int y, bool on )
67{
68 const int idx = index( x, y );
69 if ( idx < 0 )
70 return true;
71
72 const bool onBefore = testBit( idx );
73 setBit( idx, on );
74
75 return onBefore;
76}
77
78/*!
79 \brief Calculate the index in the bit field corresponding to a position
80
81 \param x X-coordinate
82 \param y Y-coordinate
83 \return Index, when rect() contains pos - otherwise -1.
84 */
85inline int QwtPixelMatrix::index( int x, int y ) const
86{
87 const int dx = x - d_rect.x();
88 if ( dx < 0 || dx >= d_rect.width() )
89 return -1;
90
91 const int dy = y - d_rect.y();
92 if ( dy < 0 || dy >= d_rect.height() )
93 return -1;
94
95 return dy * d_rect.width() + dx;
96}
97
98#endif
Note: See TracBrowser for help on using the repository browser.