From cab6ea701c2b28f081598045f48a6706a9014a77 Mon Sep 17 00:00:00 2001 From: Mr Martian Date: Mon, 29 Jul 2024 05:55:34 -0600 Subject: [PATCH] bug fixes; added all tests; actions added --- .github/workflows/coveralls.yml | 82 ++++++++++ .github/workflows/test.yml | 48 ++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 +- cobertura.xml | 1 + docs/hierarchy.html | 2 +- docs/index.html | 8 +- docs/interfaces/BaseFeature.html | 4 +- docs/interfaces/BaseFeatureCollection.html | 4 +- docs/interfaces/BaseGeometry.html | 4 +- docs/interfaces/Feature.html | 4 +- docs/interfaces/FeatureCollection.html | 4 +- docs/interfaces/LineString3DGeometry.html | 4 +- docs/interfaces/LineStringGeometry.html | 4 +- .../interfaces/MultiLineString3DGeometry.html | 4 +- docs/interfaces/MultiLineStringGeometry.html | 4 +- docs/interfaces/MultiPoint3DGeometry.html | 4 +- docs/interfaces/MultiPointGeometry.html | 4 +- docs/interfaces/MultiPolygon3DGeometry.html | 4 +- docs/interfaces/MultiPolygonGeometry.html | 4 +- docs/interfaces/Point3DGeometry.html | 4 +- docs/interfaces/PointGeometry.html | 4 +- docs/interfaces/Polygon3DGeometry.html | 4 +- docs/interfaces/PolygonGeometry.html | 4 +- docs/interfaces/S2Feature.html | 4 +- docs/interfaces/S2FeatureCollection.html | 4 +- docs/modules.html | 4 +- docs/types/Attributions.html | 4 +- docs/types/BBOX.html | 4 +- docs/types/BBox-1.html | 4 +- docs/types/BBox3D.html | 4 +- docs/types/Coordinates.html | 4 +- docs/types/Face.html | 4 +- docs/types/FeatureCollectionType.html | 4 +- docs/types/FeatureCollections.html | 4 +- docs/types/FeatureType.html | 4 +- docs/types/Features.html | 4 +- docs/types/Geometry.html | 4 +- docs/types/GeometryType.html | 4 +- docs/types/JSONCollection.html | 4 +- docs/types/LineString.html | 4 +- docs/types/LineString3D.html | 4 +- docs/types/LineStringMValues.html | 4 +- docs/types/MValue.html | 4 +- docs/types/MValues.html | 4 +- docs/types/MultiLineString.html | 4 +- docs/types/MultiLineString3D.html | 4 +- docs/types/MultiLineStringMValues.html | 4 +- docs/types/MultiPoint.html | 4 +- docs/types/MultiPoint3D.html | 4 +- docs/types/MultiPolygon.html | 4 +- docs/types/MultiPolygon3D.html | 4 +- docs/types/MultiPolygonMValues.html | 4 +- docs/types/Point.html | 4 +- docs/types/Point3D.html | 4 +- docs/types/Polygon.html | 4 +- docs/types/Polygon3D.html | 4 +- docs/types/PolygonMValues.html | 4 +- docs/types/Primitive.html | 4 +- docs/types/Properties.html | 4 +- docs/types/Value.html | 4 +- docs/types/ValueArray.html | 4 +- package.json | 3 +- rust/geometry.rs | 142 +++++++++++++++++- rust/lib.rs | 30 +++- rust/values.rs | 129 +++++++++++++++- s2json-spec/1.0.0/README.md | 2 +- src/s2json.schema.json | 2 + 69 files changed, 541 insertions(+), 136 deletions(-) create mode 100644 .github/workflows/coveralls.yml create mode 100644 .github/workflows/test.yml create mode 100644 cobertura.xml diff --git a/.github/workflows/coveralls.yml b/.github/workflows/coveralls.yml new file mode 100644 index 0000000..c4ebf79 --- /dev/null +++ b/.github/workflows/coveralls.yml @@ -0,0 +1,82 @@ +name: coveralls + +on: push + +jobs: + test: + name: Coveralls Upload + runs-on: ubuntu-latest + + # setup + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: 1.1.16 + + - name: Install dependencies + run: bun install + + # Bun tests + + - name: Run JavaScript/TypeScript tests + run: bun run test + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + # setup rust + + - name: Install Clippy + run: rustup component add clippy + + - name: Install llvm-tools-preview + run: rustup component add llvm-tools-preview + + - name: Install grcov + run: | + sudo apt-get install lcov + cargo install grcov + + - name: Build Rust project + run: cargo build + shell: bash + + # Rust tests + + - name: Run Rust tests with coverage + run: | + export CARGO_INCREMENTAL=0 + export RUSTFLAGS='-Cinstrument-coverage' + export LLVM_PROFILE_FILE='cargo-test-%p-%m.profraw' + cargo test --lib + grcov . --binary-path ./target/debug/ -s . -t lcov --branch --ignore-not-existing --ignore "/*/.cargo/*" --ignore "/*/target/*" -o ./coverage/rust-lcov.info + shell: bash + + # Merge LCOV reports + + - name: Merge Bun and Rust LCOV reports + run: | + mkdir -p coverage + if [ -f ./coverage/lcov.info ] && [ -f ./coverage/rust-lcov.info ]; then + cat ./coverage/rust-lcov.info >> ./coverage/lcov.info + elif [ -f ./coverage/rust-lcov.info ]; then + mv ./coverage/rust-lcov.info ./coverage/lcov.info + fi + + # upload to Coveralls + + - name: Upload coverage to Coveralls + run: | + if [ -f ./coverage/lcov.info ]; then + bun run coveralls < ./coverage/lcov.info + fi + env: + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4c40f82 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,48 @@ +name: test-workflow + +on: push + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Bun + uses: oven-sh/setup-bun@v1 + with: + bun-version: 1.1.16 + + - name: Install dependencies + run: bun install + + - name: Run JavaScript/TypeScript tests + run: bun run test + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Clippy + run: rustup component add clippy + + - name: Run Clippy + run: cargo clippy -- -D warnings + shell: bash + + - name: Build Rust project + run: cargo build + shell: bash + + - name: Run Rust tests + run: cargo test + shell: bash diff --git a/Cargo.lock b/Cargo.lock index 136c31d..502a19b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,7 +34,7 @@ checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "s2json" -version = "1.2.0" +version = "1.3.0" dependencies = [ "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index d3b5802..051971d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "s2json" -version = "1.2.0" +version = "1.3.0" edition = "2021" authors = ["Craig O'Connor "] description = "This library supports the S2JSON 1.0 Specification" diff --git a/README.md b/README.md index d117f73..c8b0ad8 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,9 @@ docs-rust - doc-coverage + + code-coverage + Discord diff --git a/cobertura.xml b/cobertura.xml new file mode 100644 index 0000000..2cdd96d --- /dev/null +++ b/cobertura.xml @@ -0,0 +1 @@ +/Users/craigoconnor/Documents/Projects/OpenS2/s2json \ No newline at end of file diff --git a/docs/hierarchy.html b/docs/hierarchy.html index 57ca0d9..f16017c 100644 --- a/docs/hierarchy.html +++ b/docs/hierarchy.html @@ -1 +1 @@ -s2json-spec - v1.2.0
\ No newline at end of file +s2json-spec - v1.3.0
\ No newline at end of file diff --git a/docs/index.html b/docs/index.html index 6c7a5ab..1fa6c07 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1,4 +1,4 @@ -s2json-spec - v1.2.0

s2json-spec - v1.2.0

+s2json-spec - v1.3.0

s2json-spec - v1.3.0

s2json

