-
Notifications
You must be signed in to change notification settings - Fork 1
/
Units.cs
564 lines (529 loc) · 13.1 KB
/
Units.cs
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Drawing;
namespace MicroscopeConsole
{
[Serializable]
public struct PointF
{
private float x, y;
public float X
{
set
{
x = value;
}
get
{
return x;
}
}
public float Y
{
set
{
y = value;
}
get
{
return y;
}
}
public PointF(float xx, float yy)
{
x = xx;
y = yy;
}
public static PointF Parse(string s)
{
string[] st = s.Split(',');
float xd = float.Parse(st[0], CultureInfo.InvariantCulture);
float yd = float.Parse(st[1], CultureInfo.InvariantCulture);
return new PointF(xd, yd);
}
public PointF ToPointF()
{
return new PointF((float)X, (float)Y);
}
public Point ToPointInt()
{
return new Point((int)X, (int)Y);
}
public static bool operator ==(PointF p1, PointF p2)
{
return (p1.X == p2.X && p1.Y == p2.Y);
}
public static bool operator !=(PointF p1, PointF p2)
{
return (p1.X != p2.X && p1.Y != p2.Y);
}
public override string ToString()
{
return X.ToString() + "," + Y.ToString();
}
}
[Serializable]
public struct PointD
{
private static double minX = -80000;
private static double minY = -58000;
private static double maxX = 80000;
private static double maxY = 58000;
public static double MinX
{
get
{
return minX;
}
}
public static double MinY
{
get
{
return minY;
}
}
public static double MaxX
{
get
{
return maxX;
}
}
public static double MaxY
{
get
{
return maxY;
}
}
public static PointD Min
{
get
{
return new PointD(MinX, MinY);
}
}
public static PointD Max
{
get
{
return new PointD(MaxX, MaxY);
}
}
public static bool InLimits(PointD p)
{
if (p.X < minX || p.X > maxX)
{
return false;
}
if (p.X < minY || p.X > maxY)
{
return false;
}
return true;
}
public static bool InLimitX(double px)
{
if (px < minX || px > maxX)
{
return false;
}
return true;
}
public static bool InLimitY(double py)
{
if (py < minY || py > maxY)
{
return false;
}
return true;
}
private double x, y;
public static void SetLimits(double pminX, double pmaxX, double pminY, double pmaxY)
{
minX = pminX;
minY = pminY;
maxX = pmaxX;
maxY = pmaxY;
}
public double X
{
set
{
x = value;
}
get
{
return x;
}
}
public double Y
{
set
{
y = value;
}
get
{
return y;
}
}
public PointD(double xx, double yy)
{
x = xx;
y = yy;
}
public static PointD Parse(string s)
{
string[] st = s.Split(',');
double xd = double.Parse(st[0], CultureInfo.InvariantCulture);
double yd = double.Parse(st[1], CultureInfo.InvariantCulture);
return new PointD(xd, yd);
}
public PointF ToPointF()
{
return new PointF((float)X, (float)Y);
}
public Point ToPointInt()
{
return new Point((int)X, (int)Y);
}
public static bool operator ==(PointD p1, PointD p2)
{
return (p1.X == p2.X && p1.Y == p2.Y);
}
public static bool operator !=(PointD p1, PointD p2)
{
return (p1.X != p2.X && p1.Y != p2.Y);
}
public override string ToString()
{
return X.ToString() + "," + Y.ToString();
}
}
[Serializable]
public struct Point3D
{
private static double minX = -80000;
private static double minY = -58000;
private static double maxX = 80000;
private static double maxY = 58000;
private static double maxZ = 25000;
private static double minZ = -25000;
public static string File = "";
public static void SetLimits(double pminX,double pmaxX,double pminY,double pmaxY,double pminZ,double pmaxZ)
{
minX = pminX;
minY = pminY;
minZ = pminZ;
maxX = pmaxX;
maxY = pmaxY;
maxZ = pmaxZ;
}
public static double MinX
{
get
{
return minX;
}
}
public static double MinY
{
get
{
return minY;
}
}
public static double MinZ
{
get
{
return minZ;
}
}
public static double MaxX
{
get
{
return maxX;
}
}
public static double MaxY
{
get
{
return maxY;
}
}
public static double MaxZ
{
get
{
return maxZ;
}
}
private double x, y, z;
public double X
{
set
{
x = value;
}
get
{
return x;
}
}
public double Y
{
set
{
y = value;
}
get
{
return y;
}
}
public double Z
{
set
{
z = value;
}
get
{
return z;
}
}
public static bool InLimits(Point3D p)
{
if (p.X < minX || p.X > maxX)
{
return false;
}
if (p.X < minY || p.X > maxY)
{
return false;
}
if (p.X < minZ || p.X > maxZ)
{
return false;
}
return true;
}
public static bool InLimitX(double px)
{
if (px < minX || px > maxX)
{
return false;
}
return true;
}
public static bool InLimitY(double py)
{
if (py < minY || py > maxY)
{
return false;
}
return true;
}
public static bool InLimitZ(double pz)
{
if (pz < minY || pz > maxZ)
{
return false;
}
return true;
}
public Point3D(double xd, double yd,double zd)
{
x = xd;
y = yd;
z = zd;
}
public Point3D(double xd, double yd, double zd,string f)
{
x = xd;
y = yd;
z = zd;
File = f;
}
public static Point3D Parse(string s)
{
string[] st = s.Split(',');
double xd = double.Parse(st[0], CultureInfo.InvariantCulture);
double yd = double.Parse(st[1], CultureInfo.InvariantCulture);
double zd = double.Parse(st[2], CultureInfo.InvariantCulture);
return new Point3D(xd, yd, zd);
}
public override string ToString()
{
if (File == "")
return X.ToString() + ", " + Y.ToString() + ", " + Z.ToString();
else
return X.ToString() + ", " + Y.ToString() + ", " + Z.ToString() + ", " + File;
}
public static double Distance(Point3D p0,Point3D p1)
{
double deltaX = p1.X - p0.X;
double deltaY = p1.Y - p0.Y;
double deltaZ = p1.Z - p0.Z;
float distance = (float)System.Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
return distance;
}
}
[Serializable]
public struct VolumeD
{
public VolumeD(Point3D loc, Point3D s)
{
location = loc;
size = s;
}
private Point3D location;
public Point3D Location
{
get
{
return location;
}
set
{
location = value;
}
}
private Point3D size;
public Point3D Size
{
get
{
return size;
}
set
{
size = value;
}
}
public double Width
{
get
{
return size.X;
}
set
{
size.X = value;
}
}
public double Height
{
get
{
return size.Y;
}
set
{
size.Y = value;
}
}
public double Depth
{
get
{
return size.Z;
}
set
{
size.Z = value;
}
}
public bool Intersects(PointF p)
{
if ((p.X > Location.X && p.X < (Location.X + Width)) && (p.Y > Location.Y && p.Y < (Location.Y + Height)))
{
return true;
}
else
return false;
}
public bool Intersects(PointD p)
{
if ((p.X > Location.X && p.X < (Location.X + Width)) && (p.Y > Location.Y && p.Y < (Location.Y + Height)))
{
return true;
}
else
return false;
}
public bool Intersects(Point3D p)
{
if ((p.X > Location.X && p.X < (Location.X + Width)) && (p.Y > Location.Y && p.Y < (Location.Y + Height)) && (p.Z > Location.Z && p.Z < (Location.Z + Depth)))
{
return true;
}
else
return false;
}
public bool Intersects(RectangleD rec)
{
if (Intersects(new PointD(rec.X, rec.Y)) || Intersects(new PointD(rec.X + rec.W, rec.Y)) || Intersects(new PointD(rec.X, rec.Y + rec.H)) || Intersects(new PointD(rec.X + rec.W, rec.Y + rec.H)))
return true;
else
return false;
}
}
public struct RectangleD
{
private double x;
private double y;
private double w;
private double h;
public double X { get { return x; } set { x = value; } }
public double Y { get { return y; } set { y = value; } }
public double W { get { return w; } set { w = value; } }
public double H { get { return h; } set { h = value; } }
public RectangleD(double X, double Y, double W, double H)
{
x = X;
y = Y;
w = W;
h = H;
}
public System.Drawing.Rectangle ToRectangleInt()
{
return new System.Drawing.Rectangle((int)X, (int)Y, (int)W, (int)H);
}
public bool IntersectsWith(RectangleD p)
{
if (IntersectsWith(p.X, p.Y) || IntersectsWith(p.X + p.W, p.Y) || IntersectsWith(p.X, p.Y + p.H) || IntersectsWith(p.X + p.W, p.Y + p.H))
return true;
else
return false;
}
public bool IntersectsWith(PointD p)
{
return IntersectsWith(p.X, p.Y);
}
public bool IntersectsWith(double x, double y)
{
if (X <= x && (X + W) >= x && Y <= y && (Y + H) >= y)
return true;
else
return false;
}
public RectangleF ToRectangleF()
{
return new RectangleF((float)X, (float)Y, (float)W, (float)H);
}
public override string ToString()
{
return X.ToString() + ", " + Y.ToString() + ", " + W.ToString() + ", " + H.ToString();
}
}
}