Skip to content

Commit f108cbb

Browse files
authored
Fix pixel conversion
* fix pixel conversion * clang format and abs in TAttText
1 parent 97639fd commit f108cbb

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

core/base/inc/TVirtualPad.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ class TVirtualPad : public TObject, public TAttLine, public TAttFill,
257257
virtual Int_t VtoPixel(Double_t v) const = 0;
258258
virtual Int_t XtoAbsPixel(Double_t x) const = 0;
259259
virtual Int_t YtoAbsPixel(Double_t y) const = 0;
260+
virtual Int_t HtoAbsPixel(Double_t y1, Double_t y2) const = 0;
261+
virtual Int_t WtoAbsPixel(Double_t x1, Double_t x2) const = 0;
260262
virtual void XYtoAbsPixel(Double_t x, Double_t y, Int_t &xpixel, Int_t &ypixel) const = 0;
261263
virtual void XYtoAbsPixel(Double_t x, Double_t y, Double_t &xpixel, Double_t &ypixel) const = 0;
262264
virtual Double_t XtoPad(Double_t x) const = 0;

core/base/src/TAttText.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,8 @@ Float_t TAttText::GetTextSizePercent(Float_t size)
311311
{
312312
Float_t rsize = size;
313313
if (fTextFont%10 > 2 && gPad) {
314-
UInt_t w = std::abs(gPad->XtoAbsPixel(gPad->GetX2()) -
315-
gPad->XtoAbsPixel(gPad->GetX1()));
316-
UInt_t h = std::abs(gPad->YtoAbsPixel(gPad->GetY2()) -
317-
gPad->YtoAbsPixel(gPad->GetY1()));
314+
UInt_t w = gPad->WtoAbsPixel(gPad->GetX1(), gPad->GetX2());
315+
UInt_t h = gPad->HtoAbsPixel(gPad->GetY1(), gPad->GetY2());
318316
if (w < h)
319317
rsize = rsize/w;
320318
else

graf2d/gpad/inc/TPad.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ friend class TWebCanvas;
379379
TObject *WaitPrimitive(const char *pname="", const char *emode="") override;
380380
Int_t XtoAbsPixel(Double_t x) const override;
381381
Int_t YtoAbsPixel(Double_t y) const override;
382+
Int_t HtoAbsPixel(Double_t y1, Double_t y2) const override;
383+
Int_t WtoAbsPixel(Double_t x1, Double_t x2) const override;
382384
Double_t XtoPad(Double_t x) const override;
383385
Double_t YtoPad(Double_t y) const override;
384386
Int_t XtoPixel(Double_t x) const override;

graf2d/gpad/src/TPad.cxx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7652,6 +7652,27 @@ Int_t TPad::YtoAbsPixel(Double_t y) const
76527652
return TMath::Nint(pixel_boundary(fYtoAbsPixelk + y*fYtoPixel));
76537653
}
76547654

7655+
////////////////////////////////////////////////////////////////////////////////
7656+
/// Convert a vertical distance [y1,y2] to pixel
7657+
7658+
Int_t TPad::HtoAbsPixel(Double_t y1, Double_t y2) const
7659+
{
7660+
double h1 = fYtoAbsPixelk + y1 * fYtoPixel;
7661+
double h2 = fYtoAbsPixelk + y2 * fYtoPixel;
7662+
return TMath::Nint(pixel_boundary(std::abs(h1 - h2)));
7663+
}
7664+
7665+
////////////////////////////////////////////////////////////////////////////////
7666+
/// Convert a horizontal distance [x1,x2] to pixel
7667+
7668+
Int_t TPad::WtoAbsPixel(Double_t x1, Double_t x2) const
7669+
{
7670+
double w1 = fXtoAbsPixelk + x1 * fXtoPixel;
7671+
double w2 = fXtoAbsPixelk + x2 * fXtoPixel;
7672+
return TMath::Nint(pixel_boundary(std::abs(w1 - w2)));
7673+
}
7674+
7675+
76557676
////////////////////////////////////////////////////////////////////////////////
76567677
/// Convert Y coordinate to pixel
76577678

0 commit comments

Comments
 (0)