@@ -21,7 +21,9 @@ docs-rust - doc-coverage + + code-coverage + Discord @@ -62,4 +64,4 @@

Generating Coverage Report

To generate the coverage report, use the following command:

cargo tarpaulin
# bacon
bacon coverage # or type `l` inside the tool
-
\ No newline at end of file +

\ No newline at end of file diff --git a/docs/interfaces/BaseFeature.html b/docs/interfaces/BaseFeature.html index 1dc3576..4b96f58 100644 --- a/docs/interfaces/BaseFeature.html +++ b/docs/interfaces/BaseFeature.html @@ -1,2 +1,2 @@ -BaseFeature | s2json-spec - v1.2.0

Interface BaseFeature<T, P, M>

Base component to build either an S2 or WG Feature

-
interface BaseFeature<T, P, M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +BaseFeature | s2json-spec - v1.3.0

Interface BaseFeature<T, P, M>

Base component to build either an S2 or WG Feature

+
interface BaseFeature<T, P, M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/BaseFeatureCollection.html b/docs/interfaces/BaseFeatureCollection.html index b0f888a..ae2f8d2 100644 --- a/docs/interfaces/BaseFeatureCollection.html +++ b/docs/interfaces/BaseFeatureCollection.html @@ -1,2 +1,2 @@ -BaseFeatureCollection | s2json-spec - v1.2.0

Interface BaseFeatureCollection<T, F>

Either an S2 or WG FeatureCollection

-
interface BaseFeatureCollection<T, F> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +BaseFeatureCollection | s2json-spec - v1.3.0

Interface BaseFeatureCollection<T, F>

Either an S2 or WG FeatureCollection

+
interface BaseFeatureCollection<T, F> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/BaseGeometry.html b/docs/interfaces/BaseGeometry.html index 0553d9e..6c9a8d0 100644 --- a/docs/interfaces/BaseGeometry.html +++ b/docs/interfaces/BaseGeometry.html @@ -1,2 +1,2 @@ -BaseGeometry | s2json-spec - v1.2.0

Interface BaseGeometry<T, C, M, B>

BaseGeometry with MValues is the a generic geometry type that includes MValues

-
interface BaseGeometry<T, C, M, B> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +BaseGeometry | s2json-spec - v1.3.0

Interface BaseGeometry<T, C, M, B>

BaseGeometry with MValues is the a generic geometry type that includes MValues

+
interface BaseGeometry<T, C, M, B> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/Feature.html b/docs/interfaces/Feature.html index 6885b8b..261db5c 100644 --- a/docs/interfaces/Feature.html +++ b/docs/interfaces/Feature.html @@ -1,2 +1,2 @@ -Feature | s2json-spec - v1.2.0

Interface Feature<P, M>

WG Feature

-
interface Feature<P, M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +Feature | s2json-spec - v1.3.0

Interface Feature<P, M>

WG Feature

+
interface Feature<P, M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/FeatureCollection.html b/docs/interfaces/FeatureCollection.html index 6edd0a6..4d700c6 100644 --- a/docs/interfaces/FeatureCollection.html +++ b/docs/interfaces/FeatureCollection.html @@ -1,2 +1,2 @@ -FeatureCollection | s2json-spec - v1.2.0

Interface FeatureCollection

WG FeatureCollection

-
interface FeatureCollection {}

Hierarchy (view full)

\ No newline at end of file +FeatureCollection | s2json-spec - v1.3.0

Interface FeatureCollection

WG FeatureCollection

+
interface FeatureCollection {}

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/LineString3DGeometry.html b/docs/interfaces/LineString3DGeometry.html index c3ddddd..4195fb0 100644 --- a/docs/interfaces/LineString3DGeometry.html +++ b/docs/interfaces/LineString3DGeometry.html @@ -1,2 +1,2 @@ -LineString3DGeometry | s2json-spec - v1.2.0

Interface LineString3DGeometry<M>

LineString3DGeometry is a 3D line

-
interface LineString3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +LineString3DGeometry | s2json-spec - v1.3.0

Interface LineString3DGeometry<M>

LineString3DGeometry is a 3D line

+
interface LineString3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/LineStringGeometry.html b/docs/interfaces/LineStringGeometry.html index 2917024..3569d1c 100644 --- a/docs/interfaces/LineStringGeometry.html +++ b/docs/interfaces/LineStringGeometry.html @@ -1,2 +1,2 @@ -LineStringGeometry | s2json-spec - v1.2.0

Interface LineStringGeometry<M>

LineStringGeometry is a line

-
interface LineStringGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +LineStringGeometry | s2json-spec - v1.3.0

Interface LineStringGeometry<M>

LineStringGeometry is a line

+
interface LineStringGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/MultiLineString3DGeometry.html b/docs/interfaces/MultiLineString3DGeometry.html index 655eacb..d141fb2 100644 --- a/docs/interfaces/MultiLineString3DGeometry.html +++ b/docs/interfaces/MultiLineString3DGeometry.html @@ -1,2 +1,2 @@ -MultiLineString3DGeometry | s2json-spec - v1.2.0

Interface MultiLineString3DGeometry<M>

MultiLineString3DGeometry contians multiple 3D lines

-
interface MultiLineString3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +MultiLineString3DGeometry | s2json-spec - v1.3.0

Interface MultiLineString3DGeometry<M>

MultiLineString3DGeometry contians multiple 3D lines

+
interface MultiLineString3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/MultiLineStringGeometry.html b/docs/interfaces/MultiLineStringGeometry.html index b422417..259fad6 100644 --- a/docs/interfaces/MultiLineStringGeometry.html +++ b/docs/interfaces/MultiLineStringGeometry.html @@ -1,2 +1,2 @@ -MultiLineStringGeometry | s2json-spec - v1.2.0

Interface MultiLineStringGeometry<M>

MultiLineStringGeometry contians multiple lines

-
interface MultiLineStringGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +MultiLineStringGeometry | s2json-spec - v1.3.0

Interface MultiLineStringGeometry<M>

MultiLineStringGeometry contians multiple lines

+
interface MultiLineStringGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/MultiPoint3DGeometry.html b/docs/interfaces/MultiPoint3DGeometry.html index 23e7b25..70799b6 100644 --- a/docs/interfaces/MultiPoint3DGeometry.html +++ b/docs/interfaces/MultiPoint3DGeometry.html @@ -1,2 +1,2 @@ -MultiPoint3DGeometry | s2json-spec - v1.2.0

Interface MultiPoint3DGeometry<M>

MultiPoint3DGeometry contains multiple 3D points

-
interface MultiPoint3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +MultiPoint3DGeometry | s2json-spec - v1.3.0

Interface MultiPoint3DGeometry<M>

MultiPoint3DGeometry contains multiple 3D points

+
interface MultiPoint3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/MultiPointGeometry.html b/docs/interfaces/MultiPointGeometry.html index 974849d..692f051 100644 --- a/docs/interfaces/MultiPointGeometry.html +++ b/docs/interfaces/MultiPointGeometry.html @@ -1,2 +1,2 @@ -MultiPointGeometry | s2json-spec - v1.2.0

Interface MultiPointGeometry<M>

MultiPointGeometry contains multiple points

-
interface MultiPointGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +MultiPointGeometry | s2json-spec - v1.3.0

Interface MultiPointGeometry<M>

MultiPointGeometry contains multiple points

+
interface MultiPointGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/MultiPolygon3DGeometry.html b/docs/interfaces/MultiPolygon3DGeometry.html index cd7029c..081e06d 100644 --- a/docs/interfaces/MultiPolygon3DGeometry.html +++ b/docs/interfaces/MultiPolygon3DGeometry.html @@ -1,2 +1,2 @@ -MultiPolygon3DGeometry | s2json-spec - v1.2.0

