• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iTowns / itowns / 4489150323

pending completion
4489150323

Pull #2006

github

GitHub
Merge 25159984e into 9b6d59f19
Pull Request #2006: Rework style

3262 of 5027 branches covered (64.89%)

Branch coverage included in aggregate %.

123 of 123 new or added lines in 11 files covered. (100.0%)

6997 of 8683 relevant lines covered (80.58%)

1495.03 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.87
/src/Parser/XbilParser.js
1
import { readTextureValueWithBilinearFiltering } from 'Utils/DEMUtils';
1✔
2

3
function minMax4Corners(texture, pitch, noDataValue) {
4
    const u = pitch.x;
2✔
5
    const v = pitch.y;
2✔
6
    const w = pitch.z;
2✔
7
    const z = [
2✔
8
        readTextureValueWithBilinearFiltering({ noDataValue }, texture, u, v),
9
        readTextureValueWithBilinearFiltering({ noDataValue }, texture, u + w, v),
10
        readTextureValueWithBilinearFiltering({ noDataValue }, texture, u + w, v + w),
11
        readTextureValueWithBilinearFiltering({ noDataValue }, texture, u, v + w),
12
    ].filter(v => v != undefined && v > -10);
8✔
13

14
    if (z.length) {
2!
15
        return { min: Math.min(...z), max: Math.max(...z) };
2✔
16
    }
17
}
18

19
/**
20
  * Calculates the minimum maximum texture elevation with xbil data
21
  *
22
  * @param      {THREE.Texture}  texture       The texture to parse
23
  * @param      {THREE.Vector4}  pitch  The pitch,  restrict zone to parse
24
 * @param      {number}  noDataValue  No data value
25
  * @return     {Object}  The minimum maximum elevation.
26
  */
27
export function computeMinMaxElevation(texture, pitch, noDataValue) {
28
    const { width, height, data } = texture.image;
2✔
29
    if (!data) {
2!
30
        // Return null values means there's no elevation values.
31
        // They can't be determined.
32
        // Don't return 0 because the result will be wrong
33
        return { min: null, max: null };
×
34
    }
35

36
    // compute extact minimum and maximum elvation on 4 corners texture.
37
    let { min, max } = minMax4Corners(texture, pitch, noDataValue) || { max: -Infinity, min: Infinity };
2!
38

39
    const sizeX = Math.floor(pitch.z * width);
2✔
40

41
    if (sizeX > 2) {
2!
42
        const sizeY = Math.floor(pitch.z * height);
2✔
43
        const xs = Math.floor(pitch.x * width);
2✔
44
        const ys = Math.floor(pitch.y * height);
2✔
45
        const inc = Math.max(Math.floor(sizeX / 32), 2);
2✔
46
        const limX = ys + sizeY;
47
        for (let y = ys; y < limX; y += inc) {
2✔
48
            const pit = y * (width || 0);
34!
49
            let x = pit + xs;
34✔
50
            const limX = x + sizeX;
34✔
51
            for (x; x < limX; x += inc) {
34✔
52
                const val = data[x];
1,028✔
53
                if (val > -10 && val != noDataValue) {
1,028✔
54
                    max = Math.max(max, val);
950✔
55
                    min = Math.min(min, val);
950✔
56
                }
57
            }
58
        }
59
    }
60

61
    if (max === -Infinity || min === Infinity) {
2!
62
        // Return null values means the elevation values are incoherent
63
        // They can't be determined.
64
        // Don't return 0, -Infinity or Infinity because the result will be wrong
65
        return { min: null, max: null };
×
66
    } else {
67
        return { min, max };
2✔
68
    }
69
}
70

71
// We check if the elevation texture has some significant values through corners
72
export function checkNodeElevationTextureValidity(data, noDataValue) {
73
    const l = data.length;
×
74
    return data[0] > noDataValue &&
×
75
           data[l - 1] > noDataValue &&
76
           data[Math.sqrt(l) - 1] > noDataValue &&
77
           data[l - Math.sqrt(l)] > noDataValue;
78
}
79

80
function getIndiceWithPitch(i, pitch, w) {
81
    // Return corresponding indice in parent tile using pitch
82
    const currentX = (i % w) / w;  // normalized
83
    const currentY = Math.floor(i / w) / w; // normalized
×
84
    const newX = pitch.x + currentX * pitch.z;
×
85
    const newY = pitch.y + currentY * pitch.w;
×
86
    const newIndice = Math.floor(newY * w) * w + Math.floor(newX * w);
×
87
    return newIndice;
×
88
}
89

90
// This function replaces noDataValue by significant values from parent texture (or 0)
91
export function insertSignificantValuesFromParent(data, dataParent, noDataValue, pitch) {
92
    for (let i = 0, l = data.length; i < l; ++i) {
×
93
        if (data[i] === noDataValue) {
×
94
            const parentValue = dataParent[getIndiceWithPitch(i, pitch, 256)];
×
95
            data[i] = parentValue === noDataValue ? 0 : parentValue;
×
96
        }
97
    }
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc