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

iTowns / itowns / 4076206884

pending completion
4076206884

Pull #1993

github

GitHub
Merge 3994711c0 into 7f86d26e1
Pull Request #1993: WIP Bounding box and calculation of MinMax values

3167 of 4888 branches covered (64.79%)

Branch coverage included in aggregate %.

7 of 7 new or added lines in 2 files covered. (100.0%)

6977 of 8634 relevant lines covered (80.81%)

1508.11 hits per line

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

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

3
function minMax4Corners(texture, pitch, options) {
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),
9
        readTextureValueWithBilinearFiltering(options, texture, u + w, v),
10
        readTextureValueWithBilinearFiltering(options, texture, u + w, v + w),
11
        readTextureValueWithBilinearFiltering(options, texture, u, v + w),
12
    ].filter(val => val != undefined);
8✔
13

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

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

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

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

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

72
    if (max === -Infinity || min === Infinity) {
2!
73
        // Return null values means the elevation values are incoherent
74
        // They can't be determined.
75
        // Don't return 0, -Infinity or Infinity because the result will be wrong
76
        return { min: null, max: null };
×
77
    } else {
78
        return { min, max };
2✔
79
    }
80
}
81

82
// We check if the elevation texture has some significant values through corners
83
export function checkNodeElevationTextureValidity(data, noDataValue) {
84
    const l = data.length;
×
85
    return data[0] > noDataValue &&
×
86
           data[l - 1] > noDataValue &&
87
           data[Math.sqrt(l) - 1] > noDataValue &&
88
           data[l - Math.sqrt(l)] > noDataValue;
89
}
90

91
function getIndiceWithPitch(i, pitch, w) {
92
    // Return corresponding indice in parent tile using pitch
93
    const currentX = (i % w) / w;  // normalized
94
    const currentY = Math.floor(i / w) / w; // normalized
×
95
    const newX = pitch.x + currentX * pitch.z;
×
96
    const newY = pitch.y + currentY * pitch.w;
×
97
    const newIndice = Math.floor(newY * w) * w + Math.floor(newX * w);
×
98
    return newIndice;
×
99
}
100

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

© 2025 Coveralls, Inc