Interface MultiPolygon3DGeometry<M>

MultiPolygon3DGeometry is a 3D polygon with multiple polygons with their own potential holes

-
interface MultiPolygon3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +MultiPolygon3DGeometry | s2json-spec - v1.3.0

Interface MultiPolygon3DGeometry<M>

MultiPolygon3DGeometry is a 3D polygon with multiple polygons with their own potential holes

+
interface MultiPolygon3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/MultiPolygonGeometry.html b/docs/interfaces/MultiPolygonGeometry.html index e086bbf..e3373f4 100644 --- a/docs/interfaces/MultiPolygonGeometry.html +++ b/docs/interfaces/MultiPolygonGeometry.html @@ -1,2 +1,2 @@ -MultiPolygonGeometry | s2json-spec - v1.2.0

Interface MultiPolygonGeometry<M>

MultiPolygonGeometry is a polygon with multiple polygons with their own potential holes

-
interface MultiPolygonGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +MultiPolygonGeometry | s2json-spec - v1.3.0

Interface MultiPolygonGeometry<M>

MultiPolygonGeometry is a polygon with multiple polygons with their own potential holes

+
interface MultiPolygonGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/Point3DGeometry.html b/docs/interfaces/Point3DGeometry.html index 275f9e5..8085239 100644 --- a/docs/interfaces/Point3DGeometry.html +++ b/docs/interfaces/Point3DGeometry.html @@ -1,2 +1,2 @@ -Point3DGeometry | s2json-spec - v1.2.0

Interface Point3DGeometry<M>

Point3DGeometry is a 3D point

-
interface Point3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +Point3DGeometry | s2json-spec - v1.3.0

Interface Point3DGeometry<M>

Point3DGeometry is a 3D point

+
interface Point3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/PointGeometry.html b/docs/interfaces/PointGeometry.html index ebb0403..a06ad6a 100644 --- a/docs/interfaces/PointGeometry.html +++ b/docs/interfaces/PointGeometry.html @@ -1,2 +1,2 @@ -PointGeometry | s2json-spec - v1.2.0

Interface PointGeometry<M>

PointGeometry is a point

-
interface PointGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +PointGeometry | s2json-spec - v1.3.0

Interface PointGeometry<M>

PointGeometry is a point

+
interface PointGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/Polygon3DGeometry.html b/docs/interfaces/Polygon3DGeometry.html index ae69a08..b34eec1 100644 --- a/docs/interfaces/Polygon3DGeometry.html +++ b/docs/interfaces/Polygon3DGeometry.html @@ -1,2 +1,2 @@ -Polygon3DGeometry | s2json-spec - v1.2.0

Interface Polygon3DGeometry<M>

Polygon3DGeometry is a 3D polygon with potential holes

-
interface Polygon3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +Polygon3DGeometry | s2json-spec - v1.3.0

Interface Polygon3DGeometry<M>

Polygon3DGeometry is a 3D polygon with potential holes

+
interface Polygon3DGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/PolygonGeometry.html b/docs/interfaces/PolygonGeometry.html index c06dac1..9d62dae 100644 --- a/docs/interfaces/PolygonGeometry.html +++ b/docs/interfaces/PolygonGeometry.html @@ -1,2 +1,2 @@ -PolygonGeometry | s2json-spec - v1.2.0

Interface PolygonGeometry<M>

PolygonGeometry is a polygon with potential holes

-
interface PolygonGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +PolygonGeometry | s2json-spec - v1.3.0

Interface PolygonGeometry<M>

PolygonGeometry is a polygon with potential holes

+
interface PolygonGeometry<M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/S2Feature.html b/docs/interfaces/S2Feature.html index e662db1..004df3f 100644 --- a/docs/interfaces/S2Feature.html +++ b/docs/interfaces/S2Feature.html @@ -1,2 +1,2 @@ -S2Feature | s2json-spec - v1.2.0

Interface S2Feature<P, M>

S2 Feature

-
interface S2Feature<P, M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file +S2Feature | s2json-spec - v1.3.0

Interface S2Feature<P, M>

S2 Feature

+
interface S2Feature<P, M> {}

Type Parameters

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/interfaces/S2FeatureCollection.html b/docs/interfaces/S2FeatureCollection.html index 3bb0e38..d80a2c3 100644 --- a/docs/interfaces/S2FeatureCollection.html +++ b/docs/interfaces/S2FeatureCollection.html @@ -1,2 +1,2 @@ -S2FeatureCollection | s2json-spec - v1.2.0

Interface S2FeatureCollection

S2 FeatureCollection

-
interface S2FeatureCollection {}

Hierarchy (view full)

\ No newline at end of file +S2FeatureCollection | s2json-spec - v1.3.0

Interface S2FeatureCollection

S2 FeatureCollection

+
interface S2FeatureCollection {}

Hierarchy (view full)

\ No newline at end of file diff --git a/docs/modules.html b/docs/modules.html index c9a9b2d..af30fa7 100644 --- a/docs/modules.html +++ b/docs/modules.html @@ -1,4 +1,4 @@ -s2json-spec - v1.2.0

s2json-spec - v1.2.0

Index

Interfaces

BaseFeature +s2json-spec - v1.3.0

s2json-spec - v1.3.0

Index

Interfaces

\ No newline at end of file +
\ No newline at end of file diff --git a/docs/types/Attributions.html b/docs/types/Attributions.html index 03d99b5..a511ffc 100644 --- a/docs/types/Attributions.html +++ b/docs/types/Attributions.html @@ -1,4 +1,4 @@ -Attributions | s2json-spec - v1.2.0

Type alias Attributions

Attributions: Record<string, string>

Attribution data is stored in an object. +Attributions | s2json-spec - v1.3.0

Type alias Attributions

Attributions: Record<string, string>

Attribution data is stored in an object. The key is the name of the attribution, and the value is the href link e.g. { "Open S2": "https://opens2.com/legal/data" }

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/types/BBOX.html b/docs/types/BBOX.html index 1f995a6..e5bac36 100644 --- a/docs/types/BBOX.html +++ b/docs/types/BBOX.html @@ -1,2 +1,2 @@ -BBOX | s2json-spec - v1.2.0

Type alias BBOX

BBOX: BBox | BBox3D

Either a 2D or 3D bounding box

-
\ No newline at end of file +BBOX | s2json-spec - v1.3.0

Type alias BBOX

BBOX: BBox | BBox3D

Either a 2D or 3D bounding box

+
\ No newline at end of file diff --git a/docs/types/BBox-1.html b/docs/types/BBox-1.html index e31aa8c..d0c1846 100644 --- a/docs/types/BBox-1.html +++ b/docs/types/BBox-1.html @@ -1,3 +1,3 @@ -BBox | s2json-spec - v1.2.0

Type alias BBox

BBox: [left: number, bottom: number, right: number, top: number]

A BBOX is defined in lon-lat space and helps with zooming motion to +BBox | s2json-spec - v1.3.0

Type alias BBox

BBox: [left: number, bottom: number, right: number, top: number]

A BBOX is defined in lon-lat space and helps with zooming motion to see the entire line or polygon

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/types/BBox3D.html b/docs/types/BBox3D.html index 8c7babb..20b9edc 100644 --- a/docs/types/BBox3D.html +++ b/docs/types/BBox3D.html @@ -1,3 +1,3 @@ -BBox3D | s2json-spec - v1.2.0

Type alias BBox3D

BBox3D: [left: number, bottom: number, right: number, top: number, front: number, back: number]

A BBOX is defined in lon-lat space and helps with zooming motion to +BBox3D | s2json-spec - v1.3.0

