Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CesiumGS/cesium-native into fix-mis…
Browse files Browse the repository at this point in the history
…sing-ellipsoid
  • Loading branch information
azrogers committed Oct 29, 2024
2 parents a2b31a0 + 434e51f commit 0c16b69
Show file tree
Hide file tree
Showing 14 changed files with 366 additions and 84 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

### Not Released Yet

##### Breaking Changes :mega:

- Renamed `CesiumUtility/Gunzip.h` to `CesiumUtility/Gzip.h`.

##### Additions :tada:

- Added `CesiumUtility::gzip`.
- Added `CesiumGeometry::Transforms::getUpAxisTransform` to get the transform that converts from one up axis to another.

### v0.40.1 - 2024-10-01

##### Fixes :wrench:
Expand Down
2 changes: 1 addition & 1 deletion CesiumAsync/src/GunzipAssetAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "CesiumAsync/AsyncSystem.h"
#include "CesiumAsync/IAssetResponse.h"
#include "CesiumUtility/Gunzip.h"
#include "CesiumUtility/Gzip.h"

namespace CesiumAsync {

Expand Down
12 changes: 12 additions & 0 deletions CesiumGeometry/include/CesiumGeometry/Transforms.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "Axis.h"
#include "Library.h"

#include <glm/fwd.hpp>
Expand Down Expand Up @@ -83,6 +84,17 @@ struct CESIUMGEOMETRY_API Transforms final {
glm::dvec3* pTranslation,
glm::dquat* pRotation,
glm::dvec3* pScale);

/**
* @brief Gets a transform that converts from one up axis to another.
*
* @param from The up axis to convert from.
* @param to The up axis to convert to.
*
* @returns The up axis transform.
*/
static const glm::dmat4&
getUpAxisTransform(CesiumGeometry::Axis from, CesiumGeometry::Axis to);
};

} // namespace CesiumGeometry
41 changes: 41 additions & 0 deletions CesiumGeometry/src/Transforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,45 @@ void Transforms::computeTranslationRotationScaleFromMatrix(
*pTranslation = glm::dvec3(matrix[3]);
}

namespace {
const glm::dmat4 Identity(1.0);
}

const glm::dmat4& Transforms::getUpAxisTransform(Axis from, Axis to) {
switch (from) {
case Axis::X:
switch (to) {
case Axis::X:
return Identity;
case Axis::Y:
return X_UP_TO_Y_UP;
case Axis::Z:
return X_UP_TO_Z_UP;
}
break;
case Axis::Y:
switch (to) {
case Axis::X:
return Y_UP_TO_X_UP;
case Axis::Y:
return Identity;
case Axis::Z:
return Y_UP_TO_Z_UP;
}
break;
case Axis::Z:
switch (to) {
case Axis::X:
return Z_UP_TO_X_UP;
case Axis::Y:
return Z_UP_TO_Y_UP;
case Axis::Z:
return Identity;
}
break;
}

return Identity;
}

} // namespace CesiumGeometry
91 changes: 73 additions & 18 deletions CesiumGeometry/test/TestTransforms.cpp
Original file line number Diff line number Diff line change
@@ -1,46 +1,101 @@
#include "CesiumGeometry/Axis.h"
#include "CesiumGeometry/Transforms.h"

#include <CesiumUtility/Math.h>

#include <catch2/catch.hpp>
#include <glm/mat4x4.hpp>

using namespace CesiumGeometry;

