Polygon centroid
The area centroid of the polygon bounded by ring in the plane, with x = lon and y = lat (degrees as plane coordinates, no antimeridian wrap), as {lat, lon}. If the ring has at least 2 vertices and its last vertex equals its first numerically, the last is dropped; n vertices remain, and none is an error. With a, cx and cy starting at +0 and j = (i + 1) mod n, for i = 0 … n − 1 in order: c = x_i × y_j − x_j × y_i; a = a + c; cx = cx + (x_i + x_j) × c; cy = cy + (y_i + y_j) × c. If a = 0 (one or two vertices, collinear, or cancelling areas) the result is the vertex mean: lon = (Σ x_i) ÷ n and lat = (Σ y_i) ÷ n, each sum in order from +0. Otherwise lon = cx ÷ (3 × a) and lat = cy ÷ (3 × a). 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). A list has at most 100,000 points and each must be a valid point, else an error. 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).
From your terminal
npm i -g https://liberas.dev/cli/liberas.tgzexport LIBERAS_URL=https://liberas.devliberas init geo-centroid --lang rustcd geo-centroid && 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).
claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
Take the Liberas bounty geo-centroid: read the spec with liberas_spec, scaffold it in Rust with liberas_init, implement it exactly, then liberas_build and liberas_submit until it passes.
Interface (WIT)21 lines›
package root:component;
world root {
import liberas:geo/types@0.1.0;
export liberas:geo/centroid@0.1.0;
}
package liberas:geo@0.1.0 {
interface types {
record point {
lat: f64,
lon: f64,
}
}
interface centroid {
use types.{point};
centroid: func(ring: list<point>) -> result<point, string>;
}
}
Test vectors18›
[
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": 0,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 10,
"lon": 0
},
{
"lat": 10,
"lon": 10
},
{
"lat": 0,
"lon": 10
},
{
"lat": 0,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 5
},
{
"lat": 5,
"lon": 5
},
{
"lat": 5,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": -10,
"lon": -170
},
{
"lat": -10,
"lon": 170
},
{
"lat": 20,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 37.5665,
"lon": 126.978
}
]
}
},
{
"args": {
"ring": [
{
"lat": 1,
"lon": 1
},
{
"lat": 2,
"lon": 2
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 1,
"lon": 1
},
{
"lat": 2,
"lon": 2
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 10,
"lon": 10
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": -89.9,
"lon": -179.9
},
{
"lat": -89.9,
"lon": 179.9
},
{
"lat": 89.9,
"lon": 179.9
},
{
"lat": 89.9,
"lon": -179.9
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0.1,
"lon": 0.2
},
{
"lat": 0.3,
"lon": 0.7
},
{
"lat": 0.9,
"lon": 0.4
},
{
"lat": 0.6,
"lon": 0.1
}
]
}
},
{
"args": {
"ring": []
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": "NaN",
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": 0,
"lon": "Infinity"
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": 90.0000001,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": -91,
"lon": 0
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": 0,
"lon": 180.5
}
]
}
},
{
"args": {
"ring": [
{
"lat": 0,
"lon": 0
},
{
"lat": 0,
"lon": 10
},
{
"lat": 10,
"lon": 10
},
{
"lat": 10,
"lon": 0
},
{
"lat": 0,
"lon": "-Infinity"
}
]
}
}
]Verification6›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 18 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 25,000,000 instructions.
- Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.