Skip to content

Commit

Permalink
Merged m_NumJunctions into m_BitFlag
Browse files Browse the repository at this point in the history
* The number of junctions can be at most 6 so it can be stored in 3 bits
and m_BitFlag has enough unused bits at the end to accommodate it

Signed-off-by: Jared Duffey <[email protected]>
  • Loading branch information
JDuffeyBQ committed Dec 9, 2024
1 parent b272ec9 commit dbaa76a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,26 +194,26 @@ void MMCellFlag::set(const int32_t cellLabels[8])

// Determine vertex type
int32_t numFaceCrossings = 0;
m_NumJunctions = 0;
uint32_t numJunctions = 0;
for(Face face = Face::LeftFace; face <= Face::TopFace; ++face)
{
if(faceCrossingType(face) != FaceCrossingType::NoFaceCrossing)
{
numFaceCrossings++;
if(faceCrossingType(face) == FaceCrossingType::JunctionFaceCrossing)
{
m_NumJunctions++;
numJunctions++;
}
}
}
if(numFaceCrossings != 0)
{
uint32_t vertexTypeBits = 0;
if(m_NumJunctions < 1)
if(numJunctions < 1)
{
vertexTypeBits = static_cast<uint32_t>(VertexType::SurfaceVertex);
}
else if(m_NumJunctions <= 2)
else if(numJunctions <= 2)
{
vertexTypeBits = static_cast<uint32_t>(VertexType::EdgeVertex);
}
Expand All @@ -223,6 +223,8 @@ void MMCellFlag::set(const int32_t cellLabels[8])
}
m_BitFlag |= (vertexTypeBits << k_VertexTypeShift);
}

m_BitFlag |= numJunctions << k_NumJunctionsBitShift;
}

MMCellFlag::VertexType MMCellFlag::vertexType() const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ class MMCellFlag
bool isEdgeCrossing(Edge edge) const;
uint8_t numJunctions() const
{
return m_NumJunctions;
return m_BitFlag >> k_NumJunctionsBitShift;
}

private:
static inline constexpr uint32_t k_NumJunctionsBitShift = 29;

// The bitflag
// The last 3 bits of the bitflag are the number of junctions
// numJunctions can at most be 6
uint32_t m_BitFlag = 0;
uint8_t m_NumJunctions = 0;
};

// For iterating over cell faces
Expand Down

0 comments on commit dbaa76a

Please sign in to comment.