Type alias BBox3D

BBox3D: [left: number, bottom: number, right: number, top: number, front: number, back: number]

A BBOX is defined in lon-lat space and helps with zooming motion to see the entire 3D line or polygon

-
\ No newline at end of file +
\ No newline at end of file diff --git a/docs/types/Coordinates.html b/docs/types/Coordinates.html index cfef393..3db76c1 100644 --- a/docs/types/Coordinates.html +++ b/docs/types/Coordinates.html @@ -1,2 +1,2 @@ -Coordinates | s2json-spec - v1.2.0

Type alias Coordinates

All possible geometry coordinates

-
\ No newline at end of file +Coordinates | s2json-spec - v1.3.0

Type alias Coordinates

All possible geometry coordinates

+
\ No newline at end of file diff --git a/docs/types/Face.html b/docs/types/Face.html index f9edad2..2ffa15d 100644 --- a/docs/types/Face.html +++ b/docs/types/Face.html @@ -1,2 +1,2 @@ -Face | s2json-spec - v1.2.0

Type alias Face

Face: 0 | 1 | 2 | 3 | 4 | 5

cube-face on the S2 sphere

-
\ No newline at end of file +Face | s2json-spec - v1.3.0

Type alias Face

Face: 0 | 1 | 2 | 3 | 4 | 5

cube-face on the S2 sphere

+
\ No newline at end of file diff --git a/docs/types/FeatureCollectionType.html b/docs/types/FeatureCollectionType.html index ae30d24..1f28cf5 100644 --- a/docs/types/FeatureCollectionType.html +++ b/docs/types/FeatureCollectionType.html @@ -1,2 +1,2 @@ -FeatureCollectionType | s2json-spec - v1.2.0

Type alias FeatureCollectionType

FeatureCollectionType: "FeatureCollection" | "S2FeatureCollection"

Types will either be an S2 or WG FeatureCollection

-
\ No newline at end of file +FeatureCollectionType | s2json-spec - v1.3.0

Type alias FeatureCollectionType

FeatureCollectionType: "FeatureCollection" | "S2FeatureCollection"

Types will either be an S2 or WG FeatureCollection

+
\ No newline at end of file diff --git a/docs/types/FeatureCollections.html b/docs/types/FeatureCollections.html index 48eab32..8d90975 100644 --- a/docs/types/FeatureCollections.html +++ b/docs/types/FeatureCollections.html @@ -1,2 +1,2 @@ -FeatureCollections | s2json-spec - v1.2.0

Type alias FeatureCollections

Either an S2 or WG FeatureCollection

-
\ No newline at end of file +FeatureCollections | s2json-spec - v1.3.0

Type alias FeatureCollections

Either an S2 or WG FeatureCollection

+
\ No newline at end of file diff --git a/docs/types/FeatureType.html b/docs/types/FeatureType.html index 631d99e..0521b3e 100644 --- a/docs/types/FeatureType.html +++ b/docs/types/FeatureType.html @@ -1,2 +1,2 @@ -FeatureType | s2json-spec - v1.2.0

Type alias FeatureType

FeatureType: "Feature" | "S2Feature"

Either an S2 or WG Feature type

-
\ No newline at end of file +FeatureType | s2json-spec - v1.3.0

Type alias FeatureType

FeatureType: "Feature" | "S2Feature"

Either an S2 or WG Feature type

+
\ No newline at end of file diff --git a/docs/types/Features.html b/docs/types/Features.html index 8489462..7ff23b9 100644 --- a/docs/types/Features.html +++ b/docs/types/Features.html @@ -1,2 +1,2 @@ -Features | s2json-spec - v1.2.0

Type alias Features

Features: Feature | S2Feature

Either an S2 or WG Feature

-
\ No newline at end of file +Features | s2json-spec - v1.3.0

Type alias Features

Features: Feature | S2Feature

Either an S2 or WG Feature

+
\ No newline at end of file diff --git a/docs/types/Geometry.html b/docs/types/Geometry.html index 5e8285d..3044348 100644 --- a/docs/types/Geometry.html +++ b/docs/types/Geometry.html @@ -1,2 +1,2 @@ -Geometry | s2json-spec - v1.2.0
\ No newline at end of file +Geometry | s2json-spec - v1.3.0
\ No newline at end of file diff --git a/docs/types/GeometryType.html b/docs/types/GeometryType.html index cd0f31a..d2c9cf4 100644 --- a/docs/types/GeometryType.html +++ b/docs/types/GeometryType.html @@ -1,2 +1,2 @@ -GeometryType | s2json-spec - v1.2.0

Type alias GeometryType

GeometryType: "Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "Point3D" | "MultiPoint3D" | "LineString3D" | "MultiLineString3D" | "Polygon3D" | "MultiPolygon3D"

All possible geometry types

-
\ No newline at end of file +GeometryType | s2json-spec - v1.3.0

Type alias GeometryType

GeometryType: "Point" | "MultiPoint" | "LineString" | "MultiLineString" | "Polygon" | "MultiPolygon" | "Point3D" | "MultiPoint3D" | "LineString3D" | "MultiLineString3D" | "Polygon3D" | "MultiPolygon3D"

All possible geometry types

+
\ No newline at end of file diff --git a/docs/types/JSONCollection.html b/docs/types/JSONCollection.html index 9009d3e..4a52b3c 100644 --- a/docs/types/JSONCollection.html +++ b/docs/types/JSONCollection.html @@ -1,2 +1,2 @@ -JSONCollection | s2json-spec - v1.2.0

Type alias JSONCollection

All major S2JSON types

-
\ No newline at end of file +JSONCollection | s2json-spec - v1.3.0

Type alias JSONCollection

All major S2JSON types

+
\ No newline at end of file diff --git a/docs/types/LineString.html b/docs/types/LineString.html index 1c8a1e0..e11bd91 100644 --- a/docs/types/LineString.html +++ b/docs/types/LineString.html @@ -1,2 +1,2 @@ -LineString | s2json-spec - v1.2.0

Type alias LineString

LineString: Point[]

Definition of a LineString

-
\ No newline at end of file +LineString | s2json-spec - v1.3.0

Type alias LineString

LineString: Point[]

Definition of a LineString

+
\ No newline at end of file diff --git a/docs/types/LineString3D.html b/docs/types/LineString3D.html index 37028bf..cebc248 100644 --- a/docs/types/LineString3D.html +++ b/docs/types/LineString3D.html @@ -1,2 +1,2 @@ -LineString3D | s2json-spec - v1.2.0

Type alias LineString3D

LineString3D: Point3D[]

Definition of a 3D LineString

-
\ No newline at end of file +LineString3D | s2json-spec - v1.3.0

Type alias LineString3D

LineString3D: Point3D[]

Definition of a 3D LineString

+
\ No newline at end of file diff --git a/docs/types/LineStringMValues.html b/docs/types/LineStringMValues.html index 833c0ca..7abc44e 100644 --- a/docs/types/LineStringMValues.html +++ b/docs/types/LineStringMValues.html @@ -1,2 +1,2 @@ -LineStringMValues | s2json-spec - v1.2.0

Type alias LineStringMValues<M>

LineStringMValues<M>: M[]

LineString Properties Shape

-

Type Parameters

\ No newline at end of file +LineStringMValues | s2json-spec - v1.3.0

Type alias LineStringMValues<M>

LineStringMValues<M>: M[]

LineString Properties Shape

+

Type Parameters

\ No newline at end of file diff --git a/docs/types/MValue.html b/docs/types/MValue.html index aa17e92..132bd82 100644 --- a/docs/types/MValue.html +++ b/docs/types/MValue.html @@ -1,2 +1,2 @@ -MValue | s2json-spec - v1.2.0

