INFO702 - TPs
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Disk Struct Reference

A disk is a simple graphical shape. More...

#include <objects.hpp>

Inheritance diagram for Disk:
GraphicalShape

Public Member Functions

 Disk (qreal r, const MasterShape *master_shape)
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override
 
virtual QPointF randomPoint () const override
 
virtual bool isInside (const QPointF &p) const override
 
virtual QRectF boundingRect () const override
 

Public Attributes

const qreal _r
 
const MasterShape_master_shape
 

Detailed Description

A disk is a simple graphical shape.

It points to its master shape in order to know in which color it must be painted.

Definition at line 74 of file objects.hpp.

Constructor & Destructor Documentation

◆ Disk()

Disk::Disk ( qreal  r,
const MasterShape master_shape 
)

Definition at line 30 of file objects.cpp.

31 : _r( r ), _master_shape( master_shape ) {}

Member Function Documentation

◆ boundingRect()

QRectF Disk::boundingRect ( ) const
overridevirtual

Definition at line 51 of file objects.cpp.

52{
53 return QRectF( -_r, -_r, 2.0 *_r, 2.0 * _r );
54}

◆ isInside()

bool Disk::isInside ( const QPointF &  p) const
overridevirtual

Implements GraphicalShape.

Definition at line 45 of file objects.cpp.

46{
47 return QPointF::dotProduct( p, p ) <= _r * _r;
48}

◆ paint()

void Disk::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget *  widget 
)
overridevirtual

Definition at line 57 of file objects.cpp.

58{
59 painter->setBrush( _master_shape->currentColor() );
60 painter->drawEllipse( QPointF( 0.0, 0.0 ), _r, _r );
61}

◆ randomPoint()

QPointF Disk::randomPoint ( ) const
overridevirtual

Implements GraphicalShape.

Definition at line 34 of file objects.cpp.

35{
36 QPointF p;
37 do {
38 p = QPointF( ( rand01() * 2.0 - 1.0 ),
39 ( rand01() * 2.0 - 1.0 ) );
40 } while ( ( p.x() * p.x() + p.y() * p.y() ) > 1.0 );
41 return p * _r;
42}

Member Data Documentation

◆ _master_shape

const MasterShape* Disk::_master_shape

Definition at line 83 of file objects.hpp.

◆ _r

const qreal Disk::_r

Definition at line 82 of file objects.hpp.


The documentation for this struct was generated from the following files: