<commit_before>// @(#)root/hist:$Id$
// Author: <NAME> 13/07/09

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TGraph.h"
#include "TArrow.h"
#include "TPolyLine.h"
#include "TGraphEdge.h"
#include "TGraphNode.h"

#include <gvc.h>

ClassImp(TGraphEdge);

/** \class TGraphEdge
\ingroup gviz

An edge object connecting two nodes which can be added in a
TGraphStruct.
*/

////////////////////////////////////////////////////////////////////////////////
/// Graph Edge default constructor.

TGraphEdge::TGraphEdge(): TObject(), TAttLine()
{
   fNode1  = 0;
   fNode2  = 0;
   fGVEdge = 0;
   fX      = 0;
   fY      = 0;
   fN      = 0;
   fArrX   = 0;
   fArrY   = 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Graph Edge normal constructor.

TGraphEdge::TGraphEdge(TGraphNode *n1, TGraphNode *n2)
           :TObject(), TAttLine()
{
   fNode1  = n1;
   fNode2  = n2;
   fGVEdge = 0;
   fX      = 0;
   fY      = 0;
   fN      = 0;
   fArrX   = 0;
   fArrY   = 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Graph Edge default destructor.

TGraphEdge::~TGraphEdge()
{
   if (fNode1) delete fNode1;
   if (fNode2) delete fNode2;
   if (fX) { delete [] fX; fX = 0; }
   if (fY) { delete [] fY; fY = 0; }
   if (fN) { delete [] fN; fN = 0; }
}

////////////////////////////////////////////////////////////////////////////////
/// Create the GraphViz edge into the GraphViz data structure gv.

void TGraphEdge::CreateGVEdge(GVizAgraph_t *gv)
{
   if (gv) {
      Agnode_t *n1 = (Agnode_t*)fNode1->GetGVNode();
      Agnode_t *n2 = (Agnode_t*)fNode2->GetGVNode();
#ifdef WITH_CGRAPH
      fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2, NULL, 1);
#else
      fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2);
#endif
   } else {
      Error("CreateGVEdge","Invalid graphviz graph");
   }
}

////////////////////////////////////////////////////////////////////////////////
/// Compute distance from point px,py to an edge.

Int_t TGraphEdge::DistancetoPrimitive(Int_t px, Int_t py)
{
   Int_t i,n,a,dist=999;

   TPolyLine *polyline;
   a = 0;

   for (i=1; i<=fN[0]; i++) {
      n = fN[i];
      polyline = new TPolyLine(n, &fX[a], &fY[a], "L");
      dist = polyline->DistancetoPrimitive(px, py);
      a = a+n;
   }

   return dist;
}

////////////////////////////////////////////////////////////////////////////////
/// Execute action corresponding to one event.

void TGraphEdge::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
   Int_t i,n,a;

   TPolyLine *polyline;
   a = 0;

   for (i=1; i<=fN[0]; i++) {
      n = fN[i];
      polyline = new TPolyLine(n, &fX[a], &fY[a], "L");
      polyline->ExecuteEvent(event, px, py);
      a = a+n;
   }
}

////////////////////////////////////////////////////////////////////////////////
/// Layout this edge in the GraphViz space. This is done after gvLayout
/// has been performed.

