qreal CurveBranch::findStep(qreal t, qreal t1, qreal unitLength) { //Greedy algorithm : doubling + dichotomy while it is possible const qreal START_EPS = 1e-9; const qreal CMP_EPS = 1e-6; qreal eps, h; for(eps = qMin(START_EPS, (t1 - t) / 2); t + eps <= t1;) { if ((h = calcStep(t, qMin(t + eps, t1), unitLength)) <= eps) { return h; } else { eps *= 2; } } for(eps /= 2; t1 - (t + eps) > CMP_EPS;) { if ((h = calcStep(t, qMin(t + eps, t1), unitLength)) <= eps) { return h; } else { eps = (t1 + (t + eps)) / 2 - t; } } return t1 - t; }
Sphere::Sphere(QPoint coord1, QPoint size1) { coord = coord1; step = calcStep(); size = size1; color = calcColor(); brush = 2; }
void Video::fillPolygon(uint16 color, uint16 zoom, const Point &pt) { if (_pg.bbw == 0 && _pg.bbh == 1 && _pg.numPoints == 4) { drawPoint(color, pt.x, pt.y); return; } int16 x1 = pt.x - _pg.bbw / 2; int16 x2 = pt.x + _pg.bbw / 2; int16 y1 = pt.y - _pg.bbh / 2; int16 y2 = pt.y + _pg.bbh / 2; if (x1 > 319 || x2 < 0 || y1 > 199 || y2 < 0) return; _hliney = y1; uint16 i, j; i = 0; j = _pg.numPoints - 1; x2 = _pg.points[i].x + x1; x1 = _pg.points[j].x + x1; ++i; --j; drawLine pdl; if (color < 0x10) { pdl = &Video::drawLineN; } else if (color > 0x10) { pdl = &Video::drawLineP; } else { pdl = &Video::drawLineT; } uint32 cpt1 = x1 << 16; uint32 cpt2 = x2 << 16; while (1) { _pg.numPoints -= 2; if (_pg.numPoints == 0) { return; } uint16 h; int32 step1 = calcStep(_pg.points[j + 1], _pg.points[j], h); int32 step2 = calcStep(_pg.points[i - 1], _pg.points[i], h); ++i; --j; cpt1 = (cpt1 & 0xFFFF0000) | 0x7FFF; cpt2 = (cpt2 & 0xFFFF0000) | 0x8000; if (h == 0) { cpt1 += step1; cpt2 += step2; } else { for (; h != 0; --h) { if (_hliney >= 0) { x1 = cpt1 >> 16; x2 = cpt2 >> 16; if (x1 <= 319 && x2 >= 0) { if (x1 < 0) x1 = 0; if (x2 > 319) x2 = 319; /* #ifdef MAPIP int addr = *((int*)&pdl); ((void(*)(void*,int16,int16,uint8))addr)(this, x1, x2, color); #else */ (this->*pdl)(x1, x2, color); //#endif } } cpt1 += step1; cpt2 += step2; ++_hliney; if (_hliney > 199) return; } } }