1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
|
////////////////////////////////////////////////////////////////////////////////
/*! @file Curves.cpp
- Part of RANet - Research Assistant Net Library.
- Copyright(C) 2000-2015, Viktor E. Bursian, St.Petersburg, Russia.
Viktor_dot_Bursian_at_mail_dot_ioffe_dot_ru
*///////////////////////////////////////////////////////////////////////////////
#include "Curves.h"
#include "Symbols.h"
#include "Excepts.h"
#include "Log.h"
#include "Trace.h"
#include <math.h>
#include <limits>
namespace RA {
//------------------------------------------------------------------------------
//--------------------------------------------------------- sCurveAppearance ---
sCurveAppearance::sCurveAppearance ()
:sAppearance()
,sLineAppearance()
,sPointAppearance()
,ShowLine(true)
,ShowPoints(false)
{
}
sCurveAppearance::sCurveAppearance(rcsColor color)
:sAppearance()
,sLineAppearance(color)
,sPointAppearance(color)
,ShowLine(true)
,ShowPoints(false)
{
}
sCurveAppearance::sCurveAppearance(rcsColor color
,byte line_thickness
,eLineStyle line_style)
:sAppearance()
,sLineAppearance(color,line_thickness,line_style)
,sPointAppearance(color)
,ShowLine(true)
,ShowPoints(false)
{
}
sCurveAppearance::sCurveAppearance (byte point_size
,rcsColor point_color
,eShape point_shape
)
:sAppearance()
,sLineAppearance(point_color)
,sPointAppearance(point_color,point_size,point_shape)
,ShowLine(false)
,ShowPoints(true)
{
}
sCurveAppearance::sCurveAppearance (std::istream & a_stream ,rcsVersion version)
:sStorable()
,sAppearance()
,sLineAppearance()
,sPointAppearance()
{
if( version < sVersion(1,1) ){
byte U,R,G,B;
a_stream.READ_INTO(U);
a_stream.READ_INTO(R);
a_stream.READ_INTO(G);
a_stream.READ_INTO(B);
LineColor = sColor(R,G,B);
for( int i = 0 ; i < 17 ; i++ ) a_stream.READ_INTO(U);
Hidden = false;
LineThickness=DefaultLineThickness;
LineStyle=DefaultLineStyle;
FillColor=LineColor;
ContourColor=LineColor;
Filled=true;
Contoured=false;
ContourThickness=LineThickness;
PointSize=DefaultSize;
PointShape=DefaultShape;
ShowLine=true;
ShowPoints=false;
}else{
{
sLineAppearance LA(a_stream,version);
Hidden = LA.Hidden;
LineColor = LA.LineColor;
LineThickness = LA.LineThickness;
LineStyle = LA.LineStyle;
}
{ sColor C(a_stream,version); FillColor=C; }
{ sColor C(a_stream,version); ContourColor=C; }
a_stream.READ_INTO(Filled);
a_stream.READ_INTO(Contoured);
a_stream.READ_INTO(ContourThickness);
a_stream.READ_INTO(PointSize);
a_stream.READ_INTO(PointShape);
a_stream.READ_INTO(ShowLine);
a_stream.READ_INTO(ShowPoints);
}
}
void sCurveAppearance::Store (std::ostream & a_stream) const
{
sLineAppearance::Store(a_stream);
/*! @todo{bomb} Be careful with storing/loading classes with virtual bases:
this should be unified, say, as a call to
sPointAppearance::Store(a_stream,sStorable::cOmitVirtualBases); */
{
FillColor.Store(a_stream);
ContourColor.Store(a_stream);
a_stream.WRITE_FROM(Filled);
a_stream.WRITE_FROM(Contoured);
a_stream.WRITE_FROM(ContourThickness);
a_stream.WRITE_FROM(PointSize);
a_stream.WRITE_FROM(PointShape);
}
a_stream.WRITE_FROM(ShowLine);
a_stream.WRITE_FROM(ShowPoints);
}
//psAppearance sCurveAppearance::AssignFrom (pcsAppearance other)
//{
// sLineAppearance::AssignFrom(other);
// sPointAppearance::AssignFrom(other);
// if( pcsCurveAppearance A = dynamic_cast<pcsCurveAppearance>(other) ){
// ShowLine = A->ShowLine;
// ShowPoints = A->ShowPoints;
// }
// return this;
//}
//------------------------------------------------------------------- sCurve ---
sCurve::sCurve (std::istream & a_stream ,rcsVersion version)
:sGraphObject(a_stream,version)
{
}
void sCurve::Store (std::ostream & a_stream) const
{
sGraphObject::Store(a_stream);
}
int sCurve::Distance (rcsIntPoint position
,rcsScales scales )
{
sCurve::psTracer T = GetCurveTracer(scales);
int D_min = std::numeric_limits<int>::max();
// P -- точка с координатами position
sPoint R; //вектор, идущий из точки кривой в точку P
sPoint L; //вектор отрезка кривой
real LengthL; //его длина
sPoint PP; //вектор, идущий из начала отрезка кривой
//в точку P
sPoint PPP; //координаты точки P в системе координат,
//повёрнутой так, что ось х совмещена с
//с вектором L
real DD_min ,DD;
DD_min= real(std::numeric_limits<int>::max())
* real(std::numeric_limits<int>::max());
while( T->NextPoint() ){
R = position - scales.T(T->Point);
DD=R.X*R.X+R.Y*R.Y;
if( DD < DD_min ){
DD_min=DD;
}
}
while( T->NextLineSegment() ){
PP = position - scales.T(T->LineSegment.Start);
L = scales.T(T->LineSegment.End) - scales.T(T->LineSegment.Start);
LengthL = sqrt(L.X*L.X+L.Y*L.Y);
PPP.X = (L.X/LengthL)*PP.X + (L.Y/LengthL)*PP.Y;
PPP.Y = (L.Y/LengthL)*PP.X - (L.X/LengthL)*PP.Y;
if( PPP.X < 0 ){
DD = PPP.X*PPP.X + PPP.Y*PPP.Y;
}else if( PPP.X > LengthL ){
DD = (PPP.X-LengthL)*(PPP.X-LengthL) + PPP.Y*PPP.Y;
}else{
DD = PPP.Y*PPP.Y;
}
if( DD < DD_min ){
DD_min=DD;
}
}
try{
D_min = std::min( D_min , Round(sqrt(DD_min)) );
}catch(...){
}
if( T ){ delete T; T=NULL; }
return D_min;
}
//------------------------------------------------------------------------------
} //namespace RA
|