forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundingBoxBuilder.cs
More file actions
54 lines (45 loc) · 1.73 KB
/
BoundingBoxBuilder.cs
File metadata and controls
54 lines (45 loc) · 1.73 KB
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
using GeoJSON.Net.Geometry;
namespace Npgsql.GeoJSON
{
sealed class BoundingBoxBuilder
{
bool _hasAltitude;
double _minLongitude, _maxLongitude;
double _minLatitude, _maxLatitude;
double _minAltitude, _maxAltitude;
internal BoundingBoxBuilder()
{
_hasAltitude = false;
_minLongitude = double.PositiveInfinity;
_minLatitude = double.PositiveInfinity;
_minAltitude = double.PositiveInfinity;
_maxLongitude = double.NegativeInfinity;
_maxLatitude = double.NegativeInfinity;
_maxAltitude = double.NegativeInfinity;
}
internal void Accumulate(Position position)
{
if (_minLongitude > position.Longitude)
_minLongitude = position.Longitude;
if (_maxLongitude < position.Longitude)
_maxLongitude = position.Longitude;
if (_minLatitude > position.Latitude)
_minLatitude = position.Latitude;
if (_maxLatitude < position.Latitude)
_maxLatitude = position.Latitude;
if (position.Altitude.HasValue)
{
var altitude = position.Altitude.Value;
if (_minAltitude > altitude)
_minAltitude = altitude;
if (_maxAltitude < altitude)
_maxAltitude = altitude;
_hasAltitude = true;
}
}
internal double[] Build()
=> _hasAltitude
? new[] { _minLongitude, _minLatitude, _minAltitude, _maxLongitude, _maxLatitude, _maxAltitude }
: new[] { _minLongitude, _minLatitude, _maxLongitude, _maxLatitude };
}
}