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 118 119 120 121
|
/***************************************************************************
rpainter.cpp - description
-------------------
begin : Mon Sep 27 1999
copyright : (C) 1999 by Andreas Mustun
email : andrew@ribbonsoft.com
***************************************************************************/
/****************************************************************************
** rpainter.cpp 1998/08/27 A. Mustun RibbonSoft
**
** Copyright (C) 1998 RibbonSoft. All rights reserved.
**
*****************************************************************************/
#include "rpainter.h"
#include "rmath.h"
// Constructor:
//
RPainter::RPainter()
:QPainter()
{
}
// Constructor:
//
RPainter::RPainter(const QPaintDevice* _pDev)
:QPainter(_pDev)
{
}
// Destructor:
//
RPainter::~RPainter()
{
}
// Draw a more exact arc:
//
void
RPainter::drawExactArc(float _cx, float _cy,
float _cr,
float _a1, float _a2,
int _x1, int _y1,
int _x2, int _y2,
bool _reversed)
{
if(_cr<=0.5) {
drawPoint((int)_cx, (int)_cy);
}
else {
int cix; // Next point on circle
int ciy; //
float aStep; // Angle Step (rad)
float aStep2; // Angle Step (rad)
float a; // Current Angle (rad)
if(2.0/_cr<=1.0)
aStep=asin(2.0/_cr);
else
aStep=1.0;
aStep2=aStep*0.50;
if(aStep<0.05) aStep = 0.05;
if(!_reversed) {
// Arc Counterclockwise:
//
if(_a1>_a2-0.01) _a2+=360.0;
moveTo(_x1, _y1);
for(a=(_a1/ARAD)+aStep; a<=(_a2/ARAD); a+=aStep) {
cix = (int)(_cx+cos(a)*_cr);
ciy = (int)(_cy-sin(a)*_cr);
lineTo(cix, ciy);
/*
a+=aStep2;
cix = (int)(_cx+cos(a)*_cr);
ciy = (int)(_cy-sin(a)*_cr);
moveTo(cix, ciy);
*/
}
lineTo(_x2, _y2);
}
else {
// Arc Clockwise:
if(_a1<_a2+0.01) _a2-=360.0;
moveTo(_x1, _y1);
for(a=(_a1/ARAD)-aStep; a>=(_a2/ARAD); a-=aStep) {
cix = (int)(_cx+cos(a)*_cr);
ciy = (int)(_cy-sin(a)*_cr);
lineTo(cix, ciy);
/*
a-=aStep2;
cix = (int)(_cx+cos(a)*_cr);
ciy = (int)(_cy-sin(a)*_cr);
moveTo(cix, ciy);
*/
}
lineTo(_x2, _y2);
}
}
}
// EOF
|