diff --git a/modules/globebrowsing/tile/tile.h b/modules/globebrowsing/tile/tile.h index 21c0cc5ece..1a3e643f36 100644 --- a/modules/globebrowsing/tile/tile.h +++ b/modules/globebrowsing/tile/tile.h @@ -37,115 +37,115 @@ namespace openspace { namespace globebrowsing { - struct TileMetaData { - std::vector maxValues; - std::vector minValues; - std::vector hasMissingData; +struct TileMetaData { + std::vector maxValues; + std::vector minValues; + std::vector hasMissingData; - void serialize(std::ostream& s); - static TileMetaData deserialize(std::istream& s); - }; + void serialize(std::ostream& s); + static TileMetaData deserialize(std::istream& s); +}; - struct TextureFormat { - ghoul::opengl::Texture::Format ghoulFormat; - GLuint glFormat; - }; +struct TextureFormat { + ghoul::opengl::Texture::Format ghoulFormat; + GLuint glFormat; +}; - using namespace ghoul::opengl; +using namespace ghoul::opengl; - struct RawTile { - RawTile(); +struct RawTile { + RawTile(); - char* imageData; - glm::uvec3 dimensions; - std::shared_ptr tileMetaData; - TileIndex tileIndex; - CPLErr error; - size_t nBytesImageData; + char* imageData; + glm::uvec3 dimensions; + std::shared_ptr tileMetaData; + TileIndex tileIndex; + CPLErr error; + size_t nBytesImageData; - void serializeMetaData(std::ostream& s); - static RawTile deserializeMetaData(std::istream& s); + void serializeMetaData(std::ostream& s); + static RawTile deserializeMetaData(std::istream& s); - static RawTile createDefaultRes(); + static RawTile createDefaultRes(); - }; +}; - struct TileUvTransform { - glm::vec2 uvOffset; - glm::vec2 uvScale; - }; +struct TileUvTransform { + glm::vec2 uvOffset; + glm::vec2 uvScale; +}; +/** +* Defines a status and may have a Texture and TileMetaData +*/ +struct Tile { + std::shared_ptr texture; + std::shared_ptr metaData; + /** - * Defines a status and may have a Texture and TileMetaData + * Describe if this Tile is good for usage (OK) or otherwise + * the reason why it is not. */ - struct Tile { - std::shared_ptr texture; - std::shared_ptr metaData; + enum class Status { + /** + * E.g when texture data is not currently in memory. + * texture and tileMetaData are both null + */ + Unavailable, /** - * Describe if this Tile is good for usage (OK) or otherwise - * the reason why it is not. + * Can be set by TileProviders if the requested + * TileIndex is undefined for that particular + * provider. + * texture and metaData are both null */ - enum class Status { - /** - * E.g when texture data is not currently in memory. - * texture and tileMetaData are both null - */ - Unavailable, + OutOfRange, - /** - * Can be set by TileProviders if the requested - * TileIndex is undefined for that particular - * provider. - * texture and metaData are both null - */ - OutOfRange, + /** + * An IO Error happend + * texture and metaData are both null + */ + IOError, - /** - * An IO Error happend - * texture and metaData are both null - */ - IOError, - - /** - * The Texture is uploaded to the GPU and good for usage. - * texture is defined. metaData may be defined. - */ - OK - } status; + /** + * The Texture is uploaded to the GPU and good for usage. + * texture is defined. metaData may be defined. + */ + OK + } status; - /** - * Instantiates a new tile with a single color. - * - * \param size The size of texture to be created - * \param color defined RGBA values in range 0-255. - * - * \returns a Tile with status OK and the a texture - * with the requested size and color - */ - static Tile createPlainTile(const glm::uvec2& size, const glm::uvec4& color); - - static glm::vec2 compensateSourceTextureSampling( - glm::vec2 startOffset, - glm::vec2 sizeDiff, - glm::uvec2 resolution, - glm::vec2 tileUV); - - static glm::vec2 TileUvToTextureSamplePosition( - const TileUvTransform uvTransform, - glm::vec2 tileUV, - glm::uvec2 resolution); - - /** - * A tile with status unavailable that any user can return to - * indicate that a tile was unavailable. + /** + * Instantiates a new tile with a single color. + * + * \param size The size of texture to be created + * \param color defined RGBA values in range 0-255. + * + * \returns a Tile with status OK and the a texture + * with the requested size and color */ - static const Tile TileUnavailable; + static Tile createPlainTile(const glm::uvec2& size, const glm::uvec4& color); - }; + static glm::vec2 compensateSourceTextureSampling( + glm::vec2 startOffset, + glm::vec2 sizeDiff, + glm::uvec2 resolution, + glm::vec2 tileUV); + + static glm::vec2 TileUvToTextureSamplePosition( + const TileUvTransform uvTransform, + glm::vec2 tileUV, + glm::uvec2 resolution); + + /** + * A tile with status unavailable that any user can return to + * indicate that a tile was unavailable. + */ + static const Tile TileUnavailable; + +}; } // namespace globebrowsing } // namespace openspace diff --git a/modules/globebrowsing/tile/tileindex.h b/modules/globebrowsing/tile/tileindex.h index 44b9b15d6b..f5fc7b67b1 100644 --- a/modules/globebrowsing/tile/tileindex.h +++ b/modules/globebrowsing/tile/tileindex.h @@ -31,7 +31,7 @@ #include #include -namespace ghoul{ +namespace ghoul { class Dictionary; } diff --git a/modules/globebrowsing/tile/tileprovider/texttileprovider.h b/modules/globebrowsing/tile/tileprovider/texttileprovider.h index e834195947..d9fef49b20 100644 --- a/modules/globebrowsing/tile/tileprovider/texttileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/texttileprovider.h @@ -25,6 +25,8 @@ #ifndef __TEXT_TILE_PROVIDER_H__ #define __TEXT_TILE_PROVIDER_H__ +#include + #include #include @@ -37,109 +39,108 @@ #include #include -#include #include #include ////////////////////////////////////////////////////////////////////////////////////////// -// TILE PROVIDER // +// TILE PROVIDER // ////////////////////////////////////////////////////////////////////////////////////////// namespace openspace { namespace globebrowsing { - using namespace ghoul::fontrendering; +using namespace ghoul::fontrendering; - /** - * Enables a simple way of providing tiles with any type of rendered text. - * Internally it handles setting up a FBO for rendering the text, and defines a new - * interface, consisting of only a single method for subclasses to implement: - * renderText(const FontRenderer&, const TileIndex&) const; - */ - class TextTileProvider : public TileProvider { - public: - - /** - * Default constructor with default values for texture and font size - */ - TextTileProvider(const glm::uvec2& textureSize = {512, 512}, size_t fontSize = 48); - virtual ~TextTileProvider(); - - // The TileProvider interface below is implemented in this class - virtual Tile getTile(const TileIndex& tileIndex); - virtual Tile getDefaultTile(); - virtual Tile::Status getTileStatus(const TileIndex& index); - virtual TileDepthTransform depthTransform(); - virtual void update(); - virtual void reset(); - virtual int maxLevel(); - - /** - * Returns the tile which will be used to draw text onto. - * Default implementation returns a tile with a plain transparent texture. - */ - virtual Tile backgroundTile(const TileIndex& tileIndex) const; - - - /** - * Allow overriding of hash function. - * Default is TileIndex::hashKey() - * - * \param tileIndex tileIndex to hash - * \returns hashkey used for in LRU cache for this tile - */ - virtual TileHashKey toHash(const TileIndex& tileIndex) const; - - /** - * Uses the fontRenderer to render some text onto the tile texture provided in - * backgroundTile(const TileIndex& tileIndex). - * - * \param fontRenderer used for rendering text onto texture - * \param tileIndex associated with the tile to be rendered onto - */ - virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const = 0; - - protected: - std::shared_ptr _font; - glm::uvec2 _textureSize; - size_t _fontSize; - - private: - Tile createChunkIndexTile(const TileIndex& tileIndex); - std::unique_ptr _fontRenderer; - - TileCache _tileCache; - GLuint _fbo; - }; - - /** - * Provides Tiles with the chunk index rendered as text onto its tiles. - */ - class TileIndexTileProvider : public TextTileProvider { - public: - virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const; - }; - - /** - * Constructed with an ellipsoid and uses that to render the longitudal length of each - * of each tile. +/** + * Enables a simple way of providing tiles with any type of rendered text. + * Internally it handles setting up a FBO for rendering the text, and defines a new + * interface, consisting of only a single method for subclasses to implement: + * renderText(const FontRenderer&, const TileIndex&) const; */ - class SizeReferenceTileProvider : public TextTileProvider { - public: - SizeReferenceTileProvider(const ghoul::Dictionary& dictionary); +class TextTileProvider : public TileProvider { +public: - virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const; - virtual Tile backgroundTile(const TileIndex& tileIndex) const; + /** + * Default constructor with default values for texture and font size + */ + TextTileProvider(const glm::uvec2& textureSize = {512, 512}, size_t fontSize = 48); + virtual ~TextTileProvider(); - virtual TileHashKey toHash(const TileIndex& tileIndex) const; + // The TileProvider interface below is implemented in this class + virtual Tile getTile(const TileIndex& tileIndex); + virtual Tile getDefaultTile(); + virtual Tile::Status getTileStatus(const TileIndex& index); + virtual TileDepthTransform depthTransform(); + virtual void update(); + virtual void reset(); + virtual int maxLevel(); - private: + /** + * Returns the tile which will be used to draw text onto. + * Default implementation returns a tile with a plain transparent texture. + */ + virtual Tile backgroundTile(const TileIndex& tileIndex) const; - int roundedLongitudalLength(const TileIndex& tileIndex) const; - Ellipsoid _ellipsoid; - Tile _backgroundTile; - }; + /** + * Allow overriding of hash function. + * Default is TileIndex::hashKey() + * + * \param tileIndex tileIndex to hash + * \returns hashkey used for in LRU cache for this tile + */ + virtual TileHashKey toHash(const TileIndex& tileIndex) const; + + /** + * Uses the fontRenderer to render some text onto the tile texture provided in + * backgroundTile(const TileIndex& tileIndex). + * + * \param fontRenderer used for rendering text onto texture + * \param tileIndex associated with the tile to be rendered onto + */ + virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const = 0; + +protected: + std::shared_ptr _font; + glm::uvec2 _textureSize; + size_t _fontSize; + +private: + Tile createChunkIndexTile(const TileIndex& tileIndex); + std::unique_ptr _fontRenderer; + + TileCache _tileCache; + GLuint _fbo; +}; + +/** + * Provides Tiles with the chunk index rendered as text onto its tiles. + */ +class TileIndexTileProvider : public TextTileProvider { +public: + virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const; +}; + +/** +* Constructed with an ellipsoid and uses that to render the longitudal length of each +* of each tile. +*/ +class SizeReferenceTileProvider : public TextTileProvider { +public: + SizeReferenceTileProvider(const ghoul::Dictionary& dictionary); + + virtual void renderText(const FontRenderer& fontRenderer, const TileIndex& tileIndex) const; + virtual Tile backgroundTile(const TileIndex& tileIndex) const; + + virtual TileHashKey toHash(const TileIndex& tileIndex) const; + +private: + + int roundedLongitudalLength(const TileIndex& tileIndex) const; + + Ellipsoid _ellipsoid; + Tile _backgroundTile; +}; } // namespace globebrowsing } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/tileprovider.cpp b/modules/globebrowsing/tile/tileprovider/tileprovider.cpp index c2b63b398b..97474f5eef 100644 --- a/modules/globebrowsing/tile/tileprovider/tileprovider.cpp +++ b/modules/globebrowsing/tile/tileprovider/tileprovider.cpp @@ -63,7 +63,7 @@ float TileProvider::noDataValueAsFloat() { return std::numeric_limits::min(); } -ChunkTile TileProvider::getChunkTile(TileIndex tileIndex, int parents, int maxParents){ +ChunkTile TileProvider::getChunkTile(TileIndex tileIndex, int parents, int maxParents) { TileUvTransform uvTransform; uvTransform.uvOffset = glm::vec2(0, 0); uvTransform.uvScale = glm::vec2(1, 1); diff --git a/modules/globebrowsing/tile/tileprovider/tileprovider.h b/modules/globebrowsing/tile/tileprovider/tileprovider.h index e315f09102..c556adf989 100644 --- a/modules/globebrowsing/tile/tileprovider/tileprovider.h +++ b/modules/globebrowsing/tile/tileprovider/tileprovider.h @@ -25,6 +25,8 @@ #ifndef __TILE_PROVIDER_H__ #define __TILE_PROVIDER_H__ +#include + #include // absPath #include #include @@ -33,6 +35,7 @@ #include #include +#include ////////////////////////////////////////////////////////////////////////////////////////// // TILE PROVIDER // @@ -41,121 +44,118 @@ namespace openspace { namespace globebrowsing { - class ChunkTile; - class ChunkTilePile; - - using namespace ghoul::opengl; +using namespace ghoul::opengl; +/** +* Interface for providing Tiles given a +* TileIndex. +*/ +class TileProvider { +public: + /** - * Interface for providing Tiles given a - * TileIndex. + * Factory method for instantiating different implementations of + * TileProviders. The provided dictionary must + * define a key specifying what implementation of TileProvider + * to be instantiated. */ - class TileProvider { - public: + static TileProvider* createFromDictionary(const ghoul::Dictionary& dictionary); - /** - * Factory method for instantiating different implementations of - * TileProviders. The provided dictionary must - * define a key specifying what implementation of TileProvider - * to be instantiated. - */ - static TileProvider* createFromDictionary(const ghoul::Dictionary& dictionary); + /** + * Empty default constructor + */ + TileProvider() {}; - /** - * Empty default constructor - */ - TileProvider() {}; + /** + * Implementations of the TileProvider interface must implement + * a constructor taking a dictionary as input. The provided + * dictionary must define a key specifying what implementation + * of TileProvider to be instantiated. + */ + TileProvider(const ghoul::Dictionary& dictionary); - /** - * Implementations of the TileProvider interface must implement - * a constructor taking a dictionary as input. The provided - * dictionary must define a key specifying what implementation - * of TileProvider to be instantiated. - */ - TileProvider(const ghoul::Dictionary& dictionary); + /** + * Virtual destructor that subclasses should override to do + * clean up. + */ + virtual ~TileProvider() { } - /** - * Virtual destructor that subclasses should override to do - * clean up. - */ - virtual ~TileProvider() { } - - /** - * Method for querying tiles, given a specified TileIndex. - * - * This method is expected to be invoked multiple times per frame, - * and should therefore return quickly, e.g. not perform heavy I/O - * operations. However, invoking this method may spawn separate threads - * to perform such operations. Therefore, programmers shoud - * note that there is no guarantee that the Tile - * status and texture will be consistent over different invocations - * of this method. - * - * \param tileIndex specifying a region of a map for which - * we want tile data. - * - * \returns The tile corresponding to the TileIndex by the time - * the method was invoked. - */ - virtual Tile getTile(const TileIndex& tileIndex) = 0; + /** + * Method for querying tiles, given a specified TileIndex. + * + * This method is expected to be invoked multiple times per frame, + * and should therefore return quickly, e.g. not perform heavy I/O + * operations. However, invoking this method may spawn separate threads + * to perform such operations. Therefore, programmers shoud + * note that there is no guarantee that the Tile + * status and texture will be consistent over different invocations + * of this method. + * + * \param tileIndex specifying a region of a map for which + * we want tile data. + * + * \returns The tile corresponding to the TileIndex by the time + * the method was invoked. + */ + virtual Tile getTile(const TileIndex& tileIndex) = 0; - virtual ChunkTile getChunkTile(TileIndex tileIndex, int parents = 0, int maxParents = 1337); + virtual ChunkTile getChunkTile(TileIndex tileIndex, int parents = 0, int maxParents = 1337); - virtual ChunkTilePile getChunkTilePile(TileIndex tileIndex, int pileSize); + virtual ChunkTilePile getChunkTilePile(TileIndex tileIndex, int pileSize); - /** - * TileProviders must be able to provide a defualt - * Tile which may be used by clients in cases when - * requested tiles were unavailable. - * - * \returns A default tile - */ - virtual Tile getDefaultTile() = 0; + /** + * TileProviders must be able to provide a defualt + * Tile which may be used by clients in cases when + * requested tiles were unavailable. + * + * \returns A default tile + */ + virtual Tile getDefaultTile() = 0; - /** - * Returns the status of a Tile. The Tile::Status - * corresponds the Tile that would be returned - * if the function getTile would be invoked with the same - * TileIndex argument at this point in time. - */ - virtual Tile::Status getTileStatus(const TileIndex& index) = 0; + /** + * Returns the status of a Tile. The Tile::Status + * corresponds the Tile that would be returned + * if the function getTile would be invoked with the same + * TileIndex argument at this point in time. + */ + virtual Tile::Status getTileStatus(const TileIndex& index) = 0; - /** - * Get the associated depth transform for this TileProvider. - * This is necessary for TileProviders serving height map - * data, in order to correcly map pixel values to meters. - */ - virtual TileDepthTransform depthTransform() = 0; + /** + * Get the associated depth transform for this TileProvider. + * This is necessary for TileProviders serving height map + * data, in order to correcly map pixel values to meters. + */ + virtual TileDepthTransform depthTransform() = 0; - /** - * This method should be called once per frame. Here, TileProviders - * are given the opportunity to update their internal state. - */ - virtual void update() = 0; + /** + * This method should be called once per frame. Here, TileProviders + * are given the opportunity to update their internal state. + */ + virtual void update() = 0; - /** - * Provides a uniform way of all TileProviders to reload or - * restore all of its internal state. This is mainly useful - * for debugging purposes. - */ - virtual void reset() = 0; + /** + * Provides a uniform way of all TileProviders to reload or + * restore all of its internal state. This is mainly useful + * for debugging purposes. + */ + virtual void reset() = 0; - /** - * \returns The maximum level as defined by TileIndex - * that this TileProvider is able provide. - */ - virtual int maxLevel() = 0; + /** + * \returns The maximum level as defined by TileIndex + * that this TileProvider is able provide. + */ + virtual int maxLevel() = 0; - /** - * \returns the no data value for the dataset. Default is the minimum float avalue. - */ - virtual float noDataValueAsFloat(); - }; + /** + * \returns the no data value for the dataset. Default is the minimum float avalue. + */ + virtual float noDataValueAsFloat(); +}; - typedef LRUCache TileCache; +typedef LRUCache TileCache; } // namespace globebrowsing } // namespace openspace diff --git a/modules/globebrowsing/tile/tileprovider/tileproviderbyindex.cpp b/modules/globebrowsing/tile/tileprovider/tileproviderbyindex.cpp index ed03e8228e..8d3c01ebe1 100644 --- a/modules/globebrowsing/tile/tileprovider/tileproviderbyindex.cpp +++ b/modules/globebrowsing/tile/tileprovider/tileproviderbyindex.cpp @@ -81,7 +81,7 @@ namespace globebrowsing { } TileDepthTransform TileProviderByIndex::depthTransform() { - _defaultTileProvider->depthTransform(); + return _defaultTileProvider->depthTransform(); } void TileProviderByIndex::update() { diff --git a/tests/test_aabb.inl b/tests/test_aabb.inl index da83faa03a..8d49293335 100644 --- a/tests/test_aabb.inl +++ b/tests/test_aabb.inl @@ -30,14 +30,10 @@ #include #include -using namespace openspace; - class AABBTest : public testing::Test {}; - - TEST_F(AABBTest, Contains2) { - + using namespace openspace::globebrowsing; AABB2 a1; AABB2 a2; /* @@ -67,6 +63,7 @@ TEST_F(AABBTest, Contains2) { TEST_F(AABBTest, Intersects2) { + using namespace openspace::globebrowsing; AABB2 a1; AABB2 a2; @@ -98,9 +95,8 @@ TEST_F(AABBTest, Intersects2) { } - - TEST_F(AABBTest, Contains3) { + using namespace openspace::globebrowsing; AABB3 a1; AABB3 a2; @@ -122,6 +118,7 @@ TEST_F(AABBTest, Contains3) { TEST_F(AABBTest, Intersects3) { + using namespace openspace::globebrowsing; AABB3 a1; AABB3 a2; diff --git a/tests/test_angle.inl b/tests/test_angle.inl index 25b0794acc..9658982f89 100644 --- a/tests/test_angle.inl +++ b/tests/test_angle.inl @@ -30,90 +30,92 @@ #include #include -using namespace openspace; - class AngleTest : public testing::Test {}; TEST_F(AngleTest, DoubleConversions) { - - ASSERT_EQ(dAngle::fromRadians(0).asDegrees(), 0) << "from radians to degrees"; - ASSERT_EQ(dAngle::HALF.asDegrees(), 180) << "from radians to degrees"; - ASSERT_EQ(dAngle::fromDegrees(180).asRadians(), dAngle::PI) << "from degrees to radians"; + using namespace openspace::globebrowsing; + + ASSERT_EQ(dAngle::fromRadians(0).asDegrees(), 0) << "from radians to degrees"; + ASSERT_EQ(dAngle::HALF.asDegrees(), 180) << "from radians to degrees"; + ASSERT_EQ(dAngle::fromDegrees(180).asRadians(), dAngle::PI) << "from degrees to radians"; } TEST_F(AngleTest, FloatConversions) { + using namespace openspace::globebrowsing; - ASSERT_EQ(fAngle::ZERO.asDegrees(), 0.0) << "from radians to degrees"; - ASSERT_EQ(fAngle::HALF.asDegrees(), 180.0) << "from radians to degrees"; - ASSERT_EQ(fAngle::fromDegrees(180).asRadians(), fAngle::PI) << "from degrees to radians"; + ASSERT_EQ(fAngle::ZERO.asDegrees(), 0.0) << "from radians to degrees"; + ASSERT_EQ(fAngle::HALF.asDegrees(), 180.0) << "from radians to degrees"; + ASSERT_EQ(fAngle::fromDegrees(180).asRadians(), fAngle::PI) << "from degrees to radians"; } TEST_F(AngleTest, Normalize) { - - - ASSERT_NEAR( - dAngle::fromDegrees(390).normalize().asDegrees(), - 30.0, - dAngle::EPSILON - ) << "normalize to [0, 360]"; + using namespace openspace::globebrowsing; + + ASSERT_NEAR( + dAngle::fromDegrees(390).normalize().asDegrees(), + 30.0, + dAngle::EPSILON + ) << "normalize to [0, 360]"; - dAngle a = dAngle::fromDegrees(190); - a.normalizeAround(dAngle::ZERO); - ASSERT_NEAR( - a.asDegrees(), - -170, - dAngle::EPSILON - ) << "normalize to [-180,180]"; + dAngle a = dAngle::fromDegrees(190); + a.normalizeAround(dAngle::ZERO); + ASSERT_NEAR( + a.asDegrees(), + -170, + dAngle::EPSILON + ) << "normalize to [-180,180]"; - dAngle b = dAngle::fromDegrees(190); - b.normalizeAround(dAngle::fromDegrees(90)); - ASSERT_NEAR( - b.asDegrees(), - 190, - dAngle::EPSILON - ) << "normalize to [-90,270]"; + dAngle b = dAngle::fromDegrees(190); + b.normalizeAround(dAngle::fromDegrees(90)); + ASSERT_NEAR( + b.asDegrees(), + 190, + dAngle::EPSILON + ) << "normalize to [-90,270]"; - dAngle c = dAngle::fromDegrees(360); - c.normalizeAround(dAngle::fromDegrees(1083.2)); - ASSERT_NEAR( - c.asDegrees(), - 1080, - dAngle::EPSILON - ) << "normalize to [903.2, 1263.2]"; + dAngle c = dAngle::fromDegrees(360); + c.normalizeAround(dAngle::fromDegrees(1083.2)); + ASSERT_NEAR( + c.asDegrees(), + 1080, + dAngle::EPSILON + ) << "normalize to [903.2, 1263.2]"; } TEST_F(AngleTest, Clamp) { + using namespace openspace::globebrowsing; - ASSERT_EQ( - dAngle::fromDegrees(390).clamp(dAngle::ZERO, dAngle::HALF).asDegrees(), - 180 - ) << "clamp [0, 180]"; + ASSERT_EQ( + dAngle::fromDegrees(390).clamp(dAngle::ZERO, dAngle::HALF).asDegrees(), + 180 + ) << "clamp [0, 180]"; - ASSERT_EQ( - dAngle::fromDegrees(390).clamp(dAngle::ZERO, dAngle::FULL).asDegrees(), - 360 - ) << "clamp [0, 360]"; + ASSERT_EQ( + dAngle::fromDegrees(390).clamp(dAngle::ZERO, dAngle::FULL).asDegrees(), + 360 + ) << "clamp [0, 360]"; } TEST_F(AngleTest, ConstClamp) { - - const dAngle a = dAngle::fromDegrees(390); - ASSERT_EQ( - a.getClamped(dAngle::ZERO, dAngle::HALF).asDegrees(), - 180 - ) << "clamp [0, 180]"; + using namespace openspace::globebrowsing; - const dAngle b = dAngle::fromDegrees(390); - ASSERT_EQ( - b.getClamped(dAngle::ZERO, dAngle::FULL).asDegrees(), - 360 - ) << "clamp [0, 360]"; + const dAngle a = dAngle::fromDegrees(390); + ASSERT_EQ( + a.getClamped(dAngle::ZERO, dAngle::HALF).asDegrees(), + 180 + ) << "clamp [0, 180]"; + + const dAngle b = dAngle::fromDegrees(390); + ASSERT_EQ( + b.getClamped(dAngle::ZERO, dAngle::FULL).asDegrees(), + 360 + ) << "clamp [0, 360]"; } \ No newline at end of file diff --git a/tests/test_concurrentjobmanager.inl b/tests/test_concurrentjobmanager.inl index 520c960673..1c9ba66a77 100644 --- a/tests/test_concurrentjobmanager.inl +++ b/tests/test_concurrentjobmanager.inl @@ -31,22 +31,12 @@ #include #include - - - class ConcurrentJobManagerTest : public testing::Test {}; - -using namespace openspace; -using namespace std::chrono_literals; - - - -struct TestJob : public Job { +struct TestJob : public openspace::globebrowsing::Job { TestJob(int jobExecutingTime) - : _jobExecutingTime(jobExecutingTime) { - - } + : _jobExecutingTime(jobExecutingTime) + {} virtual void execute() { std::cout << "Executing job ... " << std::endl; @@ -68,6 +58,7 @@ private: TEST_F(ConcurrentJobManagerTest, Basic) { + using namespace openspace::globebrowsing; std::shared_ptr pool = std::make_shared(1); ConcurrentJobManager jobManager(pool); @@ -95,12 +86,6 @@ TEST_F(ConcurrentJobManagerTest, Basic) { EXPECT_EQ(product, 1337) << "Expecting product to be 1337"; } - - - - - - struct VerboseProduct { VerboseProduct(int v) : val(v){ @@ -115,7 +100,7 @@ struct VerboseProduct { }; -struct VerboseJob : public Job{ +struct VerboseJob : public openspace::globebrowsing::Job{ VerboseJob(int jobExecutingTime) : _jobExecutingTime(jobExecutingTime) { std::cout << "VerboseTestJob constructor" << std::endl; @@ -141,12 +126,9 @@ struct VerboseJob : public Job{ }; - - - - - TEST_F(ConcurrentJobManagerTest, JobCreation) { + using namespace openspace::globebrowsing; + std::shared_ptr pool = std::make_shared(1); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); @@ -170,8 +152,6 @@ TEST_F(ConcurrentJobManagerTest, JobCreation) { auto product = finishedJob->product(); } - int a; - } diff --git a/tests/test_concurrentqueue.inl b/tests/test_concurrentqueue.inl index 3415a806fb..fda05e577d 100644 --- a/tests/test_concurrentqueue.inl +++ b/tests/test_concurrentqueue.inl @@ -30,17 +30,11 @@ #include #include - - - class ConcurrentQueueTest : public testing::Test {}; - -using namespace openspace; - - - TEST_F(ConcurrentQueueTest, Basic) { + using namespace openspace::globebrowsing; + ConcurrentQueue q1; q1.push(4); int val = q1.pop(); diff --git a/tests/test_convexhull.inl b/tests/test_convexhull.inl index d4cfdc4dc0..1060fcc1a4 100644 --- a/tests/test_convexhull.inl +++ b/tests/test_convexhull.inl @@ -30,13 +30,10 @@ #include #include -using namespace openspace; - class ConvexHull2Test : public testing::Test {}; - - TEST_F(ConvexHull2Test, basic) { + using namespace openspace::globebrowsing; // points // 2 x @@ -68,6 +65,7 @@ TEST_F(ConvexHull2Test, basic) { } TEST_F(ConvexHull2Test, intersection) { + using namespace openspace::globebrowsing; std::vector points1 = { { -1.0, 0.0 }, { 1.0, 0.0 }, @@ -97,6 +95,7 @@ TEST_F(ConvexHull2Test, intersection) { TEST_F(ConvexHull2Test, non_intersection) { + using namespace openspace::globebrowsing; std::vector points1 = { { -2.0, 0.0 }, { 2.0, 0.0 }, diff --git a/tests/test_lrucache.inl b/tests/test_lrucache.inl index 6420e1febf..53151b86ee 100644 --- a/tests/test_lrucache.inl +++ b/tests/test_lrucache.inl @@ -32,72 +32,65 @@ class LRUCacheTest : public testing::Test {}; -using namespace openspace; - TEST_F(LRUCacheTest, Get) { - LRUCache lru(4); - lru.put(1, "hej"); - lru.put(12, "san"); - ASSERT_STREQ(lru.get(1).c_str(), "hej") << "testing get"; + openspace::globebrowsing::LRUCache lru(4); + lru.put(1, "hej"); + lru.put(12, "san"); + ASSERT_STREQ(lru.get(1).c_str(), "hej") << "testing get"; } TEST_F(LRUCacheTest, CleaningCache) { - LRUCache lru(4); - lru.put(1, 1.2); - lru.put(12, 2.3); - lru.put(123, 33.4); - lru.put(1234, 4.5); - lru.put(12345, 6.7); - ASSERT_FALSE(lru.exist(1)) << "Element should have been cleaned out of cache"; - ASSERT_TRUE(lru.exist(12)) << "Element should remain in cache"; + openspace::globebrowsing::LRUCache lru(4); + lru.put(1, 1.2); + lru.put(12, 2.3); + lru.put(123, 33.4); + lru.put(1234, 4.5); + lru.put(12345, 6.7); + ASSERT_FALSE(lru.exist(1)) << "Element should have been cleaned out of cache"; + ASSERT_TRUE(lru.exist(12)) << "Element should remain in cache"; } - - - - struct MyKey { - int x, y; + int x, y; }; bool operator==(const MyKey& a, const MyKey& b) { - return a.x == b.x && a.y == b.y; + return a.x == b.x && a.y == b.y; } std::ostream& operator<<(std::ostream& o, const MyKey& key) { - return o << key.x << ", " << key.y; + return o << key.x << ", " << key.y; } // custom specialization of std::hash can be injected in namespace std namespace std { - template<> struct hash { - std::size_t operator()(MyKey const& s) const { - return s.x ^ (s.y << 1); - } - }; + template<> struct hash { + std::size_t operator()(MyKey const& s) const { + return s.x ^ (s.y << 1); + } + }; } TEST_F(LRUCacheTest, StructKey) { + openspace::globebrowsing::LRUCache lru(4); - LRUCache lru(4); + // These two custom keys should be treated as equal + MyKey key1 = { 2, 3 }; + MyKey key2 = { 2, 3 }; - // These two custom keys should be treated as equal - MyKey key1 = { 2, 3 }; - MyKey key2 = { 2, 3 }; - - std::string val1 = "value 1"; - std::string val2 = "value 2"; + std::string val1 = "value 1"; + std::string val2 = "value 2"; - lru.put(key1, val1); - ASSERT_TRUE(lru.exist(key1)); - ASSERT_EQ(lru.get(key1), val1); + lru.put(key1, val1); + ASSERT_TRUE(lru.exist(key1)); + ASSERT_EQ(lru.get(key1), val1); - // Putting key2 should replace key1 - lru.put(key2, val2); - ASSERT_EQ(key1, key2) << "key 1 and key2 should be considered equal"; - ASSERT_TRUE(lru.exist(key2)); - ASSERT_EQ(lru.get(key1), val2); - ASSERT_EQ(lru.get(key2), val2); - + // Putting key2 should replace key1 + lru.put(key2, val2); + ASSERT_EQ(key1, key2) << "key 1 and key2 should be considered equal"; + ASSERT_TRUE(lru.exist(key2)); + ASSERT_EQ(lru.get(key1), val2); + ASSERT_EQ(lru.get(key2), val2); + } \ No newline at end of file