TEST_CASE("Transforms convert the axes correctly") {

glm::dvec4 X_AXIS{1.0, 0.0, 0.0, 0.0};
glm::dvec4 Y_AXIS{0.0, 1.0, 0.0, 0.0};
glm::dvec4 Z_AXIS{0.0, 0.0, 1.0, 0.0};

SECTION("Y_UP_TO_Z_UP transforms X to X, Y to -Z, and Z to Y") {
REQUIRE(X_AXIS * CesiumGeometry::Transforms::Y_UP_TO_Z_UP == X_AXIS);
REQUIRE(Y_AXIS * CesiumGeometry::Transforms::Y_UP_TO_Z_UP == -Z_AXIS);
REQUIRE(Z_AXIS * CesiumGeometry::Transforms::Y_UP_TO_Z_UP == Y_AXIS);
REQUIRE(X_AXIS * Transforms::Y_UP_TO_Z_UP == X_AXIS);
REQUIRE(Y_AXIS * Transforms::Y_UP_TO_Z_UP == -Z_AXIS);
REQUIRE(Z_AXIS * Transforms::Y_UP_TO_Z_UP == Y_AXIS);
}
SECTION("Z_UP_TO_Y_UP transforms X to X, Y to Z, and Z to -Y") {
REQUIRE(X_AXIS * CesiumGeometry::Transforms::Z_UP_TO_Y_UP == X_AXIS);
REQUIRE(Y_AXIS * CesiumGeometry::Transforms::Z_UP_TO_Y_UP == Z_AXIS);
REQUIRE(Z_AXIS * CesiumGeometry::Transforms::Z_UP_TO_Y_UP == -Y_AXIS);
REQUIRE(X_AXIS * Transforms::Z_UP_TO_Y_UP == X_AXIS);
REQUIRE(Y_AXIS * Transforms::Z_UP_TO_Y_UP == Z_AXIS);
REQUIRE(Z_AXIS * Transforms::Z_UP_TO_Y_UP == -Y_AXIS);
}

SECTION("X_UP_TO_Z_UP transforms X to -Z, Y to Y, and Z to X") {
REQUIRE(X_AXIS * CesiumGeometry::Transforms::X_UP_TO_Z_UP == -Z_AXIS);
REQUIRE(Y_AXIS * CesiumGeometry::Transforms::X_UP_TO_Z_UP == Y_AXIS);
REQUIRE(Z_AXIS * CesiumGeometry::Transforms::X_UP_TO_Z_UP == X_AXIS);
REQUIRE(X_AXIS * Transforms::X_UP_TO_Z_UP == -Z_AXIS);
REQUIRE(Y_AXIS * Transforms::X_UP_TO_Z_UP == Y_AXIS);
REQUIRE(Z_AXIS * Transforms::X_UP_TO_Z_UP == X_AXIS);
}
SECTION("Z_UP_TO_X_UP transforms X to Z, Y to Y, and Z to -X") {
REQUIRE(X_AXIS * CesiumGeometry::Transforms::Z_UP_TO_X_UP == Z_AXIS);
REQUIRE(Y_AXIS * CesiumGeometry::Transforms::Z_UP_TO_X_UP == Y_AXIS);
REQUIRE(Z_AXIS * CesiumGeometry::Transforms::Z_UP_TO_X_UP == -X_AXIS);
REQUIRE(X_AXIS * Transforms::Z_UP_TO_X_UP == Z_AXIS);
REQUIRE(Y_AXIS * Transforms::Z_UP_TO_X_UP == Y_AXIS);
REQUIRE(Z_AXIS * Transforms::Z_UP_TO_X_UP == -X_AXIS);
}

SECTION("X_UP_TO_Y_UP transforms X to -Y, Y to X, and Z to Z") {
REQUIRE(X_AXIS * CesiumGeometry::Transforms::X_UP_TO_Y_UP == -Y_AXIS);
REQUIRE(Y_AXIS * CesiumGeometry::Transforms::X_UP_TO_Y_UP == X_AXIS);
REQUIRE(Z_AXIS * CesiumGeometry::Transforms::X_UP_TO_Y_UP == Z_AXIS);
REQUIRE(X_AXIS * Transforms::X_UP_TO_Y_UP == -Y_AXIS);
REQUIRE(Y_AXIS * Transforms::X_UP_TO_Y_UP == X_AXIS);
REQUIRE(Z_AXIS * Transforms::X_UP_TO_Y_UP == Z_AXIS);
}
SECTION("Y_UP_TO_X_UP transforms X to Y, Y to -X, and Z to Z") {
REQUIRE(X_AXIS * CesiumGeometry::Transforms::Y_UP_TO_X_UP == Y_AXIS);
REQUIRE(Y_AXIS * CesiumGeometry::Transforms::Y_UP_TO_X_UP == -X_AXIS);
REQUIRE(Z_AXIS * CesiumGeometry::Transforms::Y_UP_TO_X_UP == Z_AXIS);
REQUIRE(X_AXIS * Transforms::Y_UP_TO_X_UP == Y_AXIS);
REQUIRE(Y_AXIS * Transforms::Y_UP_TO_X_UP == -X_AXIS);
REQUIRE(Z_AXIS * Transforms::Y_UP_TO_X_UP == Z_AXIS);
}
}

