Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GeoBoundingBox.cs
1using System;
2using System.Text;
3
5{
9 public sealed class GeoBoundingBox : IGeoBoundingBox
10 {
11 private readonly GeoPosition min;
12 private readonly GeoPosition max;
13 private readonly string boxId;
14 private readonly bool includeMin;
15 private readonly bool includeMax;
16
23 : this(Min, Max, true, true)
24 {
25 }
26
35 : this(Guid.NewGuid().ToString(), Min, Max, IncludeMin, IncludeMax)
36 {
37 }
38
46 : this(BoxId, Min, Max, true, true)
47 {
48 }
49
59 {
60 this.boxId = BoxId;
61 this.min = Min;
62 this.max = Max;
63 this.includeMin = IncludeMin;
64 this.includeMax = IncludeMax;
65 }
69 public string BoxId => this.boxId;
70
74 public GeoPosition Min => this.min;
75
79 public GeoPosition Max => this.max;
80
84 public bool IncludeMin => this.includeMin;
85
89 public bool IncludeMax => this.includeMax;
90
95 public bool LongitudeWrapped
96 {
97 get
98 {
99 return
100 !(this.min is null) &&
101 !(this.max is null) &&
102 this.min.Longitude > this.max.Longitude;
103 }
104 }
105
107 public override string ToString()
108 {
109 StringBuilder sb = new StringBuilder();
110
111 if (this.includeMin)
112 sb.Append('[');
113 else
114 sb.Append('(');
115
116 sb.Append(this.min?.ToString());
117 sb.Append(" - ");
118 sb.Append(this.max?.ToString());
119
120 if (this.includeMax)
121 sb.Append(']');
122 else
123 sb.Append(')');
124
125 return sb.ToString();
126 }
127
129 public string ToNormalizedString()
130 {
131 StringBuilder sb = new StringBuilder();
132
133 if (this.includeMin)
134 sb.Append('[');
135 else
136 sb.Append('(');
137
138 sb.Append(this.min?.NormalizedValue);
139 sb.Append(" - ");
140 sb.Append(this.max?.NormalizedValue);
141
142 if (this.includeMax)
143 sb.Append(']');
144 else
145 sb.Append(')');
146
147 return sb.ToString();
148 }
149
151 public override bool Equals(object obj)
152 {
153 return
154 obj is GeoBoundingBox Obj &&
155 (this.min?.Equals(Obj.Min) ?? Obj.Min is null) &&
156 (this.max?.Equals(Obj.Max) ?? Obj.Max is null) &&
157 this.includeMin == Obj.includeMin &&
158 this.includeMax == Obj.includeMax;
159 }
160
162 public override int GetHashCode()
163 {
164 int Result = this.min?.GetHashCode() ?? 0;
165 Result ^= Result << 5 ^ (this.max?.GetHashCode() ?? 0);
166 Result ^= Result << 5 ^ this.includeMin.GetHashCode();
167 Result ^= Result << 5 ^ this.includeMax.GetHashCode();
168
169 return Result;
170 }
171
179 {
180 if (A is null ^ B is null)
181 return false;
182
183 if (A is null)
184 return true;
185
186 return A.Equals(B);
187 }
188
196 {
197 if (A is null ^ B is null)
198 return true;
199
200 if (A is null)
201 return false;
202
203 return !A.Equals(B);
204 }
205
211 public bool Contains(GeoPosition Location)
212 {
213 return !Location.LiesOutside(this.min, this.max, !this.includeMin, !this.includeMax);
214 }
215
222 public bool Contains(GeoPosition Location, bool IgnoreAltitude)
223 {
224 return !Location.LiesOutside(this.min, this.max, !this.includeMin, !this.includeMax, IgnoreAltitude);
225 }
226 }
227}
Contains information about a geo-spatial bounding box using the Mercator Projection.
static bool operator==(GeoBoundingBox A, GeoBoundingBox B)
Checks if two geo-spatial bounding boxes are equal.
string BoxId
The ID of the geo-spatial bounding box.
GeoBoundingBox(string BoxId, GeoPosition Min, GeoPosition Max, bool IncludeMin, bool IncludeMax)
Contains information about a position in a geo-spatial coordinate system.
GeoBoundingBox(GeoPosition Min, GeoPosition Max, bool IncludeMin, bool IncludeMax)
Contains information about a position in a geo-spatial coordinate system.
bool Contains(GeoPosition Location)
If the bounding box contains a location.
bool LongitudeWrapped
If the bounding box is longitude-wrapped, i.e. if the box passes the +-180 degrees longitude.
GeoBoundingBox(GeoPosition Min, GeoPosition Max)
Contains information about a position in a geo-spatial coordinate system.
static bool operator!=(GeoBoundingBox A, GeoBoundingBox B)
Checks if two geo-spatial bounding boxes are not equal.
bool IncludeMax
If the max latitude/longitude/altitude should be considered as included in the boundoing box.
bool Contains(GeoPosition Location, bool IgnoreAltitude)
If the bounding box contains a location.
override bool Equals(object obj)
GeoPosition Max
Upper-right corner of bounding box.
GeoBoundingBox(string BoxId, GeoPosition Min, GeoPosition Max)
Contains information about a position in a geo-spatial coordinate system.
bool IncludeMin
If the min latitude/longitude/altitude should be considered as included in the boundoing box.
GeoPosition Min
Lower-left corner of bounding box.
Contains information about a position in a geo-spatial coordinate system.
Definition: GeoPosition.cs:17
Interface for a geo-spatial bounding box using the Mercator Projection.