simple c++ snippets for demo
#include <algorithm>
#include <utility>
#include <vector>
typedef void* GzPointer;
typedef float GzCoord[3];
class Vertex
{
public:
explicit Vertex(const GzCoord& vertex)
{
x = vertex[0];
y = vertex[1];
z = vertex[2];
}
static bool SortByY(const Vertex& v1, const Vertex& v2)
{
if (v1.y == v2.y)
return v1.x < v2.x;
return v1.y < v2.y;
}
float x;
float y;
float z;
};
Vertex CoordToVertex(const GzCoord& coord)
{
return Vertex(coord);
}
static void RealTest()
{
GzCoord coord[4] = {
{3.0f, 1.0f, 3.0f},
{2.0f, 2.0f, 2.0f},
{1.0f, 2.0f, 2.0f},
{1.0f, 1.0f, 3.0f}};
std::vector<Vertex> vec;
std::transform(coord, coord+4, std::back_inserter(vec), CoordToVertex);
std::sort(vec.begin(), vec.end(), Vertex::SortByY);
}