void TGraphEdge::Layout()
{
   bezier bz;
   Int_t i,j;

   if (fX) { delete [] fX; fX = 0; }
   if (fY) { delete [] fY; fY = 0; }
   if (fN) { delete [] fN; fN = 0; }

   Int_t np = ED_spl((Agedge_t*)fGVEdge)->size;
   fN       = new Int_t[np+1];
   fN[0]    = np;
   Int_t nb = 0;

   // Compute the total size of the splines arrays<commit_msg>Fix memory leak in TGraphEdge<commit_after>// @(#)root/hist:$Id$
// Author: <NAME> 13/07/09

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#include "TGraph.h"
#include "TArrow.h"
#include "TPolyLine.h"
#include "TGraphEdge.h"
#include "TGraphNode.h"

#include <gvc.h>

ClassImp(TGraphEdge);

/** \class TGraphEdge
\ingroup gviz

An edge object connecting two nodes which can be added in a
TGraphStruct.
*/

////////////////////////////////////////////////////////////////////////////////
/// Graph Edge default constructor.

TGraphEdge::TGraphEdge(): TObject(), TAttLine()
{
   fNode1  = 0;
   fNode2  = 0;
   fGVEdge = 0;
   fX      = 0;
   fY      = 0;
   fN      = 0;
   fArrX   = 0;
   fArrY   = 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Graph Edge normal constructor.

TGraphEdge::TGraphEdge(TGraphNode *n1, TGraphNode *n2)
           :TObject(), TAttLine()
{
   fNode1  = n1;
   fNode2  = n2;
   fGVEdge = 0;
   fX      = 0;
   fY      = 0;
   fN      = 0;
   fArrX   = 0;
   fArrY   = 0;
}

////////////////////////////////////////////////////////////////////////////////
/// Graph Edge default destructor.

TGraphEdge::~TGraphEdge()
{
   if (fNode1) delete fNode1;
   if (fNode2) delete fNode2;
   if (fX) { delete [] fX; fX = 0; }
   if (fY) { delete [] fY; fY = 0; }
   if (fN) { delete [] fN; fN = 0; }
}

////////////////////////////////////////////////////////////////////////////////
/// Create the GraphViz edge into the GraphViz data structure gv.

void TGraphEdge::CreateGVEdge(GVizAgraph_t *gv)
{
   if (gv) {
      Agnode_t *n1 = (Agnode_t*)fNode1->GetGVNode();
      Agnode_t *n2 = (Agnode_t*)fNode2->GetGVNode();
#ifdef WITH_CGRAPH
      fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2, NULL, 1);
#else
      fGVEdge = (GVizAgedge_t*)agedge((Agraph_t *)gv, n1, n2);
#endif
   } else {
      Error("CreateGVEdge","Invalid graphviz graph");
   }
}

////////////////////////////////////////////////////////////////////////////////
/// Compute distance from point px,py to an edge.

Int_t TGraphEdge::DistancetoPrimitive(Int_t px, Int_t py)
{
   Int_t a = 0, dist = 999;

   for (Int_t i = 1; i <= fN[0]; i++) {
      Int_t n = fN[i];
      TPolyLine polyline(n, &fX[a], &fY[a], "L");
      auto d = polyline.DistancetoPrimitive(px, py);
      if (d < dist) dist = d;
      a += n;
   }

   return dist;
}

////////////////////////////////////////////////////////////////////////////////
/// Execute action corresponding to one event.

void TGraphEdge::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{
   Int_t a = 0;

   for (Int_t i = 1; i <= fN[0]; i++) {
      Int_t n = fN[i];
      TPolyLine polyline(n, &fX[a], &fY[a], "L");
      polyline.ExecuteEvent(event, px, py);
      a += n;
   }
}

////////////////////////////////////////////////////////////////////////////////
/// Layout this edge in the GraphViz space. This is done after gvLayout
/// has been performed.

void TGraphEdge::Layout()
{
   bezier bz;
   Int_t i,j;

   if (fX) { delete [] fX; fX = 0; }
   if (fY) { delete [] fY; fY = 0; }
   if (fN) { delete [] fN; fN = 0; }

   Int_t np = ED_spl((Agedge_t*)fGVEdge)->size;
   fN       = new Int_t[np+1];
   fN[0]    = np;
   Int_t nb = 0;

   // Compute the total size of the splines arrays
{'fraction_non_alphanumeric': 0.3092604930046636, 'fraction_numerical': 0.017854763491005995, 'mean_word_length': 1.456151832460733, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4203107', 'n_tokens_mistral': 2593, 'n_tokens_neox': 2471, 'n_words': 631}