mapbox / geojson-vt

Slice GeoJSON into vector tiles on the fly in the browser
ISC License
1.89k stars 270 forks source link

Fix mid calculation for #173. #176

Closed mlptownsend closed 1 year ago

mlptownsend commented 1 year ago

Fix the mid index calculation.

image

mourner commented 1 year ago

Huh, interesting — looks like this change makes one of the tests fail. Needs investigation before we can merge then...

mlptownsend commented 1 year ago

Yeah, it's over here.

"z6-11-23": [
    {
      "geometry": [
        [
          [
            3302,
            -64
          ],
          [
            3315,
            -40
          ],
          [
            3403,
            33
          ],
          [
            3399,
            230
          ],
          [
            3483,
            315
          ],
          [
            3634,
            326
          ],
          [
            3730,
            657
          ],
          [
            3814,
            712
          ],
          [
            3890,
            617
          ],
          [
            4117,
            623
          ],
          [
            4160,
            600
          ],
          [
            4160,
            3109
          ],
          [
            799,
            3104
          ],
          [
            799,
            1285
          ],
          [
            895,
            952
          ],
          [
            835,
            868
          ],
          [
            695,
            852
          ],
          [
            643,
            712
          ],
          [
            791,
            349
          ],
          [
            867,
            315
          ],
          [
            942,
            163
          ],
          [
            931,
            67
          ],
          [
            1014,
            -57
          ],
          [
            1016,
            -64
          ],
          [
            3302,
            -64
          ]
        ]
      ],
      "type": 3,
      "tags": {
        "name": "Idaho",
        "density": 19.15
      },
      "id": "16"
    },...

vs

"z6-11-23": [
    {
      "geometry": [
        [
          [
            3302,
            -64
          ],
          [
            3315,
            -40
          ],
          [
            3403,
            33
          ],
          [
            3399,
            230
          ],
          [
            3483,
            315
          ],
          [
            3634,
            326
          ],
          [
            3730,
            657
          ],
          [
            3814,
            712
          ],
          [
            3890,
            617
          ],
          [
            4117,
            623
          ],
          [
            4160,
            600
          ],
          [
            4160,
            3109
          ],
          [
            2972,
            3109
          ],
          [
            799,
            3104
          ],
          [
            799,
            1285
          ],
          [
            895,
            952
          ],
          [
            835,
            868
          ],
          [
            695,
            852
          ],
          [
            643,
            712
          ],
          [
            791,
            349
          ],
          [
            867,
            315
          ],
          [
            942,
            163
          ],
          [
            931,
            67
          ],
          [
            1014,
            -57
          ],
          [
            1016,
            -64
          ],
          [
            3302,
            -64
          ]
        ]
      ],
      "type": 3,
      "tags": {
        "name": "Idaho",
        "density": 19.15
      },
      "id": "16"
    },...

The new one has another point in it.

[
            2972,
            3109
          ],

That's the only difference.

mourner commented 1 year ago

The result visually looks fine to me. I guess there's a chance that choosing a different pivot might lead to a slightly different outcome, even if it's not very noticeable... Let's update the test fixture then.

mlptownsend commented 1 year ago

Sure, can do.

Here's what the new bottom of Idaho looks like in the debug visualizer: image vs image

The red line is a wee bit darker in the old one.