Cogs.Foundation
Loading...
Searching...
No Matches
Classes | Enumerations | Functions
Cogs::Geometry Namespace Reference

Classes

class  Polygon
 Generic 2D concave or convex polygon. More...
 
struct  Vertex
 

Enumerations

enum  Location { Inside = -1 , Outside = 1 }
 

Functions

COGSFOUNDATION_API void generateQuadIndices (std::vector< uint32_t > &dest, size_t quadCount, uint32_t vertexNumber, bool sharedVertices)
 Generate indices for rendering the specified number of quads from four vertices starting from the given vertex number.
 
bool veryClose (const glm::vec3 &lhs, const glm::vec3 &rhs)
 Tests whether the two points are within one centimetre of each other.
 
void removeDuplicates (Vertex::List &vertices)
 Removes any adjacent vertices that are within five millimetres of their neighbours.
 
int calcLineSide (const glm::vec3 &start, const glm::vec3 &end, const glm::vec3 &point)
 Calculates which side of the line (start-end) the given point lies.
 
uint32_t findMatchingVertex (const glm::vec3 &vertex, const Vertex::List &vertices)
 Searches for the vertex at the specified location.
 
Location getVertexLocation (const Vertex &vertex, const Vertex::List &vertices)
 Determines whether the given vertex is located inside the polygon defined by the list of vertices.
 
Location findDivergenceForwards (const Vertex::List &mine, const Vertex::List &theirs, uint32_t myIdx, uint32_t theirIdx, uint32_t &myNextIdx, uint32_t &theirNextIdx)
 Trace a path from the two specified points (which are located at the same position) until they diverge.
 
bool generateIntersectionPoints (Vertex::List &mine, Vertex::List &theirs)
 Inserts additional vertices into the two provided lists at all the intersection points of the two polygons those lists represent.
 
bool findClosestVertices (const Vertex::List &mine, const Vertex::List &theirs, uint32_t &myPoint, uint32_t &theirPoint)
 Finds the closest vertices from the two polygons.
 
uint32_t findNextIntersection (const Vertex::List &vertices, uint32_t startIdx, bool wrap=true)
 Searches the provided list of vertices looking for the next one that is marked as being an intersection between the two polygons.
 

Enumeration Type Documentation

◆ Location

Enumerator
Inside 
Outside 

Function Documentation

◆ calcLineSide()

int Cogs::Geometry::calcLineSide ( const glm::vec3 &  start,
const glm::vec3 &  end,
const glm::vec3 &  point 
)

Calculates which side of the line (start-end) the given point lies.

A positive value means the point is on the left of the line (when looking along the line from its start), while a negative value means the point is on the right. *============================================================================================

◆ findClosestVertices()

bool Cogs::Geometry::findClosestVertices ( const Vertex::List mine,
const Vertex::List theirs,
uint32_t &  myPoint,
uint32_t &  theirPoint 
)

Finds the closest vertices from the two polygons.

*============================================================================================

References Cogs::Geometry::Vertex::None.

Referenced by Cogs::Geometry::Polygon::subtract().

◆ findDivergenceForwards()

Location Cogs::Geometry::findDivergenceForwards ( const Vertex::List mine,
const Vertex::List theirs,
uint32_t  myIdx,
uint32_t  theirIdx,
uint32_t &  myNextIdx,
uint32_t &  theirNextIdx 
)

Trace a path from the two specified points (which are located at the same position) until they diverge.

The path will trace either backwards or forwards around their polygon, but always forwards around ours. When we encounter a divergence in the paths we determine whether my path diverges into their polygon, or out away from it. *============================================================================================

References getVertexLocation().

Referenced by generateIntersectionPoints().

◆ findMatchingVertex()

uint32_t Cogs::Geometry::findMatchingVertex ( const glm::vec3 &  vertex,
const Vertex::List vertices 
)

Searches for the vertex at the specified location.

Returns the index of that vertex. *============================================================================================

References Cogs::Geometry::Vertex::None.

Referenced by generateIntersectionPoints(), and Cogs::Geometry::Polygon::subtract().

◆ findNextIntersection()

uint32_t Cogs::Geometry::findNextIntersection ( const Vertex::List vertices,
uint32_t  startIdx,
bool  wrap = true 
)

Searches the provided list of vertices looking for the next one that is marked as being an intersection between the two polygons.

*============================================================================================

References Cogs::Geometry::Vertex::None.

Referenced by Cogs::Geometry::Polygon::subtract().

◆ generateIntersectionPoints()

bool Cogs::Geometry::generateIntersectionPoints ( Vertex::List mine,
Vertex::List theirs 
)

Inserts additional vertices into the two provided lists at all the intersection points of the two polygons those lists represent.

*============================================================================================

References findDivergenceForwards(), findMatchingVertex(), getVertexLocation(), Inside, Cogs::Geometry::Vertex::None, Outside, removeDuplicates(), and veryClose().

Referenced by Cogs::Geometry::Polygon::subtract().

◆ generateQuadIndices()

void Cogs::Geometry::generateQuadIndices ( std::vector< uint32_t > &  dest,
size_t  quadCount,
uint32_t  vertexNumber,
bool  sharedVertices 
)

Generate indices for rendering the specified number of quads from four vertices starting from the given vertex number.

Vertices can be shared between quads or not.

Shared NotShared

0 ____2____ 4 0 ____ 2 4 ____ 6 | /| /| | /| | /| | / | / | | / | | / | | / | / | | / | | / | |/___|/___| |/___| |/___| 1 3 5 1 3 5 7

Assumes counter-clockwise winding order.

◆ getVertexLocation()

Location Cogs::Geometry::getVertexLocation ( const Vertex vertex,
const Vertex::List vertices 
)

Determines whether the given vertex is located inside the polygon defined by the list of vertices.

*============================================================================================

References Inside, Outside, and Cogs::Geometry::Vertex::position.

Referenced by findDivergenceForwards(), generateIntersectionPoints(), and Cogs::Geometry::Polygon::subtract().

◆ removeDuplicates()

void Cogs::Geometry::removeDuplicates ( Vertex::List vertices)

Removes any adjacent vertices that are within five millimetres of their neighbours.

*============================================================================================

References Cogs::Geometry::Vertex::intersectionPoint, Cogs::Geometry::Vertex::position, and veryClose().

Referenced by generateIntersectionPoints().

◆ veryClose()

bool Cogs::Geometry::veryClose ( const glm::vec3 &  lhs,
const glm::vec3 &  rhs 
)

Tests whether the two points are within one centimetre of each other.

*============================================================================================

Referenced by generateIntersectionPoints(), and removeDuplicates().