forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCrsMapBuilder.cs
More file actions
54 lines (45 loc) · 1.48 KB
/
CrsMapBuilder.cs
File metadata and controls
54 lines (45 loc) · 1.48 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 System;
namespace Npgsql.GeoJSON.Internal;
struct CrsMapBuilder
{
CrsMapEntry[] _overrides;
int _overriddenIndex;
int _wellKnownIndex;
internal void Add(in CrsMapEntry entry)
{
var wellKnown = CrsMap.WellKnown[_wellKnownIndex];
if (wellKnown.MinSrid == entry.MinSrid &&
wellKnown.MaxSrid == entry.MaxSrid &&
string.Equals(wellKnown.Authority, entry.Authority, StringComparison.Ordinal))
{
_wellKnownIndex++;
return;
}
if (wellKnown.MinSrid < entry.MinSrid)
{
do
_wellKnownIndex++;
while (CrsMap.WellKnown.Length < _wellKnownIndex &&
CrsMap.WellKnown[_wellKnownIndex].MaxSrid < entry.MaxSrid);
AddCore(new CrsMapEntry(wellKnown.MinSrid, Math.Min(wellKnown.MaxSrid, entry.MinSrid - 1), null));
}
AddCore(entry);
}
void AddCore(in CrsMapEntry entry)
{
var index = _overriddenIndex + 1;
if (_overrides == null)
_overrides = new CrsMapEntry[4];
else
if (_overrides.Length == index)
Array.Resize(ref _overrides, _overrides.Length << 1);
_overrides[_overriddenIndex] = entry;
_overriddenIndex = index;
}
internal CrsMap Build()
{
if (_overrides != null && _overrides.Length < _overriddenIndex)
Array.Resize(ref _overrides, _overriddenIndex);
return new CrsMap(_overrides);
}
}