Skip to content

Commit

Permalink
#5622: Refactor result type
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed May 23, 2021
1 parent ee03026 commit 4fd43a9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
37 changes: 15 additions & 22 deletions radiantcore/map/algorithm/Import.cpp
Expand Up @@ -374,9 +374,12 @@ void importFromStream(std::istream& stream)
}
}

ComparisonResult::FingerprintsByType collectFingerprints(const scene::INodePtr& root)
using Fingerprints = std::map<std::size_t, scene::INodePtr>;
using FingerprintsByType = std::map<scene::INode::Type, Fingerprints>;

FingerprintsByType collectFingerprints(const scene::INodePtr& root)
{
ComparisonResult::FingerprintsByType result;
FingerprintsByType result;

root->foreachNode([&](const scene::INodePtr& node)
{
Expand Down Expand Up @@ -426,42 +429,32 @@ ComparisonResult::Ptr compareGraphs(const scene::IMapRootNodePtr& target, const

for (const auto& sourceEntity : sourceFingerprints[scene::INode::Type::Entity])
{
// Create the collection to hold the of matching node pairs
auto& matchingNodeList = result->equivalentNodes.try_emplace(scene::INode::Type::Entity).first->second;
auto& differingNodes = result->differingNodes.try_emplace(scene::INode::Type::Entity).first->second;

// Check each source node for an equivalent node in the target
auto matchingTargetNode = targetEntities.find(sourceEntity.first);

if (matchingTargetNode != targetEntities.end())
{
// Found an equivalent node
matchingNodeList.emplace_back(ComparisonResult::Match{ sourceEntity.first, sourceEntity.second, matchingTargetNode->second });
result->equivalentEntities.emplace_back(ComparisonResult::Match{ sourceEntity.first, sourceEntity.second, matchingTargetNode->second });
}
else
{
differingNodes.emplace(sourceEntity.first, sourceEntity.second);
result->differingEntities.emplace_back(ComparisonResult::Mismatch{ sourceEntity.first, sourceEntity.second });
}
}

for (const auto& pair : result->equivalentNodes)
{
rMessage() << "Equivalent Nodes of Type " << static_cast<std::size_t>(pair.first) << ": " << pair.second.size() << std::endl;
rMessage() << "Equivalent Entities " << result->equivalentEntities.size() << std::endl;

for (const auto& fingerprintedNode : pair.second)
{
rMessage() << " - Equivalent Node: " << fingerprintedNode.sourceNode->name() << std::endl;
}
for (const auto& match: result->equivalentEntities)
{
rMessage() << " - Equivalent Entity: " << match.sourceNode->name() << std::endl;
}

for (const auto& pair : result->differingNodes)
{
rMessage() << "Different Nodes of Type " << static_cast<std::size_t>(pair.first) << ": " << pair.second.size() << std::endl;
rMessage() << "Mismatching Entities: " << result->differingEntities.size() << std::endl;

for (const auto& fingerprintedNode : pair.second)
{
rMessage() << " - Differing Node: " << fingerprintedNode.second->name() << std::endl;
}
for (const auto& mismatch : result->differingEntities)
{
rMessage() << " - Differing Entity " << mismatch.sourceNode->name() << std::endl;
}

return result;
Expand Down
16 changes: 10 additions & 6 deletions radiantcore/map/algorithm/Import.h
Expand Up @@ -59,8 +59,6 @@ MapFormatPtr determineMapFormat(std::istream& stream);
struct ComparisonResult
{
using Ptr = std::shared_ptr<ComparisonResult>;
using Fingerprints = std::map<std::size_t, scene::INodePtr>;
using FingerprintsByType = std::map<scene::INode::Type, Fingerprints>;

// Represents a matching node pair
struct Match
Expand All @@ -70,11 +68,17 @@ struct ComparisonResult
scene::INodePtr targetNode;
};

// The collection of nodes with the same fingerprint value, grouped by type
std::map<scene::INode::Type, std::list<Match>> equivalentNodes;
struct Mismatch
{
std::size_t fingerPrint;
scene::INodePtr sourceNode;
};

// The collection of entities with the same fingerprint value
std::list<Match> equivalentEntities;

// The collection of nodes with differing fingerprint values, grouped by type
FingerprintsByType differingNodes;
// The collection of entities with differing fingerprint values
std::list<Mismatch> differingEntities;
};

// Runs a comparison of "source" (to be merged) against the "target" (merge target)
Expand Down

0 comments on commit 4fd43a9

Please sign in to comment.