Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions graf2d/graf/inc/TLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,25 @@
#include "TObject.h"
#include "TAttLine.h"
#include "TAttBBox2D.h"
#include <memory>

class TPoint;

namespace ROOT {
namespace Internal {
struct TLineInteractive;
}
}

class TLine : public TObject, public TAttLine, public TAttBBox2D {

protected:

Double_t fX1{0}; ///< X of 1st point
Double_t fY1{0}; ///< Y of 1st point
Double_t fX2{0}; ///< X of 2nd point
Double_t fY2{0}; ///< Y of 2nd point
std::unique_ptr<ROOT::Internal::TLineInteractive> fInteractive; ///<! temporary object for interactivity handling
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a strong reason to make it a unique_ptr rather than embedding the fields directly? (or as a struct value)

Sure, you'd have to define the internal class in the header, and it would take up more space in the TLine instance, but is that really a problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mention - I see it as template for other classes.
There one can have big arrays used only during interactivity.
Also for TLine it is an issue - if you have 1000 of them at once.
Use of std::unique_ptr<> introduces only 8 extra bytes in size - which remain constant disregard of complexity of TLineInteractive class


public:
// TLine status bits
Expand All @@ -35,10 +44,10 @@ class TLine : public TObject, public TAttLine, public TAttBBox2D {
kHorizontal = BIT(16) ///< Line is horizontal
};

TLine() {}
TLine();
TLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2);
TLine(const TLine &line);
~TLine() override = default;
~TLine() override;

TLine &operator=(const TLine &src);

