Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
geo / geo-web-mercator-forwardOpenRuns on Liberas

Web Mercator forward

Web Mercator (EPSG:3857: spherical Mercator on R = 6,378,137 m) easting and northing of point at, in millimetres. at must be a valid point with −85.051129 ≤ lat ≤ 85.051129, else an error. x = R × rad(lon) and y = R × ln(tan(π ÷ 4 + rad(lat) ÷ 2)); the result is {x: round(x × 1000), y: round(y × 1000)}. A point is {lat, lon} in degrees; it is an error unless both are finite with −90 ≤ lat ≤ 90 and −180 ≤ lon ≤ 180 (NaN and ±Infinity are errors). rad(v) = v × π ÷ 180 and deg(v) = v × 180 ÷ π, left to right, with π the binary64 nearest π. Arithmetic is IEEE 754 binary64, each operation rounded to nearest-even and evaluated in exactly the order written (left to right; no fused multiply-add). sin, cos, tan, asin, atan, atan2, exp and ln are the platform's own: the result is an integer, round half away from zero, so any libm accurate to a few ulps gives the same answer except within a hair of a rounding boundary.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init geo-web-mercator-forward --lang rust
cd geo-web-mercator-forward && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)26 lines›
geo-web-mercator-forward.wit
package root:component;

world root {
  import liberas:geo/types@0.1.0;

  export liberas:geo/mercator-forward@0.1.0;
}
package liberas:geo@0.1.0 {
  interface types {
    record point {
      lat: f64,
      lon: f64,
    }

    record xy-mm {
      x: s64,
      y: s64,
    }
  }
  interface mercator-forward {
    use types.{point, xy-mm};

    forward: func(at: point) -> result<xy-mm, string>;
  }
}
Test vectors14›
geo-web-mercator-forward.cases.json
[
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 37.5665,
        "lon": 126.978
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 51.5074,
        "lon": -0.1278
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 85.051129,
        "lon": 180
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -85.051129,
        "lon": -180
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -33.8688,
        "lon": 151.2093
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 85.06,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -90,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": "NaN",
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": "Infinity"
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 90.0000001,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": -91,
        "lon": 0
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": 180.5
      }
    }
  },
  {
    "args": {
      "at": {
        "lat": 0,
        "lon": "-Infinity"
      }
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 14 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.