qwt_pixel_matrix.h
Go to the documentation of this file.
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 
23 class QWT_EXPORT QwtPixelMatrix: public QBitArray
24 {
25 public:
26  explicit 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 
37 private:
38  QRect d_rect;
39 };
40 
50 inline 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 
66 inline 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 
85 inline 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
bool testPixel(int x, int y) const
Test if a pixel has been set.
int index(int x, int y) const
Calculate the index in the bit field corresponding to a position.
A bit field corresponding to the pixels of a rectangle.
#define QWT_EXPORT
Definition: qwt_global.h:38
TFSIMD_FORCE_INLINE const tfScalar & y() const
bool testAndSetPixel(int x, int y, bool on)
Set a pixel and test if a pixel has been set before.
TFSIMD_FORCE_INLINE const tfScalar & x() const


plotjuggler
Author(s): Davide Faconti
autogenerated on Sat Jul 6 2019 03:44:17