1. [代码]jsi-rtree-library

/**
 * 
 */
package com.mycompany.project;
 
//package net.sourceforge.jsi.examples;
 
import java.util.ArrayList;
import java.util.List;
 
import org.apache.log4j.Logger;
 
//import org.slf4j.*;
import com.infomatiq.jsi.*;
 
import gnu.trove.*;
 
import com.infomatiq.jsi.Rectangle;
import com.infomatiq.jsi.rtree.RTree;
 
public class Contains
{
    private static Logger logger = Logger.getLogger(Contains.class);
     
    public static void main(String[] args)
    {
        new Contains().run();
    }
 
    private void run()
    {
        // Create and initialize an rtree
        SpatialIndex si = new RTree();
        si.init(null);
 
        // We have some points or rectangles in some other data structure.
        // The rtree can handle millions of these.
        Rectangle[] rects = new Rectangle[] { new Rectangle(0, 0, 0, 0),
                new Rectangle(0, 1, 0, 1), new Rectangle(1, 0, 1, 0),
                new Rectangle(1, 1, 1, 1), 
                new Rectangle(0.0f, 0.25f, 0.5f, 0.75f),
                };
 
        // Add our data to the rtree. Every time we add a rectangle we give it
        // an ID. This ID is what is returned by querying the rtree. In this
        // example we use the array index as the ID.
        for (int i = 0; i < rects.length; i++)
        {
            si.add(rects[i], i);
        }
 
        // Now see which of these points is contained by some
        // other rectangle. The rtree returns the results of a query
        // by calling the execute() method on a TIntProcedure.
        // In this example we want to save the results of the query
        // into a list, so that's what the execute() method does.
        class SaveToListProcedure implements TIntProcedure
        {http://www.huiyi8.com/clxgt/窗帘效果图
            private List<Integer> ids = new ArrayList<Integer>();
 
            @Override
            public boolean execute(int id)
            {
                ids.add(id);
                return true;
            };
 
            private List<Integer> getIds()
            {
                return ids;
            }
        }
        ;
 
        SaveToListProcedure myProc = new SaveToListProcedure();
        si.contains(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), myProc);
 
         
        SaveToListProcedure insectMyProc = new SaveToListProcedure();
        si.intersects(new Rectangle(-0.5f, -0.5f, 1.5f, 0.5f), insectMyProc);
         
        List<Integer> intersectIds = insectMyProc.getIds();
         
        for (Integer integer : intersectIds)
        {
            logger.info(rects[integer].toString() + "was intersected!");
        }
         
    }
}

最新文章

  1. wpf版扫雷游戏
  2. cookie---session
  3. js原生碰撞检测
  4. django redis操作
  5. jquery重写一个对话框
  6. 在PHP5.3以上版本运行ecshop和ecmall出现的问题及解决方案
  7. secureFX中出现中文乱码修改方法
  8. Web缓存杂谈--Etag &amp; If-None-Match
  9. 异步工作流控制-condCall
  10. [SVN服务器搭建] 在myecplise下使用的 tortoise1.9 64位 跟 subversion1.9的服务器使用
  11. python3导入sqlite3报错
  12. webpack-工程化工具
  13. nodejs源码编译-mipse64el架构
  14. Oracle 在JDBC中使用 存储过程,包
  15. JS如何截取一段字符中,某一个字符的前面和后面的字符
  16. JS设计模式——工厂模式详解
  17. 高性能场景下,HashMap的优化使用建议
  18. ELK学习笔记之F5 DNS可视化让DNS运维更安全更高效-F5 ELK可视化方案系列(3)
  19. hadoop 视频教程2
  20. python的map函数和reduce函数(转)

热门文章

  1. Java实验--关于课上找“水王”问题分析
  2. SPOJ 8222 Substrings
  3. IntelliJ IDEA重构技巧收集
  4. tensorflow global_variables_initializer()
  5. IOS 教你玩转UITableViewController和TableView
  6. 如何提高NodeJS程序的运行的稳定性
  7. AngularJS的简单表单验证
  8. OpenGL之路(七)为立方体加入丰富色彩
  9. Cocos2d-X中提高性能的方法
  10. vue-router篇