1
////////////////////////////////////////////////////////////////////////////////
2
/*! @file Curves.cpp Абстракция кривых и функций.
3
- Part of RANet - Research Assistant Net Library (based on ANSI C++).
4
- Copyright(C) 2000-2010, Viktor E. Bursian, St.Petersburg, Russia.
5
Viktor.Bursian@mail.ioffe.ru
6
*///////////////////////////////////////////////////////////////////////////////
12
//------------------------------------------------------------------------------
14
DEFINE_CLASS_TAG(sCurveAppearance)
15
DEFINE_CLASS_TAG(sCurve)
17
//--------------------------------------------------------- sCurveAppearance ---
19
sCurveAppearance::sCurveAppearance ()
25
sCurveAppearance::sCurveAppearance (rsObjectStream S)
33
void sCurveAppearance::Store (rsObjectStream S)
35
sAppearance::Store(S);
41
//------------------------------------------------------------------- sCurve ---
43
sCurve::sCurve (rsObjectStream a_stream)
44
:s2DVisibleObject(a_stream)
50
void sCurve::Store (rsObjectStream a_stream)
52
s2DVisibleObject::Store(a_stream);
53
sRecord::Store(a_stream);
57
sString sCurve::Text (eTextFormat F
58
,eTextDetalization D) const
61
psCurveAppearance A = dynamic_cast<psCurveAppearance>(Appearance);
62
if( A && (F == HTML) ){
64
T += A->/*Line.*/Color.TagForHTML();
67
return T + sRecord::Text(F,D);
71
void sCurve::AssignIntrinsicContent (sNodePtr NP)
73
sRecord::AssignIntrinsicContent(NP);
74
// if( NP->OwnType() <= sCurve::Type ){
79
sBoundaries sCurve::Boundaries ()
81
sCurve::psTracer T = GetCurveTracer();
89
Xmin = Xmax = T->Point.X;
90
Ymin = Ymax = T->Point.Y;
91
while( T->NextPoint() ){
92
if( T->Point.X < Xmin ){
94
}else if( Xmax < T->Point.X ){
97
if( T->Point.Y < Ymin ){
99
}else if( Ymax < T->Point.Y ){
103
B = sBoundaries( sRange(Xmin,Xmax) , sRange(Ymin,Ymax) );
106
while( T->NextLineSegment() ){
107
if( T->LineSegment.Start.X < B.X.From ){
108
B.X.From=T->LineSegment.Start.X;
109
}else if( T->LineSegment.Start.X > B.X.To ){
110
B.X.To=T->LineSegment.Start.X;
112
if( T->LineSegment.Start.Y < B.Y.From ){
113
B.Y.From=T->LineSegment.Start.Y;
114
}else if( T->LineSegment.Start.Y > B.Y.To ){
115
B.Y.To=T->LineSegment.Start.Y;
117
if( T->LineSegment.End.X < B.X.From ){
118
B.X.From=T->LineSegment.End.X;
119
}else if( T->LineSegment.End.X > B.X.To ){
120
B.X.To=T->LineSegment.End.X;
122
if( T->LineSegment.End.Y < B.Y.From ){
123
B.Y.From=T->LineSegment.End.Y;
124
}else if( T->LineSegment.End.Y > B.Y.To ){
125
B.Y.To=T->LineSegment.End.Y;
129
if( T ){ delete T; T=NULL; };
134
bool sCurve::IsUnambigousFunction () const
140
real sCurve::Value (real /*X*/) const
147
int sCurve::Distance (sPoint P
151
sCurve::psTracer T = GetCurveTracer();
156
DD_min= real(std::numeric_limits<int>::max())
157
* real(std::numeric_limits<int>::max());
158
while( T->NextPoint() ){
159
DD=((P.X - T->Point.X)/XPixelValue)*((P.X - T->Point.X)/XPixelValue)
160
+((P.Y - T->Point.Y)/YPixelValue)*((P.Y - T->Point.Y)/YPixelValue);
165
while( T->NextLineSegment() ){
167
PP.X = (PP.X - T->LineSegment.Start.X) / XPixelValue;
168
PP.Y = (PP.Y - T->LineSegment.Start.Y) / YPixelValue;
169
LX = (T->LineSegment.End.X - T->LineSegment.Start.X) / XPixelValue;
170
LY = (T->LineSegment.End.Y - T->LineSegment.Start.Y) / YPixelValue;
171
L = sqrt(LX*LX+LY*LY);
172
PPP.X = (LX/L)*PP.X + (LY/L)*PP.Y;
173
PPP.Y = (LY/L)*PP.X - (LX/L)*PP.Y;
175
DD = PPP.X*PPP.X + PPP.Y*PPP.Y;
176
}else if( PPP.X > L ){
177
DD = (PPP.X-L)*(PPP.X-L) + PPP.Y*PPP.Y;
185
if( T ){ delete T; T=NULL; };
187
return Round(sqrt(DD_min));
189
return std::numeric_limits<int>::max();
193
//------------------------------------------------------------------------------