Commit 74b6501c authored by wenqing's avatar wenqing

[Test] Added unit test for AdjustNodeCoordinates

parent d4ce9ee5
/**
* \file
* \copyright
* Copyright (c) 2012-2020, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
* Created on October 12, 2020, 2:58 PM
*/
#include "gtest/gtest.h"
#include <vector>
#include "MeshLib/Utils/GetOutlineMagnitude.h"
#include "MeshLib/Utils/AdjustNodeCoordinates.h"
#include "MeshLib/Node.h"
#include "MeshLib/MeshSurfaceExtraction.h"
TEST(MeshLib, AdjustNodeCoordinates)
{
std::vector<MeshLib::Node*> nodes;
nodes.reserve(3);
//-- Plane in 3D outline space
// Nodes on an inclined plane.
nodes.push_back(new MeshLib::Node(1.0, 0.0, 0.));
nodes.push_back(new MeshLib::Node(0.0, 1.0, 0.));
nodes.push_back(new MeshLib::Node(0.0, 0.0, 1.));
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
for (int i = 0; i < 3; i++)
{
auto const x = nodes[i]->getCoords();
for (int k = 0; k < 3; k++)
{
double const expected = (i == k) ? 1.0 : 0.0;
ASSERT_EQ(expected, x[k]);
}
}
}
//-- Plane in 2D outline space
// Nodes on x-y plane with an offset of 1.0 in z direction..
nodes[0]->updateCoordinates(0.0, 0.0, 1.0);
nodes[1]->updateCoordinates(1.0, 0.0, 1.0);
nodes[2]->updateCoordinates(0.0, 1.0, 1.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
auto const x0 = nodes[0]->getCoords();
for (int k = 0; k < 3; k++)
{
ASSERT_EQ(0.0, x0[k]);
}
auto const x1 = nodes[1]->getCoords();
ASSERT_EQ(1.0, x1[0]);
ASSERT_EQ(0.0, x1[1]);
ASSERT_EQ(0.0, x1[2]);
auto const x2 = nodes[2]->getCoords();
ASSERT_EQ(0.0, x2[0]);
ASSERT_EQ(1.0, x2[1]);
ASSERT_EQ(0.0, x2[2]);
}
//-- Line in 3D outline space
// Nodes on a line.
nodes[0]->updateCoordinates(0.0, 0.0, 0.0);
nodes[1]->updateCoordinates(1.0, 1.0, 1.0);
nodes[2]->updateCoordinates(2.0, 2.0, 2.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
auto const x0 = nodes[0]->getCoords();
for (int k = 0; k < 3; k++)
{
ASSERT_EQ(0.0, x0[k]);
}
auto const x1 = nodes[1]->getCoords();
ASSERT_EQ(1.0, x1[0]);
ASSERT_EQ(1.0, x1[1]);
ASSERT_EQ(1.0, x1[2]);
auto const x2 = nodes[2]->getCoords();
ASSERT_EQ(2.0, x2[0]);
ASSERT_EQ(2.0, x2[1]);
ASSERT_EQ(2.0, x2[2]);
}
//-- Lines in 2D outline space
// Nodes on a line on a plane parallel to z=0 plane.
nodes[0]->updateCoordinates(0.0, 0.0, 1.0);
nodes[1]->updateCoordinates(1.0, 1.0, 1.0);
nodes[2]->updateCoordinates(2.0, 2.0, 1.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
auto const x0 = nodes[0]->getCoords();
for (int k = 0; k < 3; k++)
{
ASSERT_EQ(0.0, x0[k]);
}
auto const x1 = nodes[1]->getCoords();
ASSERT_EQ(1.0, x1[0]);
ASSERT_EQ(1.0, x1[1]);
ASSERT_EQ(0.0, x1[2]);
auto const x2 = nodes[2]->getCoords();
ASSERT_EQ(2.0, x2[0]);
ASSERT_EQ(2.0, x2[1]);
ASSERT_EQ(0.0, x2[2]);
}
// Nodes on x-z plane with an offset of 1.0 in y direction..
nodes[0]->updateCoordinates(0.0, 1.0, 0.0);
nodes[1]->updateCoordinates(1.0, 1.0, 0.0);
nodes[2]->updateCoordinates(0.0, 1.0, 1.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
auto const x0 = nodes[0]->getCoords();
for (int k = 0; k < 3; k++)
{
ASSERT_EQ(0.0, x0[k]);
}
auto const x1 = nodes[1]->getCoords();
ASSERT_EQ(1.0, x1[0]);
ASSERT_EQ(0.0, x1[1]);
ASSERT_EQ(0.0, x1[2]);
auto const x2 = nodes[2]->getCoords();
ASSERT_EQ(0.0, x2[0]);
ASSERT_EQ(1.0, x2[1]);
ASSERT_EQ(0.0, x2[2]);
}
// Nodes on y-z plane with an offset of 1.0 in x direction.
nodes[0]->updateCoordinates(1.0, 0.0, 0.0);
nodes[1]->updateCoordinates(1.0, 1.0, 0.0);
nodes[2]->updateCoordinates(1.0, 0.0, 1.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
auto const x0 = nodes[0]->getCoords();
for (int k = 0; k < 3; k++)
{
ASSERT_EQ(0.0, x0[k]);
}
auto const x1 = nodes[1]->getCoords();
ASSERT_EQ(1.0, x1[0]);
ASSERT_EQ(0.0, x1[1]);
ASSERT_EQ(0.0, x1[2]);
auto const x2 = nodes[2]->getCoords();
ASSERT_EQ(0.0, x2[0]);
ASSERT_EQ(1.0, x2[1]);
ASSERT_EQ(0.0, x2[2]);
}
//-- Line in 1D outline space
// Nodes on a line that is parallel to x axis, which has an offset of 1.0 in
// y direction, and
// an offset of 2.0 in z direction.
double const x_coord[] = {1.0, 2.0, 3.0};
nodes[0]->updateCoordinates(x_coord[0], 1.0, 2.0);
nodes[1]->updateCoordinates(x_coord[1], 1.0, 2.0);
nodes[2]->updateCoordinates(x_coord[2], 1.0, 2.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
for (std::size_t i = 0; i < nodes.size(); i++)
{
auto const x = nodes[i]->getCoords();
ASSERT_EQ(x_coord[i], x[0]);
ASSERT_EQ(0.0, x[1]);
ASSERT_EQ(0.0, x[2]);
}
}
// Nodes on a line that is parallel to y axis, which has an offset of 1.0 in
// x direction, and
// an offset of 2.0 in z direction.
nodes[0]->updateCoordinates(1.0, x_coord[0], 2.0);
nodes[1]->updateCoordinates(1.0, x_coord[1], 2.0);
nodes[2]->updateCoordinates(1.0, x_coord[2], 2.0);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
for (std::size_t i = 0; i < nodes.size(); i++)
{
auto const x = nodes[i]->getCoords();
ASSERT_EQ(x_coord[i], x[0]);
ASSERT_EQ(0.0, x[1]);
ASSERT_EQ(0.0, x[2]);
}
}
// Nodes on a line that is parallel to z axis, which has an offset of 1.0 in
// x direction, and an offset of 2.0 in y direction.
nodes[0]->updateCoordinates(1.0, 2.0, x_coord[0]);
nodes[1]->updateCoordinates(1.0, 2.0, x_coord[1]);
nodes[2]->updateCoordinates(1.0, 2.0, x_coord[2]);
{
auto const& x_magnitude = MeshLib::getOutlineMagnitude(nodes);
MeshLib::adjustNodeCoordinates(x_magnitude, nodes);
for (std::size_t i = 0; i < nodes.size(); i++)
{
auto const x = nodes[i]->getCoords();
ASSERT_EQ(x_coord[i], x[0]);
ASSERT_EQ(0.0, x[1]);
ASSERT_EQ(0.0, x[2]);
}
}
for (auto node : nodes)
{
delete node;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment