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

iTowns / itowns / 11270483022

10 Oct 2024 08:39AM UTC coverage: 86.928% (-0.02%) from 86.944%
11270483022

push

github

jailln
fix(Terrain): fix terrain subdivision when a terrain tile only has values that should be clamped

2795 of 3710 branches covered (75.34%)

Branch coverage included in aggregate %.

4 of 10 new or added lines in 1 file covered. (40.0%)

24343 of 27509 relevant lines covered (88.49%)

1022.68 hits per line

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

67.24
/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
        // Clamp values to zmin and zmax values configured in ElevationLayer
2✔
68
        if (options.zmin != null) {
2!
NEW
69
            if (min < options.zmin) { min = options.zmin; }
×
NEW
70
            if (max < options.zmin) { max = options.zmin; }
×
NEW
71
        }
×
72

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

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

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

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