예제 #1
0
void FormSegmentator::uniteCorners()
{
	bool wasUnited = true;
	while (wasUnited) {
		bool isBeginDiagram1 = false;
		bool isBeginDiagram2 = false;
		int mergeDiagram1 = -1;
		int mergeDiagram2 = -1;
		for (int i = 0; i < mAllComponents.size(); i ++) {
			Component diagram = mAllComponents.at(i);
			if (diagram.back().dist(diagram.at(0)) <= neighbourhoodRad) {
				continue;
			}
			for (int j = 0; j <= 1; j ++) {
				int pos = (j == 1) ? 0 : (diagram.size() - 1);
				SquarePos currentPos = diagram.at(pos);
				int numDiagram = neighbourPos(currentPos, i);
				if (numDiagram < 0) {
					continue;
				}
				mergeDiagram1 = i;
				mergeDiagram2 = numDiagram;
				isBeginDiagram1 = (j == 1);
				SquarePos firstPosDiagram2 = mAllComponents.at(numDiagram).at(0);
				isBeginDiagram2 =
						currentPos.dist(firstPosDiagram2) <= neighbourhoodRad;
			}
		}
		wasUnited = isMergedDiagrams(mergeDiagram1, mergeDiagram2,
									 isBeginDiagram1, isBeginDiagram2);
	}
}
예제 #2
0
core::MapNodeNeighbours neighboursByPos(
    const QPoint& pos, const WorldSurface* worldSurface, const std::unordered_map<core::MapNode*, QPoint>& mapNodesPos)
{
    core::MapNodeNeighbours neighbours;

    const auto tileSize = worldSurface->getTileSize();
    for (core::Direction direction : core::directions)
    {
        QPoint nPos = neighbourPos(pos, direction, tileSize);

        neighbours[direction] = mapNodeAtPos(nPos, mapNodesPos, worldSurface);
    }

    return neighbours;
}
예제 #3
0
static void positionMapNode(core::MapNode* node, std::unordered_map<core::MapNode*, QPoint>& nodesPos, int tileSize)
{
    QPoint pos = nodesPos[node];
    const core::MapNodeNeighbours& neighbours = node->getNeighbours();
    for (const auto& element : neighbours)
    {
        core::Direction dir = element.first;
        core::MapNode* neighbour = element.second;

        if (neighbour == nullptr || nodesPos.find(neighbour) != nodesPos.end())
            continue;

        nodesPos.insert(std::make_pair(neighbour, neighbourPos(pos, dir, tileSize)));

        positionMapNode(neighbour, nodesPos, tileSize);
    }
}