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

iTowns / itowns / 11859808789

15 Nov 2024 04:24PM UTC coverage: 86.829%. Remained the same
11859808789

push

github

airnez
fix(xbilparser): apply zmin / zmax for any texture subsampling size

2791 of 3708 branches covered (75.27%)

Branch coverage included in aggregate %.

5 of 10 new or added lines in 1 file covered. (50.0%)

1 existing line in 1 file now uncovered.

24357 of 27558 relevant lines covered (88.38%)

1022.34 hits per line

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

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

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

2✔
14
    if (z.length) {
2✔
15
        return { min: Math.min(...z), max: Math.max(...z) };
2✔
16
    } else {
2!
17
        return {
×
18
            min: Infinity,
×
19
            max: -Infinity,
×
20
        };
×
21
    }
×
22
}
2✔
23

1✔
24
/**
1✔
25
 * Calculates the minimum maximum texture elevation with xbil data
1✔
26
 *
1✔
27
 * @param      {THREE.Texture}   texture                     The texture to parse
1✔
28
 * @param      {THREE.Vector4}   pitch                       The pitch,  restrict zone to parse
1✔
29
 * @param      {Object}          options                     No data value and clamp values
1✔
30
 * @param      {number}          options.noDataValue         No data value
1✔
31
 * @param      {number}          [options.zmin]   The minimum elevation value after which it will be clamped
1✔
32
 * @param      {number}          [options.zmax]   The maximum elevation value after which it will be clamped
1✔
33
 * @return     {Object}  The minimum and maximum elevation.
1✔
34
 */
1✔
35
export function computeMinMaxElevation(texture, pitch, options) {
1✔
36
    const { width, height, data } = texture.image;
2✔
37
    if (!data) {
2!
38
        // Return null values means there's no elevation values.
×
39
        // They can't be determined.
×
40
        // Don't return 0 because the result will be wrong
×
41
        return { min: null, max: null };
×
42
    }
×
43

2✔
44
    // compute the minimum and maximum elevation on the 4 corners texture.
2✔
45
    let { min, max } = minMax4Corners(texture, pitch, options);
2✔
46

2✔
47
    const sizeX = Math.floor(pitch.z * width);
2✔
48

2✔
49
    if (sizeX > 2) {
2✔
50
        const sizeY = Math.floor(pitch.z * height);
2✔
51
        const xs = Math.floor(pitch.x * width);
2✔
52
        const ys = Math.floor(pitch.y * height);
2✔
53
        const inc = Math.max(Math.floor(sizeX / 32), 2);
2✔
54
        const limX = ys + sizeY;
2✔
55
        for (let y = ys; y < limX; y += inc) {
2✔
56
            const pit = y * (width || 0);
34!
57
            let x = pit + xs;
34✔
58
            const limX = x + sizeX;
34✔
59
            for (x; x < limX; x += inc) {
34✔
60
                const val = data[x];
1,028✔
61
                if (val !== options.noDataValue) {
1,028✔
62
                    max = Math.max(max, val);
1,028✔
63
                    min = Math.min(min, val);
1,028✔
64
                }
1,028✔
65
            }
1,028✔
66
        }
34✔
67
    }
2✔
68

2✔
69
    // Clamp values to zmin and zmax values configured in ElevationLayer
2✔
70
    if (options.zmin != null) {
2!
NEW
71
        if (min < options.zmin) { min = options.zmin; }
×
NEW
72
        if (max < options.zmin) { max = options.zmin; }
×
NEW
73
    }
×
74

2✔
75
    if (options.zmax != null) {
2!
NEW
76
        if (min > options.zmax) { min = options.zmax; }
×
NEW
77
        if (max > options.zmax) { max = options.zmax; }
×
UNCOV
78
    }
×
79

2✔
80
    if (max === -Infinity || min === Infinity) {
2!
81
        // Return null values means the elevation values are incoherent
×
82
        // They can't be determined.
×
83
        // Don't return 0, -Infinity or Infinity because the result will be wrong
×
84
        return { min: null, max: null };
×
85
    } else {
2✔
86
        return { min, max };
2✔
87
    }
2✔
88
}
2✔
89

1✔
90
// We check if the elevation texture has some significant values through corners
1✔
91
export function checkNodeElevationTextureValidity(data, noDataValue) {
1✔
92
    const l = data.length;
×
93
    return data[0] > noDataValue &&
×
94
           data[l - 1] > noDataValue &&
×
95
           data[Math.sqrt(l) - 1] > noDataValue &&
×
96
           data[l - Math.sqrt(l)] > noDataValue;
×
97
}
×
98

1✔
99
// This function replaces noDataValue by significant values from parent texture (or 0)
1✔
100
export function insertSignificantValuesFromParent(data, dataParent = () => 0, noDataValue) {
1✔
101
    for (let i = 0, l = data.length; i < l; ++i) {
×
102
        if (data[i] === noDataValue) {
×
103
            data[i] = dataParent(i);
×
104
        }
×
105
    }
×
106
}
×
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