It reduces the number of polygon's vertices using actual pixel coordinates.
#include <cassert>
#include <vector>
public:
PolyTest2();
private:
enum TestSize {
kNSawPoints = 10000
};
std::vector<Double_t> fXs1;
std::vector<Double_t> fYs1;
std::vector<Double_t> fXs2;
std::vector<Double_t> fYs2;
};
PolyTest2::PolyTest2()
:
TNamed(
"polygon_compression_test2",
"polygon_compression_test2")
{
assert(
gPad !=
nullptr &&
"PolyTest2, gPad is null");
assert(
gRandom !=
nullptr &&
"PolyTest2, gRandom is null");
Double_t xMin = 0., xMax = 0., yMin = 0., yMax = 0.;
gPad->GetRange(xMin, yMin, xMax, yMax);
assert(xMax - xMin > 0 && yMax - yMin > 0 && "PolyTest2, invalid canvas' ranges");
const unsigned nVertices = 3 + kNSawPoints;
{
fXs1.resize(nVertices);
fYs1.resize(nVertices);
fXs1[0] = 0.;
fYs1[0] = 0.;
const Double_t w1 = 0.2 * (xMax - xMin);
const Double_t saw1ToothSize = 0.1 * w1;
const Double_t yStep = (yMax - yMin) / (kNSawPoints - 1);
for (unsigned i = 1; i <= kNSawPoints; ++i) {
fYs1[i] = yMin + yStep * (i - 1);
}
fXs1[nVertices - 2] = 0.;
fYs1[nVertices - 2] = yMax;
fXs1[nVertices - 1] = fXs1[0];
fYs1[nVertices - 1] = fYs1[0];
}
{
const Double_t x2Min = xMin + 0.25 * (xMax - xMin);
const Double_t xStep = (xMax - x2Min) / (kNSawPoints - 1);
fXs2.resize(nVertices);
fYs2.resize(nVertices);
fXs2[0] = x2Min;
fYs2[0] = 0.;
for (unsigned i = 1; i <= kNSawPoints; ++i) {
fXs2[i] = x2Min + xStep * i;
}
fXs2[nVertices - 2] = xMax;
fYs2[nVertices - 2] = 0.;
fXs2[nVertices - 1] = fXs2[0];
fYs2[nVertices - 1] = fYs2[0];
}
}
void PolyTest2::Paint(
const Option_t * )
{
assert(
gPad !=
nullptr &&
"Paint, gPad is null");
gPad->PaintFillArea((
Int_t)fXs1.size(), &fXs1[0], &fYs1[0]);
gPad->PaintPolyLine((
Int_t)fXs1.size(), &fXs1[0], &fYs1[0]);
gPad->PaintFillArea((
Int_t)fXs2.size(), &fXs2[0], &fYs2[0]);
gPad->PaintPolyLine((
Int_t)fXs2.size(), &fXs2[0], &fYs2[0]);
}
void polytest2()
{
PolyTest2 * polygon = new PolyTest2;
polygon->Draw();
}
Option_t Option_t SetLineColor
Option_t Option_t SetFillColor
R__EXTERN TRandom * gRandom
Fill Area Attributes class.
virtual void Modify()
Change current fill area attributes if necessary.
virtual void Modify()
Change current line attributes if necessary.
TVirtualPad * cd(Int_t subpadnumber=0) override
Set current canvas & pad.
The TNamed class is the base class for all named ROOT classes.
virtual void Paint(Option_t *option="")
This method must be overridden if a class wants to paint itself.
Double_t Rndm() override
Machine independent random number generator.