zoukankan      html  css  js  c++  java
  • Actionscript3版四叉树的插入与查询

    代码

    public function query(queryArea:Rectangle):Array
    {
        var result:Array 
    = [];

        
    for each (var item:IQuadNodeItem in contents)
        {
            
    if (queryArea.intersects(item.getRectangle()))
                result.push(item);
        }
        
    for each (var node:QuadNode in nodes)
        {
            
    if (node.isEmpty)
                
    continue;
            
    if (node.bounds.containsRect(queryArea))
            {
                result 
    = result.concat(node.query(queryArea));
                
    break;
            }
            
    if (queryArea.containsRect(node.bounds))
            {
                result 
    = result.concat(node.subTreeContents);
                
    continue;
            }
            
    if (node.bounds.intersects(queryArea))
                result 
    = result.concat(node.query(queryArea));
        }
        
    return result;
    }

    public function insert(item:IQuadNodeItem):void
    {
        
    if (!bounds.containsRect(item.getRectangle()))
            
    return;
        
    if (nodes.length == 0)
            createSubNodes();
        
    for each (var node:QuadNode in nodes)
        {
            
    if (node.bounds.containsRect(item.getRectangle()))
            {
                node.insert(item);
                
    return;
            }
        }
        
    this.contents.push(item);
    }
  • 相关阅读:
    How to Use .Net Remoting Using C#
    How to: Build a Client Application
    C# 禁用鼠标中间键
    秒杀系统:设计方案与实现思路
    JDBC连接数据库
    Java调用webService示例
    spring MVC
    rust贪吃蛇
    初识智遥工作流软件——表单开发篇2
    初识智遥工作流软件——表单开发篇1
  • 原文地址:https://www.cnblogs.com/sevenyuan/p/1624781.html
Copyright © 2011-2022 走看看