32 class PolyTest1 :
public TNamed,
public TAttLine,
public TAttFill {
34 PolyTest1(
unsigned nVertices);
36 void Paint(
const Option_t *notUsed);
37 void Reset(
unsigned nVertices);
41 kNPointsDefault = 10000
44 std::vector<Double_t> fXs;
45 std::vector<Double_t> fYs;
49 PolyTest1::PolyTest1(
unsigned nVertices)
50 : TNamed(
"polygon_compression_test1",
"polygon_compression_test1")
56 void PolyTest1::Reset(
unsigned nVertices)
59 assert(gPad != 0 &&
"Reset, gPad is null");
61 assert(gRandom != 0 &&
"Reset, gRandom is null");
63 if (nVertices < kNPointsDefault) {
64 Warning(
"Reset",
"resetting nVertices parameter to %u",
unsigned(kNPointsDefault));
65 nVertices = kNPointsDefault;
68 fXs.resize(nVertices);
69 fYs.resize(nVertices);
71 Double_t xMin = 0., xMax = 0., yMin = 0., yMax = 0.;
72 gPad->GetRange(xMin, yMin, xMax, yMax);
73 assert(xMax - xMin > 0 && yMax - yMin > 0 &&
"Reset, invalid canvas' ranges");
75 const Double_t xCentre = xMin + 0.5 * (xMax - xMin);
76 const Double_t yCentre = yMin + 0.5 * (yMax - yMin);
78 const Double_t r = TMath::Min(xMax - xMin, yMax - yMin) * 0.8 / 2;
79 const Double_t angle = TMath::TwoPi() / (nVertices - 1);
81 for (
unsigned i = 0; i < nVertices - 1; ++i) {
82 const Double_t currR = r + gRandom->Rndm() * r * 0.01;
83 fXs[i] = xCentre + currR * TMath::Cos(angle * i);
84 fYs[i] = yCentre + currR * TMath::Sin(angle * i);
87 fXs[nVertices - 1] = fXs[0];
88 fYs[nVertices - 1] = fYs[0];
92 void PolyTest1::Paint(
const Option_t * )
94 assert(gPad != 0 &&
"Paint, gPad is null");
97 gPad->PaintFillArea((Int_t)fXs.size(), &fXs[0], &fYs[0]);
100 gPad->PaintPolyLine((Int_t)fXs.size(), &fXs[0], &fYs[0]);
105 TCanvas *
const cnv =
new TCanvas;
108 PolyTest1 * polygon =
new PolyTest1(1000000);
109 polygon->SetLineColor(kBlue);
110 polygon->SetFillColor(kRed);
111 polygon->SetLineWidth(1);