Expand All @@ -51,7 +60,7 @@ class TLine : public TObject, public TAttLine, public TAttBBox2D {
Double_t GetX2() const {return fX2;}
Double_t GetY1() const {return fY1;}
Double_t GetY2() const {return fY2;}
Double_t GetSlope() const;
Double_t GetSlope() const;
Double_t GetYIntercept() const;
Bool_t IsHorizontal();
Bool_t IsVertical();
Expand Down
56 changes: 25 additions & 31 deletions graf2d/graf/src/TArrow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ void TArrow::Copy(TObject &obj) const

void TArrow::Draw(Option_t *option)
{
Option_t *opt;
if (option && strlen(option)) opt = option;
else opt = (char*)GetOption();
Option_t *opt = option && *option ? option : GetOption();

AppendPad(opt);
}
Expand All @@ -130,15 +128,15 @@ void TArrow::Draw(Option_t *option)
/// - if `option=""`, `option` will be the current arrow option

TArrow *TArrow::DrawArrow(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
Float_t arrowsize ,Option_t *option)
Float_t arrowsize, Option_t *option)
{

Float_t size = arrowsize;
if (size <= 0) size = fArrowSize;
if (size <= 0) size = 0.05;
const char* opt = option;
if (!opt || !opt[0]) opt = fOption.Data();
if (!opt || !opt[0]) opt = "|>";
Option_t* opt = option;
if (!opt || !*opt) opt = GetOption();
if (!opt || !*opt) opt = "|>";
TArrow *newarrow = new TArrow(x1,y1,x2,y2,size,opt);
newarrow->SetAngle(fAngle);
TAttLine::Copy(*newarrow);
Expand All @@ -154,14 +152,9 @@ TArrow *TArrow::DrawArrow(Double_t x1, Double_t y1,Double_t x2, Double_t y2,
void TArrow::Paint(Option_t *option)
{
if (!gPad) return;
Option_t *opt;
if (option && strlen(option)) opt = option;
else opt = (char*)GetOption();
Option_t *opt = option && *option ? option : GetOption();
if (TestBit(kLineNDC))
PaintArrow(gPad->GetX1() + fX1 * (gPad->GetX2() - gPad->GetX1()),
gPad->GetY1() + fY1 * (gPad->GetY2() - gPad->GetY1()),
gPad->GetX1() + fX2 * (gPad->GetX2() - gPad->GetX1()),
gPad->GetY1() + fY2 * (gPad->GetY2() - gPad->GetY1()), fArrowSize, opt);
PaintArrowNDC(fX1, fY1, fX2, fY2, fArrowSize, opt);
else
PaintArrow(gPad->XtoPad(fX1), gPad->YtoPad(fY1), gPad->XtoPad(fX2), gPad->YtoPad(fY2), fArrowSize, opt);
}
Expand All @@ -173,11 +166,12 @@ void TArrow::PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
Float_t arrowsize, Option_t *option)
{
if (!gPad) return;
auto &parent = *gPad;
// Compute the gPad coordinates in TRUE normalized space (NDC)
Int_t iw = gPad->GetWw();
Int_t ih = gPad->GetWh();
Int_t iw = parent.GetWw();
Int_t ih = parent.GetWh();
Double_t x1p,y1p,x2p,y2p;
gPad->GetPadPar(x1p,y1p,x2p,y2p);
parent.GetPadPar(x1p,y1p,x2p,y2p);
Int_t ix1 = (Int_t)(iw*x1p);
Int_t iy1 = (Int_t)(ih*y1p);
Int_t ix2 = (Int_t)(iw*x2p);
Expand All @@ -187,8 +181,8 @@ void TArrow::PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
// Option and attributes
TString opt = option;
opt.ToLower();
TAttLine::Modify();
TAttFill::Modify();
TAttLine::ModifyOn(parent);
TAttFill::ModifyOn(parent);


Double_t wndc = TMath::Min(1.,(Double_t)iw/(Double_t)ih);
Expand All @@ -202,7 +196,7 @@ void TArrow::PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2,

// Ratios to convert user space in TRUE normalized space (NDC)
Double_t rx1,ry1,rx2,ry2;
gPad->GetRange(rx1,ry1,rx2,ry2);
parent.GetRange(rx1,ry1,rx2,ry2);
Double_t rx = (x2ndc-x1ndc)/(rx2-rx1);
Double_t ry = (y2ndc-y1ndc)/(ry2-ry1);

Expand Down Expand Up @@ -274,7 +268,7 @@ void TArrow::PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
yarr[i] = (1/ry)*(yarr[i]-y1ndc)+ry1;
}
// paint arrow main line with start/stop segment together
gPad->PaintSegments(cnt/2, xarr, yarr);
parent.PaintSegments(cnt/2, xarr, yarr);

// Draw the arrow's head(s)
if (opt.Contains(">")) {
Expand All @@ -295,15 +289,15 @@ void TArrow::PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
y2ar[i] = (1/ry)*(y2ar[i]-y1ndc)+ry1;
}
if (opt.Contains("|>")) {
gPad->GetPainter()->SetLineStyle(1);
parent.GetPainter()->SetLineStyle(1);
if (GetFillColor()) {
gPad->PaintFillArea(3,x2ar,y2ar);
gPad->PaintPolyLine(4,x2ar,y2ar);
parent.PaintFillArea(3,x2ar,y2ar);
parent.PaintPolyLine(4,x2ar,y2ar);
} else {
gPad->PaintPolyLine(4,x2ar,y2ar);
parent.PaintPolyLine(4,x2ar,y2ar);
}
} else {
gPad->PaintPolyLine(3,x2ar,y2ar);
parent.PaintPolyLine(3,x2ar,y2ar);
}
}

Expand All @@ -324,15 +318,15 @@ void TArrow::PaintArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2,
y1ar[i] = (1/ry)*(y1ar[i]-y1ndc)+ry1;
}
if (opt.Contains("<|")) {
gPad->GetPainter()->SetLineStyle(1);
parent.GetPainter()->SetLineStyle(1);
if (GetFillColor()) {
gPad->PaintFillArea(3,x1ar,y1ar);
gPad->PaintPolyLine(4,x1ar,y1ar);
parent.PaintFillArea(3,x1ar,y1ar);
parent.PaintPolyLine(4,x1ar,y1ar);
} else {
gPad->PaintPolyLine(4,x1ar,y1ar);
parent.PaintPolyLine(4,x1ar,y1ar);
}
} else {
gPad->PaintPolyLine(3,x1ar,y1ar);
parent.PaintPolyLine(3,x1ar,y1ar);
}
}
}
Expand Down
Loading
Loading