Type alias MValue

MValue: Properties

Shape of a feature's M-Values object

-
\ No newline at end of file +MValue | s2json-spec - v1.3.0

Type alias MValue

MValue: Properties

Shape of a feature's M-Values object

+
\ No newline at end of file diff --git a/docs/types/MValues.html b/docs/types/MValues.html index 4097a65..5cbac28 100644 --- a/docs/types/MValues.html +++ b/docs/types/MValues.html @@ -1,2 +1,2 @@ -MValues | s2json-spec - v1.2.0

Type alias MValues

All possible M-Value shapes

-
\ No newline at end of file +MValues | s2json-spec - v1.3.0

Type alias MValues

All possible M-Value shapes

+
\ No newline at end of file diff --git a/docs/types/MultiLineString.html b/docs/types/MultiLineString.html index f57cb1d..c10ac2e 100644 --- a/docs/types/MultiLineString.html +++ b/docs/types/MultiLineString.html @@ -1,2 +1,2 @@ -MultiLineString | s2json-spec - v1.2.0

Type alias MultiLineString

MultiLineString: LineString[]

Definition of a MultiLineString

-
\ No newline at end of file +MultiLineString | s2json-spec - v1.3.0

Type alias MultiLineString

MultiLineString: LineString[]

Definition of a MultiLineString

+
\ No newline at end of file diff --git a/docs/types/MultiLineString3D.html b/docs/types/MultiLineString3D.html index 93b65c6..f1b9c0f 100644 --- a/docs/types/MultiLineString3D.html +++ b/docs/types/MultiLineString3D.html @@ -1,2 +1,2 @@ -MultiLineString3D | s2json-spec - v1.2.0

Type alias MultiLineString3D

MultiLineString3D: LineString3D[]

Definition of a 3D MultiLineString

-
\ No newline at end of file +MultiLineString3D | s2json-spec - v1.3.0

Type alias MultiLineString3D

MultiLineString3D: LineString3D[]

Definition of a 3D MultiLineString

+
\ No newline at end of file diff --git a/docs/types/MultiLineStringMValues.html b/docs/types/MultiLineStringMValues.html index 680b3a2..7a57c28 100644 --- a/docs/types/MultiLineStringMValues.html +++ b/docs/types/MultiLineStringMValues.html @@ -1,2 +1,2 @@ -MultiLineStringMValues | s2json-spec - v1.2.0

Type alias MultiLineStringMValues<M>

MultiLineStringMValues<M>: M[][]

MultiLineString Properties Shape

-

Type Parameters

\ No newline at end of file +MultiLineStringMValues | s2json-spec - v1.3.0

Type alias MultiLineStringMValues<M>

MultiLineStringMValues<M>: M[][]

MultiLineString Properties Shape

+

Type Parameters

\ No newline at end of file diff --git a/docs/types/MultiPoint.html b/docs/types/MultiPoint.html index f007eab..5d64b3d 100644 --- a/docs/types/MultiPoint.html +++ b/docs/types/MultiPoint.html @@ -1,2 +1,2 @@ -MultiPoint | s2json-spec - v1.2.0

Type alias MultiPoint

MultiPoint: Point[]

Definition of a MultiPoint

-
\ No newline at end of file +MultiPoint | s2json-spec - v1.3.0

Type alias MultiPoint

MultiPoint: Point[]

Definition of a MultiPoint

+
\ No newline at end of file diff --git a/docs/types/MultiPoint3D.html b/docs/types/MultiPoint3D.html index f159911..f013563 100644 --- a/docs/types/MultiPoint3D.html +++ b/docs/types/MultiPoint3D.html @@ -1,2 +1,2 @@ -MultiPoint3D | s2json-spec - v1.2.0

Type alias MultiPoint3D

MultiPoint3D: Point3D[]

Definition of a 3D MultiPoint

-
\ No newline at end of file +MultiPoint3D | s2json-spec - v1.3.0

Type alias MultiPoint3D

MultiPoint3D: Point3D[]

Definition of a 3D MultiPoint

+
\ No newline at end of file diff --git a/docs/types/MultiPolygon.html b/docs/types/MultiPolygon.html index b879006..af5a385 100644 --- a/docs/types/MultiPolygon.html +++ b/docs/types/MultiPolygon.html @@ -1,2 +1,2 @@ -MultiPolygon | s2json-spec - v1.2.0

Type alias MultiPolygon

MultiPolygon: Polygon[]

Definition of a MultiPolygon

-
\ No newline at end of file +MultiPolygon | s2json-spec - v1.3.0

Type alias MultiPolygon

MultiPolygon: Polygon[]

Definition of a MultiPolygon

+
\ No newline at end of file diff --git a/docs/types/MultiPolygon3D.html b/docs/types/MultiPolygon3D.html index 3857f2d..3bb7ce8 100644 --- a/docs/types/MultiPolygon3D.html +++ b/docs/types/MultiPolygon3D.html @@ -1,2 +1,2 @@ -MultiPolygon3D | s2json-spec - v1.2.0

Type alias MultiPolygon3D

MultiPolygon3D: Polygon3D[]

Definition of a 3D MultiPolygon

-
\ No newline at end of file +MultiPolygon3D | s2json-spec - v1.3.0

Type alias MultiPolygon3D

MultiPolygon3D: Polygon3D[]

Definition of a 3D MultiPolygon

+
\ No newline at end of file diff --git a/docs/types/MultiPolygonMValues.html b/docs/types/MultiPolygonMValues.html index ed9022d..4330634 100644 --- a/docs/types/MultiPolygonMValues.html +++ b/docs/types/MultiPolygonMValues.html @@ -1,2 +1,2 @@ -MultiPolygonMValues | s2json-spec - v1.2.0

Type alias MultiPolygonMValues<M>

MultiPolygonMValues<M>: M[][][]

MultiPolygon MValues Shape

-

Type Parameters

\ No newline at end of file +MultiPolygonMValues | s2json-spec - v1.3.0

Type alias MultiPolygonMValues<M>

MultiPolygonMValues<M>: M[][][]

MultiPolygon MValues Shape

+

Type Parameters

\ No newline at end of file diff --git a/docs/types/Point.html b/docs/types/Point.html index 5f486a8..abe089e 100644 --- a/docs/types/Point.html +++ b/docs/types/Point.html @@ -1,2 +1,2 @@ -Point | s2json-spec - v1.2.0

Type alias Point

Point: [x: number, y: number]

Definition of a Point. May represent WebMercator Lon-Lat or S2Geometry S-T

-
\ No newline at end of file +Point | s2json-spec - v1.3.0

Type alias Point

Point: [x: number, y: number]

Definition of a Point. May represent WebMercator Lon-Lat or S2Geometry S-T

+
\ No newline at end of file diff --git a/docs/types/Point3D.html b/docs/types/Point3D.html index 39ce49e..6582736 100644 --- a/docs/types/Point3D.html +++ b/docs/types/Point3D.html @@ -1,2 +1,2 @@ -Point3D | s2json-spec - v1.2.0

Type alias Point3D

Point3D: [x: number, y: number, z: number]

Definition of a 3D Point. May represent WebMercator Lon-Lat or S2Geometry S-T with a z-value

-
\ No newline at end of file +Point3D | s2json-spec - v1.3.0

Type alias Point3D

Point3D: [x: number, y: number, z: number]

Definition of a 3D Point. May represent WebMercator Lon-Lat or S2Geometry S-T with a z-value

