#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2015 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_GEOMETRY_PARTITIONING_VORONOIMESH2_H #define NUCLEX_GEOMETRY_PARTITIONING_VORONOIMESH2_H #include "Nuclex/Geometry/Config.h" #include "Nuclex/Geometry/Point2.h" #include namespace Nuclex { namespace Geometry { namespace Partitioning { // ------------------------------------------------------------------------------------------- // /// Describes the voronoi cell around one of the input elements class VoronoiCell2 { /// Index of the element this voronoi cell encompasses /// /// This is the index of the input element (point or line segment) around which this /// cell has been built. The voronoi mesh does not save the input elements, if you /// need to reference them, you need to save the input /// public: std::size_t PointIndex; /// Indices of the vertices that make up the voronoi cell's outline public: std::vector Outline; }; // ------------------------------------------------------------------------------------------- // /// 2D mesh forming the voronoi regions of a set of points template struct VoronoiMesh2 { /// Vertex index that indicates an edge extends to infinity /// /// All non-empty voronoi graphs have at least 2 edges that extend to infinity. To /// represent these, the edges are given one vertex at unit length from its neighbor /// that indicates the direction, followed by this invalid index. /// public: const std::size_t InfinityVertexIndex = std::size_t(-1); /// Type of points the voronoi mesh is working with public: typedef Point2 PointType; /// Offsets the entire voronoi graph by the specified amount /// Amount the graph will be offset on the X axis /// Amount the graph will be offset on the Y axis public: void ShiftBy(TScalar amountX, TScalar amountY) { for(std::size_t index = 0; index < this->count; ++index) { this->vertices[index].X += amountX; this->vertices[index].Y += amountY; } } /// Offsets the entire voronoi graph by the specified amount /// Amount the graph will be offset public: void ShiftBy(const Vector2 &amount) { for(std::size_t index = 0; index < this->count; ++index) { this->Vertices[index] += amount; } } /// Vertices used by the voronoi graph public: std::vector Vertices; /// Indices that connect the vorono graph to a complete mesh /// /// As described in the constant, a non-empty voronoi /// graph has at least two edges ending in infinity that are represented by connecting /// to a special infinity vertex index. /// public: std::vector Indices; /// Voronoi cells around the input elements /// /// Exterior cells have an infinite side. See the description of the /// constant on how to spot them and how to work /// with them. /// public: std::vector Cells; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Geometry::Partitioning #endif // NUCLEX_GEOMETRY_PARTITIONING_VORONOIMESH2_H