TEST_CASE("Gets up axis transform") {
const glm::dmat4 Identity(1.0);

SECTION("Gets X-up to X-up transform") {
CHECK(Transforms::getUpAxisTransform(Axis::X, Axis::X) == Identity);
}

SECTION("Gets X-up to Y-up transform") {
CHECK(
Transforms::getUpAxisTransform(Axis::X, Axis::Y) ==
Transforms::X_UP_TO_Y_UP);
}

SECTION("Gets X-up to Z-up transform") {
CHECK(
Transforms::getUpAxisTransform(Axis::X, Axis::Z) ==
Transforms::X_UP_TO_Z_UP);
}

SECTION("Gets Y-up to X-up transform") {
CHECK(
Transforms::getUpAxisTransform(Axis::Y, Axis::X) ==
Transforms::Y_UP_TO_X_UP);
}

SECTION("Gets Y-up to Y-up transform") {
CHECK(Transforms::getUpAxisTransform(Axis::Y, Axis::Y) == Identity);
}

SECTION("Gets Y-up to Z-up transform") {
CHECK(
Transforms::getUpAxisTransform(Axis::Y, Axis::Z) ==
Transforms::Y_UP_TO_Z_UP);
}

SECTION("Gets Z-up to X-up transform") {
CHECK(
Transforms::getUpAxisTransform(Axis::Z, Axis::X) ==
Transforms::Z_UP_TO_X_UP);
}

SECTION("Gets Z-up to Y-up transform") {
CHECK(
Transforms::getUpAxisTransform(Axis::Z, Axis::Y) ==
Transforms::Z_UP_TO_Y_UP);
}

SECTION("Gets Z-up to Z-up transform") {
CHECK(Transforms::getUpAxisTransform(Axis::Z, Axis::Z) == Identity);
}
}
1 change: 1 addition & 0 deletions CesiumUtility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set_target_properties(CesiumUtility
PROPERTIES
TEST_SOURCES "${CESIUM_UTILITY_TEST_SOURCES}"
TEST_HEADERS "${CESIUM_UTILITY_TEST_HEADERS}"
TEST_DATA_DIR ${CMAKE_CURRENT_LIST_DIR}/test/data
)

set_target_properties(CesiumUtility
Expand Down
14 changes: 0 additions & 14 deletions CesiumUtility/include/CesiumUtility/Gunzip.h

This file was deleted.

45 changes: 45 additions & 0 deletions CesiumUtility/include/CesiumUtility/Gzip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once
#include <gsl/span>

#include <vector>

namespace CesiumUtility {

/**
* @brief Checks whether the data is gzipped.
*
* @param data The data.
*
* @returns Whether the data is gzipped
*/
bool isGzip(const gsl::span<const std::byte>& data);

/**
* @brief Gzips data.
*
* If successful, it will return true and the result will be in the
* provided vector.
*
* @param data The data to gzip.
* @param out The gzipped data.
*
* @returns True if successful, false otherwise.
*/
bool gzip(const gsl::span<const std::byte>& data, std::vector<std::byte>& out);

/**
* @brief Gunzips data.
*
* If successful, it will return true and the result will be in the
* provided vector.
*
* @param data The data to gunzip.
* @param out The gunzipped data.
*
* @returns True if successful, false otherwise.
*/
bool gunzip(
const gsl::span<const std::byte>& data,
std::vector<std::byte>& out);

} // namespace CesiumUtility
51 changes: 0 additions & 51 deletions CesiumUtility/src/Gunzip.cpp

This file was deleted.

Loading

0 comments on commit 0c16b69

Please sign in to comment.