+
\ No newline at end of file diff --git a/docs/types/Polygon.html b/docs/types/Polygon.html index aaea207..86aacaf 100644 --- a/docs/types/Polygon.html +++ b/docs/types/Polygon.html @@ -1,2 +1,2 @@ -Polygon | s2json-spec - v1.2.0

Type alias Polygon

Polygon: Point[][]

Definition of a Polygon

-
\ No newline at end of file +Polygon | s2json-spec - v1.3.0

Type alias Polygon

Polygon: Point[][]

Definition of a Polygon

+
\ No newline at end of file diff --git a/docs/types/Polygon3D.html b/docs/types/Polygon3D.html index 20bd45d..49fc0e7 100644 --- a/docs/types/Polygon3D.html +++ b/docs/types/Polygon3D.html @@ -1,2 +1,2 @@ -Polygon3D | s2json-spec - v1.2.0

Type alias Polygon3D

Polygon3D: Point3D[][]

Definition of a 3D Polygon

-
\ No newline at end of file +Polygon3D | s2json-spec - v1.3.0

Type alias Polygon3D

Polygon3D: Point3D[][]

Definition of a 3D Polygon

+
\ No newline at end of file diff --git a/docs/types/PolygonMValues.html b/docs/types/PolygonMValues.html index 658cf33..bba6280 100644 --- a/docs/types/PolygonMValues.html +++ b/docs/types/PolygonMValues.html @@ -1,2 +1,2 @@ -PolygonMValues | s2json-spec - v1.2.0

Type alias PolygonMValues<M>

PolygonMValues<M>: M[][]

Polygon MValues Shape

-

Type Parameters

\ No newline at end of file +PolygonMValues | s2json-spec - v1.3.0

Type alias PolygonMValues<M>

PolygonMValues<M>: M[][]

Polygon MValues Shape

+

Type Parameters

\ No newline at end of file diff --git a/docs/types/Primitive.html b/docs/types/Primitive.html index a451f01..8ad7bec 100644 --- a/docs/types/Primitive.html +++ b/docs/types/Primitive.html @@ -1,2 +1,2 @@ -Primitive | s2json-spec - v1.2.0

Type alias Primitive

Primitive: string | number | boolean | null

Primitive types supported by Properties

-
\ No newline at end of file +Primitive | s2json-spec - v1.3.0

Type alias Primitive

Primitive: string | number | boolean | null

Primitive types supported by Properties

+
\ No newline at end of file diff --git a/docs/types/Properties.html b/docs/types/Properties.html index fecbb4a..c2bba17 100644 --- a/docs/types/Properties.html +++ b/docs/types/Properties.html @@ -1,2 +1,2 @@ -Properties | s2json-spec - v1.2.0

Type alias Properties

Properties: Record<string, Value>

Shape of a features properties object

-
\ No newline at end of file +Properties | s2json-spec - v1.3.0

Type alias Properties

Properties: Record<string, Value>

Shape of a features properties object

+
\ No newline at end of file diff --git a/docs/types/Value.html b/docs/types/Value.html index 63ed6a7..4c32629 100644 --- a/docs/types/Value.html +++ b/docs/types/Value.html @@ -1,5 +1,5 @@ -Value | s2json-spec - v1.2.0

Type alias Value

Value: Primitive | any[] | {
    [key: string]: Value;
}

Supports primitive types string, number, boolean, null +Value | s2json-spec - v1.3.0

Type alias Value

Value: Primitive | any[] | {
    [key: string]: Value;
}

Supports primitive types string, number, boolean, null May be an array of those types, or an object of those types Object keys are always strings, values can be any basic type, an array, or a nested object. Array values must all be the same type.

-

Type declaration

\ No newline at end of file +

Type declaration

\ No newline at end of file diff --git a/docs/types/ValueArray.html b/docs/types/ValueArray.html index 3c651b7..e37e0b0 100644 --- a/docs/types/ValueArray.html +++ b/docs/types/ValueArray.html @@ -1,3 +1,3 @@ -ValueArray | s2json-spec - v1.2.0

Type alias ValueArray

ValueArray: (Primitive | {
        [key: string]: Primitive;
    })[] extends (infer U)[]
    ? U[]
    : never

When an array is used, it must be an array of the same type. +ValueArray | s2json-spec - v1.3.0

Type alias ValueArray

ValueArray: (Primitive | {
        [key: string]: Primitive;
    })[] extends (infer U)[]
    ? U[]
    : never

When an array is used, it must be an array of the same type. Arrays are also limited to primitives and objects of primitives

