]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/AliMUONSegment.cxx
Fixing anti-aliasing problem on MacOSX
[u/mrichter/AliRoot.git] / MUON / AliMUONSegment.cxx
CommitLineData
0b936dc0 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15
16// $Id$
17
18/// \class AliMUONSegment
19///
20/// A basic line segment, to be used in contour making algorithms.
21///
22/// In particular, this class defines what a left or right edge is.
23///
24/// Also, please note that, due to the way Root collections are sorted (relying
25/// on TObject::Compare method), the way the AliMUONSegment::Compare method
26/// is implemented below is really important when it comes to understand
27/// contour making algorithm. Keep that in mind.
28///
29/// \author Laurent Aphecetche, Subatech
30///
31
32#include "AliMUONSegment.h"
33
34#include "TMath.h"
35#include "Riostream.h"
36#include "AliMpConstants.h"
37
b80faac0 38using std::cout;
39using std::endl;
0b936dc0 40/// \cond CLASSIMP
41ClassImp(AliMUONSegment)
42/// \endcond
43
44const Double_t AliMUONSegment::fgkPrecision(AliMpConstants::LengthTolerance());
45
46//_____________________________________________________________________________
47AliMUONSegment::AliMUONSegment() :
48TObject(),
49fStartX(), fStartY(), fEndX(), fEndY(), fSmallerY(), fIsHorizontal(), fIsVertical(),
50fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
51{
52 /// Ctor
53 Set(fStartX,fStartY,fEndX,fEndY);
54}
55
56//_____________________________________________________________________________
57AliMUONSegment::AliMUONSegment(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
58: TObject(),
59fStartX(xstart), fStartY(ystart), fEndX(xend), fEndY(yend), fSmallerY(), fIsHorizontal(), fIsVertical(),
60fIsLeftEdge(), fIsRightEdge(), fIsAPoint(kTRUE)
61{
62 /// Ctor
63 Set(xstart,ystart,xend,yend);
64}
65
66//_____________________________________________________________________________
67Bool_t
68AliMUONSegment::AreEqual(double a, double b)
69{
70 /// Whether the two floats are equal within the given precision
71 return (TMath::Abs(b-a) < fgkPrecision);
72}
73
74//_____________________________________________________________________________
75Int_t
76AliMUONSegment::Compare(const TObject* obj) const
77{
78 /// Compare method, which sort segments in ascending x order
79 /// if same x, insure that left edges are before right edges
80 /// within same x, order by increasing bottommost y
81 /// Mind your steps ! This method is critical to the contour merging algorithm !
82
83 const AliMUONSegment* rhs = static_cast<const AliMUONSegment*>(obj);
84
85 if ( AreEqual(StartX(),rhs->StartX()) )
86 {
87 if ( IsLeftEdge() && rhs->IsRightEdge() ) return -1;
88 if ( IsRightEdge() && rhs->IsLeftEdge() ) return 1;
89 if ( SmallerY() < rhs->SmallerY() ) return -1;
90 if ( SmallerY() > rhs->SmallerY() ) return 1;
91 return 0;
92 }
93 else if ( StartX() < rhs->StartX() )
94 {
95 return -1;
96 }
97 else //if ( StartX() > rhs->StartX() )
98 {
99 return 1;
100 }
101}
102
103//_____________________________________________________________________________
104double AliMUONSegment::Top() const
105{
106 /// Max Y of the segment
107 return TMath::Max(fStartY,fEndY);
108}
109
110//_____________________________________________________________________________
111double AliMUONSegment::Distance() const
112{
113 /// Length of the segment
114 return TMath::Sqrt((fStartX-fEndX)*(fStartX-fEndX) +
115 (fStartY-fEndY)*(fStartY-fEndY));
116}
117
118//_____________________________________________________________________________
119void AliMUONSegment::Print(Option_t*) const
120{
121 /// Printout
122 cout << AsString() << endl;
123}
124
125//_____________________________________________________________________________
126const char* AliMUONSegment::AsString() const
127{
128 /// Return a string representation of this object
129 return Form("[ (%10.5f,%10.5f) -> (%10.5f,%10.5f) %s ] (d=%e)",fStartX,fStartY,fEndX,fEndY,
130 IsLeftEdge() ? "L" : ( IsRightEdge() ? "R" : ( IsHorizontal() ? "H" : "" )),
131 Distance() );
132}
133
134//_____________________________________________________________________________
135void
136AliMUONSegment::Set(Double_t xstart, Double_t ystart, Double_t xend, Double_t yend)
137{
138 /// Set start and end point, and (re)compute internal values
139 fStartX = xstart;
140 fEndX = xend;
141 fStartY = ystart;
142 fEndY = yend;
143 fSmallerY = TMath::Min(fStartY,fEndY);
144 fIsHorizontal = AreEqual(fStartY,fEndY);
145 fIsVertical = AreEqual(fStartX,fEndX);
146 fIsLeftEdge = fIsVertical && ( fStartY > fEndY );
147 fIsRightEdge = fIsVertical && ( fStartY < fEndY );
148 fIsAPoint = ( Distance() < fgkPrecision );
149}
150