-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathNetOnDouble.cs
125 lines (113 loc) · 4.03 KB
/
NetOnDouble.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace МатКлассы
{
/// <summary>
/// Сетка на отрезке действительной оси
/// </summary>
public sealed class NetOnDouble:Idup<NetOnDouble>
{
/// <summary>
/// Начало отрезка
/// </summary>
public readonly double Begin;
/// <summary>
/// Конец отрезка
/// </summary>
public readonly double End;
/// <summary>
/// Число точек в сетке (включая начало отрезка и конец, второе если WithEnd=true)
/// </summary>
public readonly int Count;
/// <summary>
/// Шаг по отрезку, расстояние между соседними точками
/// </summary>
public readonly double Step;
/// <summary>
/// Флаг, указывающий, содержит ли сетка конец отрезка
/// </summary>
public readonly bool WithEnd;
/// <summary>
/// Создать сетку по параметрам
/// </summary>
/// <param name="begin">Начало отрезка</param>
/// <param name="end">Конец отрезка</param>
/// <param name="count">Число точек в сетке</param>
/// <param name="withend">Включать ли конец отрезка в сетку</param>
public NetOnDouble(double begin, double end, int count, bool withend = true)
{
Begin = begin;
End = end;
Count = count;
WithEnd = withend;
if (WithEnd)
Step = (End - Begin) / (Count - 1);
else
Step = (End - Begin) / Count;
}
/// <summary>
/// Создать отрезок по концам и шагу
/// </summary>
/// <param name="begin">Начало отрезка</param>
/// <param name="end">Конец отрезка</param>
/// <param name="step">Шаг</param>
public NetOnDouble(double begin, double end, double step)
{
Begin = begin;
Count = (int)Math.Floor(Math.Abs(end - begin) / step)+1;
Step = step;
End = end;
WithEnd = begin + step * Count == end;
}
private NetOnDouble(NetOnDouble netOnDouble)
{
Begin = netOnDouble.Begin;
End = netOnDouble.End;
Count = netOnDouble.Count;
Step = netOnDouble.Step;
WithEnd = netOnDouble.WithEnd;
}
/// <summary>
/// Копия сетки, но с другим числом узлов
/// </summary>
/// <param name="netOnDouble"></param>
/// <param name="newCount"></param>
public NetOnDouble(NetOnDouble netOnDouble,int newCount) : this(netOnDouble)
{
Count = newCount;
if (WithEnd)
Step = (End - Begin) / (Count - 1);
else
Step = (End - Begin) / Count;
}
private double[] arr = null;
/// <summary>
/// Сам массив сетки
/// </summary>
public double[] Array
{
get
{
if (arr == null)
arr = Enumerable.Range(0, Count).Select(i => Begin + i * Step).ToArray();
return arr;
}
}
public NetOnDouble dup => new NetOnDouble(this);
/// <summary>
/// Длина отрезка для сетки
/// </summary>
public double Range => Math.Abs(Begin - End);
/// <summary>
/// Середина отрезка
/// </summary>
public double Center => (Begin + End) / 2;
public void MoveTo(NetOnDouble t)
{
throw new NotImplementedException();
}
}
}