-
\ No newline at end of file +
\ No newline at end of file diff --git a/package.json b/package.json index 9b2b04a..924d71e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "s2json-spec", "publisher": "OpenS2", - "version": "1.2.0", + "version": "1.3.0", "description": "S2JSON is a specification for encoding a variety of geographic data structures", "keywords": [ "vector", @@ -34,6 +34,7 @@ "prettier:fix": "bunx prettier -- --write", "format": "bunx prettier:fix && bun run lint:fix", "build": "tsc -p ./", + "test:dev": "bun test --watch --coverage", "test": "bun test", "test:watch": "bun test --watch", "types:bundle": "bun run types:build && node scripts/types.mjs", diff --git a/rust/geometry.rs b/rust/geometry.rs index b9dc23b..f28d197 100644 --- a/rust/geometry.rs +++ b/rust/geometry.rs @@ -97,12 +97,12 @@ pub struct BBox3D { pub right: T, /// top most latitude (WG) or S (S2) pub top: T, - /// front most height (WG) or T (S2) - /// generic height is relative to the surface of the earth in meters - pub front: T, /// back most height (WG) or T (S2) /// generic height is relative to the surface of the earth in meters pub back: T, + /// front most height (WG) or T (S2) + /// generic height is relative to the surface of the earth in meters + pub front: T, } impl Serialize for BBox3D where @@ -117,8 +117,8 @@ where seq.serialize_element(&self.bottom)?; seq.serialize_element(&self.right)?; seq.serialize_element(&self.top)?; - seq.serialize_element(&self.front)?; seq.serialize_element(&self.back)?; + seq.serialize_element(&self.front)?; seq.end() } } @@ -157,11 +157,11 @@ where .ok_or_else(|| de::Error::invalid_length(2, &self))?; let top = seq.next_element()? .ok_or_else(|| de::Error::invalid_length(3, &self))?; - let front = seq.next_element()? - .ok_or_else(|| de::Error::invalid_length(4, &self))?; let back = seq.next_element()? + .ok_or_else(|| de::Error::invalid_length(4, &self))?; + let front = seq.next_element()? .ok_or_else(|| de::Error::invalid_length(5, &self))?; - Ok(BBox3D { left, bottom, right, top, front, back }) + Ok(BBox3D { left, bottom, right, top, back, front }) } } @@ -268,4 +268,130 @@ pub type MultiLineString3DGeometry = BaseGeometry; /// MultiPolygon3DGeometry is a 3D polygon with multiple polygons with their own potential holes -pub type MultiPolygon3DGeometry = BaseGeometry; +pub type MultiPolygon3DGeometry = BaseGeometry; + +#[cfg(test)] +mod tests { + use super::*; + use alloc::vec; + + #[test] + fn test_bbox() { + let bbox = BBox { left: 0.0, bottom: 0.0, right: 1.0, top: 1.0 }; + assert_eq!(bbox, BBox { left: 0.0, bottom: 0.0, right: 1.0, top: 1.0 }); + let bbox_str = serde_json::to_string(&bbox).unwrap(); + assert_eq!(bbox_str, "[0.0,0.0,1.0,1.0]"); + let str_bbox: BBox = serde_json::from_str(&bbox_str).unwrap(); + assert_eq!(str_bbox, bbox); + } + + #[test] + fn test_bbox3d() { + let bbox = BBox3D { left: 0.0, bottom: 0.0, right: 1.0, top: 1.0, back: 0.0, front: 1.0 }; + assert_eq!(bbox, BBox3D { left: 0.0, bottom: 0.0, right: 1.0, top: 1.0, back: 0.0, front: 1.0 }); + let bbox_str = serde_json::to_string(&bbox).unwrap(); + assert_eq!(bbox_str, "[0.0,0.0,1.0,1.0,0.0,1.0]"); + let str_bbox: BBox3D = serde_json::from_str(&bbox_str).unwrap(); + assert_eq!(str_bbox, bbox); + } + + #[test] + fn test_point_geometry() { + let point = PointGeometry { coordinates: (0.0, 0.0), m_values: None, bbox: None }; + assert_eq!(point, PointGeometry { coordinates: (0.0, 0.0), m_values: None, bbox: None }); + let point_str = serde_json::to_string(&point).unwrap(); + assert_eq!(point_str, "{\"coordinates\":[0.0,0.0]}"); + let str_point: PointGeometry = serde_json::from_str(&point_str).unwrap(); + assert_eq!(str_point, point); + } + + #[test] + fn test_point3d_geometry() { + let point = Point3DGeometry { coordinates: (0.0, 0.0, 0.0), m_values: None, bbox: Some(BBox3D { left: 0.0, bottom: 0.0, right: 1.0, top: 1.0, back: 0.0, front: 1.0 }) }; + assert_eq!(point, Point3DGeometry { coordinates: (0.0, 0.0, 0.0), m_values: None, bbox: Some(BBox3D { left: 0.0, bottom: 0.0, right: 1.0, top: 1.0, back: 0.0, front: 1.0 }) }); + let point_str = serde_json::to_string(&point).unwrap(); + assert_eq!(point_str, "{\"coordinates\":[0.0,0.0,0.0],\"bbox\":[0.0,0.0,1.0,1.0,0.0,1.0]}"); + let str_point: Point3DGeometry = serde_json::from_str(&point_str).unwrap(); + assert_eq!(str_point, point); + } + + #[test] + fn test_line_string_geometry() { + let line = LineStringGeometry { coordinates: vec![(0.0, 0.0), (1.0, 1.0)], m_values: None, bbox: None }; + assert_eq!(line, LineStringGeometry { coordinates: vec![(0.0, 0.0), (1.0, 1.0)], m_values: None, bbox: None }); + let line_str = serde_json::to_string(&line).unwrap(); + assert_eq!(line_str, "{\"coordinates\":[[0.0,0.0],[1.0,1.0]]}"); + let str_line: LineStringGeometry = serde_json::from_str(&line_str).unwrap(); + assert_eq!(str_line, line); + } + + #[test] + fn test_line_string3d_geometry() { + let line = LineString3DGeometry { coordinates: vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)], m_values: None, bbox: None }; + assert_eq!(line, LineString3DGeometry { coordinates: vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)], m_values: None, bbox: None }); + let line_str = serde_json::to_string(&line).unwrap(); + assert_eq!(line_str, "{\"coordinates\":[[0.0,0.0,0.0],[1.0,1.0,1.0]]}"); + let str_line: LineString3DGeometry = serde_json::from_str(&line_str).unwrap(); + assert_eq!(str_line, line); + } + + #[test] + fn test_multi_point_geometry() { + let multi_point = MultiPointGeometry { coordinates: vec![(0.0, 0.0), (1.0, 1.0)], m_values: None, bbox: None }; + assert_eq!(multi_point, MultiPointGeometry { coordinates: vec![(0.0, 0.0), (1.0, 1.0)], m_values: None, bbox: None }); + let multi_point_str = serde_json::to_string(&multi_point).unwrap(); + assert_eq!(multi_point_str, "{\"coordinates\":[[0.0,0.0],[1.0,1.0]]}"); + let str_multi_point: MultiPointGeometry = serde_json::from_str(&multi_point_str).unwrap(); + assert_eq!(str_multi_point, multi_point); + } + + #[test] + fn test_multi_point3d_geometry() { + let multi_point = MultiPoint3DGeometry { coordinates: vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)], m_values: None, bbox: None }; + assert_eq!(multi_point, MultiPoint3DGeometry { coordinates: vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0)], m_values: None, bbox: None }); + let multi_point_str = serde_json::to_string(&multi_point).unwrap(); + assert_eq!(multi_point_str, "{\"coordinates\":[[0.0,0.0,0.0],[1.0,1.0,1.0]]}"); + let str_multi_point: MultiPoint3DGeometry = serde_json::from_str(&multi_point_str).unwrap(); + assert_eq!(str_multi_point, multi_point); + } + + #[test] + fn test_polygon_geometry() { + let polygon = PolygonGeometry { coordinates: vec![vec![(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]], m_values: None, bbox: None }; + assert_eq!(polygon, PolygonGeometry { coordinates: vec![vec![(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]], m_values: None, bbox: None }); + let polygon_str = serde_json::to_string(&polygon).unwrap(); + assert_eq!(polygon_str, "{\"coordinates\":[[[0.0,0.0],[1.0,1.0],[0.0,1.0]]]}"); + let str_polygon: PolygonGeometry = serde_json::from_str(&polygon_str).unwrap(); + assert_eq!(str_polygon, polygon); + } + + #[test] + fn test_polygon3d_geometry() { + let polygon = Polygon3DGeometry { coordinates: vec![vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]], m_values: None, bbox: None }; + assert_eq!(polygon, Polygon3DGeometry { coordinates: vec![vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]], m_values: None, bbox: None }); + let polygon_str = serde_json::to_string(&polygon).unwrap(); + assert_eq!(polygon_str, "{\"coordinates\":[[[0.0,0.0,0.0],[1.0,1.0,1.0],[0.0,1.0,1.0]]]}"); + let str_polygon: Polygon3DGeometry = serde_json::from_str(&polygon_str).unwrap(); + assert_eq!(str_polygon, polygon); + } + + #[test] + fn test_multi_polygon_geometry() { + let multi_polygon = MultiPolygonGeometry { coordinates: vec![vec![vec![(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]]], m_values: None, bbox: None }; + assert_eq!(multi_polygon, MultiPolygonGeometry { coordinates: vec![vec![vec![(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]]], m_values: None, bbox: None }); + let multi_polygon_str = serde_json::to_string(&multi_polygon).unwrap(); + assert_eq!(multi_polygon_str, "{\"coordinates\":[[[[0.0,0.0],[1.0,1.0],[0.0,1.0]]]]}"); + let str_multi_polygon: MultiPolygonGeometry = serde_json::from_str(&multi_polygon_str).unwrap(); + assert_eq!(str_multi_polygon, multi_polygon); + } + + #[test] + fn test_multi_polygon3d_geometry() { + let multi_polygon = MultiPolygon3DGeometry { coordinates: vec![vec![vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]]], m_values: None, bbox: None }; + assert_eq!(multi_polygon, MultiPolygon3DGeometry { coordinates: vec![vec![vec![(0.0, 0.0, 0.0), (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]]], m_values: None, bbox: None }); + let multi_polygon_str = serde_json::to_string(&multi_polygon).unwrap(); + assert_eq!(multi_polygon_str, "{\"coordinates\":[[[[0.0,0.0,0.0],[1.0,1.0,1.0],[0.0,1.0,1.0]]]]}"); + let str_multi_polygon: MultiPolygon3DGeometry = serde_json::from_str(&multi_polygon_str).unwrap(); + assert_eq!(str_multi_polygon, multi_polygon); + } +} \ No newline at end of file diff --git a/rust/lib.rs b/rust/lib.rs index ccfc1ea..6bf6dbc 100644 --- a/rust/lib.rs +++ b/rust/lib.rs @@ -127,6 +127,7 @@ pub type Attributions = BTreeMap; /// Either an S2 or WG FeatureCollection #[derive(Serialize, Deserialize, Debug, PartialEq)] +#[serde(untagged)] pub enum FeatureCollections { /// An WG FeatureCollection FeatureCollection(FeatureCollection), @@ -136,6 +137,7 @@ pub enum FeatureCollections { /// Either an S2 or WG Feature #[derive(Serialize, Deserialize, Debug, PartialEq)] +#[serde(untagged)] pub enum Features { /// An WG Feature Feature(Feature), @@ -145,6 +147,7 @@ pub enum Features { /// All major S2JSON types #[derive(Serialize, Deserialize, Debug, PartialEq)] +#[serde(untagged)] pub enum JSONCollection { /// An WG FeatureCollection FeatureCollection(FeatureCollection), @@ -158,11 +161,28 @@ pub enum JSONCollection { #[cfg(test)] mod tests { - // use super::*; + use super::*; #[test] - fn it_works() { - let result = 2 + 2; - assert_eq!(result, 4); + fn face() { + let face = Face::Face0; + assert_eq!(u8::from(face), 0); + let face = Face::Face1; + assert_eq!(u8::from(face), 1); + let face = Face::Face2; + assert_eq!(u8::from(face), 2); + let face = Face::Face3; + assert_eq!(u8::from(face), 3); + let face = Face::Face4; + assert_eq!(u8::from(face), 4); + let face = Face::Face5; + assert_eq!(u8::from(face), 5); + + assert_eq!(Face::Face0, Face::from(0)); + assert_eq!(Face::Face1, Face::from(1)); + assert_eq!(Face::Face2, Face::from(2)); + assert_eq!(Face::Face3, Face::from(3)); + assert_eq!(Face::Face4, Face::from(4)); + assert_eq!(Face::Face5, Face::from(5)); } -} \ No newline at end of file +} diff --git a/rust/values.rs b/rust/values.rs index 9a38bf6..24bcbff 100644 --- a/rust/values.rs +++ b/rust/values.rs @@ -7,6 +7,7 @@ use alloc::collections::BTreeMap; /// Primitive types supported by Properties #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(untagged)] pub enum PrimitiveValue { /// String type utf8 encoded String(String), @@ -46,15 +47,15 @@ pub enum ValueType { /// An array of values Array(Vec), /// A nested object - Nested(Value), + Nested(Shape), } /// Shape design -pub type Value = BTreeMap; +pub type Shape = BTreeMap; /// Shape of a features properties object -pub type Properties = Value; +pub type Properties = Shape; /// Shape of a feature's M-Values object -pub type MValue = Value; +pub type MValue = Shape; /// LineString Properties Shape pub type LineStringMValues = Vec; @@ -67,6 +68,7 @@ pub type MultiPolygonMValues = Vec; /// All possible M-Value shapes #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[serde(untagged)] pub enum MValues { /// Single M-Value MValue(MValue), @@ -79,3 +81,122 @@ pub enum MValues { /// MultiPolygon M-Value MultiPolygonMValues(MultiPolygonMValues), } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn primitive_value() { + let prim_value = PrimitiveValue::String("test".into()); + assert_eq!(prim_value, PrimitiveValue::String("test".into())); + let prim_value = PrimitiveValue::U64(1); + assert_eq!(prim_value, PrimitiveValue::U64(1)); + let prim_value = PrimitiveValue::I64(1); + assert_eq!(prim_value, PrimitiveValue::I64(1)); + let prim_value = PrimitiveValue::F32(1.0); + assert_eq!(prim_value, PrimitiveValue::F32(1.0)); + let prim_value = PrimitiveValue::F64(1.0); + assert_eq!(prim_value, PrimitiveValue::F64(1.0)); + let prim_value = PrimitiveValue::Bool(true); + assert_eq!(prim_value, PrimitiveValue::Bool(true)); + let prim_value = PrimitiveValue::Null; + assert_eq!(prim_value, PrimitiveValue::Null); + } + + #[test] + fn primitive_string_serialize() { + let prim_value = PrimitiveValue::String("test".into()); + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "\"test\""); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::String("test".into())); + } + + #[test] + fn primitive_u64_serialize() { + let prim_value = PrimitiveValue::U64(1); + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "1"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::U64(1)); + } + + #[test] + fn primitive_i64_serialize() { + let prim_value = PrimitiveValue::I64(-1); + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "-1"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::I64(-1)); + } + + #[test] + fn primitive_f32_serialize() { + let prim_value = PrimitiveValue::F32(1.0); + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "1.0"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::F32(1.0)); + } + + #[test] + fn primitive_f64_serialize() { + let prim_value = PrimitiveValue::F64(-135435345435345345.0); + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "-1.3543534543534534e17"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::F32(-1.3543534e17)); + } + + #[test] + fn primitive_bool_serialize() { + let prim_value = PrimitiveValue::Bool(true); + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "true"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::Bool(true)); + } + + #[test] + fn primitive_null_serialize() { + let prim_value = PrimitiveValue::Null; + let serialized = serde_json::to_string(&prim_value).unwrap(); + assert_eq!(serialized, "null"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, PrimitiveValue::Null); + } + + #[test] + fn shape_serialize() { + let shape: Shape = BTreeMap::from([ + ("type".into(), ValueType::Primitive(PrimitiveValue::String("Point".into()))), + ("coordinates".into(), ValueType::Primitive(PrimitiveValue::F32(1.0))), + ]); + let serialized = serde_json::to_string(&shape).unwrap(); + assert_eq!(serialized, "{\"coordinates\":1.0,\"type\":\"Point\"}"); + let deserialize = serde_json::from_str::(&serialized).unwrap(); + assert_eq!(deserialize, shape); + + let shape_str = r#" + { + "class": "ocean", + "offset": 22, + "info": { + "name": "Pacific Ocean", + "value": 22.2 + } + } + "#; + + let deserialize = serde_json::from_str::(shape_str).unwrap(); + assert_eq!(deserialize, BTreeMap::from([ + ("class".into(), ValueType::Primitive(PrimitiveValue::String("ocean".into()))), + ("offset".into(), ValueType::Primitive(PrimitiveValue::U64(22))), + ("info".into(), ValueType::Nested(BTreeMap::from([ + ("name".into(), ValueType::Primitive(PrimitiveValue::String("Pacific Ocean".into()))), + ("value".into(), ValueType::Primitive(PrimitiveValue::F32(22.2))), + ]))), + ])); + } +} diff --git a/s2json-spec/1.0.0/README.md b/s2json-spec/1.0.0/README.md index fe14bb4..4f437ad 100755 --- a/s2json-spec/1.0.0/README.md +++ b/s2json-spec/1.0.0/README.md @@ -132,7 +132,7 @@ Example: ### 5.2. Array Values -Array values are ordered lists of values. Once you use an array, each item MUST be of the same type. Each item MUST be either a primitive value or an object whose keys are strings and values are primitive values. +Array values are ordered lists of values. Once you use an array, each item MUST be of the same type. Each item MUST be either a primitive value or an object whose keys are strings and values are primitive values. The maximum number of items in an array is 16. Example: diff --git a/src/s2json.schema.json b/src/s2json.schema.json index 3adc8e9..9a701f4 100644 --- a/src/s2json.schema.json +++ b/src/s2json.schema.json @@ -79,6 +79,8 @@ }, "valueArray": { "type": "array", + "minItems": 0, + "maxItems": 16, "items": { "oneOf": [ { "$ref": "#/definitions/primitive" },