-QuadTreeIndex QuadTree::GetNeighbour(QuadTreeIndex start, int xdir, int ydir)
+QuadTreeIndex QuadTree::GetNeighbour(QuadTreeIndex start, int xdir, int ydir) const
{
if (!xdir && !ydir) return start;
+ QuadTreeIndex newNode;
// Try moving to the right if that's easy.
if (xdir > 0)
{
{
case QTC_TOP_LEFT:
case QTC_BOTTOM_LEFT:
- QuadTreeIndex newNode;
+ {
if (nodes[start].child_type == QTC_TOP_LEFT)
- newNode = node[nodes[start].parent].top_right;
+ newNode = nodes[nodes[start].parent].top_right;
else
- newNode = node[nodes[start].parent].bottom_right;
+ newNode = nodes[nodes[start].parent].bottom_right;
return GetNeighbour(newNode, xdir - 1, ydir);
+ }
case QTC_TOP_RIGHT:
case QTC_BOTTOM_RIGHT:
+ {
QuadTreeIndex right_parent = GetNeighbour(nodes[start].parent, 1, 0);
if (right_parent == -1) return -1;
- QuadTreeIndex newNode;
if (nodes[start].child_type == QTC_TOP_RIGHT)
- newNode = node[right_parent].top_left;
+ newNode = nodes[right_parent].top_left;
else
- newNode = node[right_parent].bottom_left;
+ newNode = nodes[right_parent].bottom_left;
return GetNeighbour(newNode, xdir - 1, ydir);
+ }
+ default:
+ return -1;
}
}
{
case QTC_TOP_RIGHT:
case QTC_BOTTOM_RIGHT:
- QuadTreeIndex newNode;
+ {
if (nodes[start].child_type == QTC_TOP_RIGHT)
- newNode = node[nodes[start].parent].top_left;
+ newNode = nodes[nodes[start].parent].top_left;
else
- newNode = node[nodes[start].parent].bottom_left;
+ newNode = nodes[nodes[start].parent].bottom_left;
return GetNeighbour(newNode, xdir + 1, ydir);
+ }
case QTC_TOP_LEFT:
case QTC_BOTTOM_LEFT:
+ {
QuadTreeIndex left_parent = GetNeighbour(nodes[start].parent, -1, 0);
if (left_parent == -1) return -1;
- QuadTreeIndex newNode;
if (nodes[start].child_type == QTC_TOP_LEFT)
- newNode = node[left_parent].top_right;
+ newNode = nodes[left_parent].top_right;
else
- newNode = node[left_parent].bottom_right;
+ newNode = nodes[left_parent].bottom_right;
return GetNeighbour(newNode, xdir + 1, ydir);
-
+ }
+ default:
+ return -1;
}
}
{
case QTC_TOP_LEFT:
case QTC_TOP_RIGHT:
- QuadTreeIndex newNode;
+ {
if (nodes[start].child_type == QTC_TOP_LEFT)
- newNode = node[nodes[start].parent].bottom_left;
+ newNode = nodes[nodes[start].parent].bottom_left;
else
- newNode = node[nodes[start].parent].bottom_right;
+ newNode = nodes[nodes[start].parent].bottom_right;
return GetNeighbour(newNode, xdir, ydir - 1);
+ }
case QTC_BOTTOM_LEFT:
case QTC_BOTTOM_RIGHT:
+ {
QuadTreeIndex bottom_parent = GetNeighbour(nodes[start].parent, 0, 1);
if (bottom_parent == -1) return -1;
- QuadTreeIndex newNode;
if (nodes[start].child_type == QTC_BOTTOM_LEFT)
- newNode = node[bottom__parent].top_left;
+ newNode = nodes[bottom_parent].top_left;
else
- newNode = node[bottom_parent].top_right;
+ newNode = nodes[bottom_parent].top_right;
return GetNeighbour(newNode, xdir, ydir - 1);
-
+ }
+ default:
+ return -1;
}
}
{
case QTC_BOTTOM_LEFT:
case QTC_BOTTOM_RIGHT:
- QuadTreeIndex newNode;
+ {
if (nodes[start].child_type == QTC_BOTTOM_LEFT)
- newNode = node[nodes[start].parent].top_left;
+ newNode = nodes[nodes[start].parent].top_left;
else
- newNode = node[nodes[start].parent].top_right;
+ newNode = nodes[nodes[start].parent].top_right;
return GetNeighbour(newNode, xdir, ydir + 1);
+ }
case QTC_TOP_LEFT:
- case QTC_BOTTOM_LEFT:
+ case QTC_TOP_RIGHT:
+ {
QuadTreeIndex top_parent = GetNeighbour(nodes[start].parent, 0, -1);
if (top_parent == -1) return -1;
- QuadTreeIndex newNode;
if (nodes[start].child_type == QTC_TOP_LEFT)
- newNode = node[top_parent].bottom_left;
+ newNode = nodes[top_parent].bottom_left;
else
- newNode = node[top_parent].bottom_right;
+ newNode = nodes[top_parent].bottom_right;
return GetNeighbour(newNode, xdir, ydir + 1);
-
+ }
+ default:
+ return -1;
}
}
return -1;
QuadTreeIndex root_id;
std::vector<QuadTreeNode> nodes;
- QuadTreeIndex GetNeighbour(QuadTreeIndex start, int xdir, int ydir);
+ QuadTreeIndex GetNeighbour(QuadTreeIndex start, int xdir, int ydir) const;
};
if (pt_y >= y + h) return false;
return true;
}
+
+ inline bool Intersects(const Rect& other) const
+ {
+ if (x + w < other.x) return false;
+ if (y + h < other.y) return false;
+ if (x > other.x + other.w) return false;
+ if (y > other.y + other.h) return false;
+ return true;
+ }
};
inline Rect TransformRectCoordinates(const Rect& view, const Rect& r)
#ifndef QUADTREE_DISABLED
- m_quadtree_max_depth = 1;
+ m_quadtree_max_depth = 2;
m_current_quadtree_node = document.GetQuadTree().root_id;
#endif
}
#ifndef QUADTREE_DISABLED
if (m_bounds_dirty)
{
- if ( (m_bounds.x > 1.0 || m_bounds.x < 0.0 || m_bounds.y > 1.0 || m_bounds.y < 0.0 || m_bounds.w > 1.0 || m_bounds.h > 1.0))
+ if ( false && (m_bounds.x > 1.0 || m_bounds.x < 0.0 || m_bounds.y > 1.0 || m_bounds.y < 0.0 || m_bounds.w > 1.0 || m_bounds.h > 1.0))
{
//TODO: Generate a new parent node.
if (m_document.GetQuadTree().nodes[m_current_quadtree_node].parent != QUADTREE_EMPTY)
m_bounds_dirty = true;
RenderRange(width, height, m_document.GetQuadTree().nodes[node].object_begin, m_document.GetQuadTree().nodes[node].object_end);
+ if (m_bounds.Intersects(Rect(-1,-1,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x - 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, -1), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(-1,0,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x - 1, m_bounds.y, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 0), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(-1,1,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x - 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, -1, 1), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(0,-1,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x, m_bounds.y - 1, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, -1), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(0,1,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x, m_bounds.y + 1, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 0, 1), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(1,-1,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x + 1, m_bounds.y - 1, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, -1), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(1,0,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x + 1, m_bounds.y, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 0), remaining_depth - 1);
+ }
+ if (m_bounds.Intersects(Rect(1,1,1,1)))
+ {
+ m_bounds = Rect(m_bounds.x + 1, m_bounds.y + 1, m_bounds.w, m_bounds.h);
+ m_bounds_dirty = true;
+ RenderQuadtreeNode(width, height, m_document.GetQuadTree().GetNeighbour(node, 1, 1), remaining_depth - 1);
+ }
+ m_bounds = old_bounds;
+ m_bounds_dirty = true;
+
+#if 0
m_bounds = TransformToQuadChild(old_bounds, QTC_TOP_LEFT);
m_bounds_dirty = true;
RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].top_left, remaining_depth-1);
RenderQuadtreeNode(width, height, m_document.GetQuadTree().nodes[node].bottom_right, remaining_depth-1);
m_bounds = old_bounds;
m_bounds_dirty = true;
+#endif
}
#endif