File: Root.cpp

package info (click to toggle)
geos 3.4.2-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 16,572 kB
  • ctags: 13,989
  • sloc: cpp: 97,030; xml: 32,337; sh: 10,379; ansic: 3,726; php: 1,831; makefile: 1,619; ruby: 1,295; python: 928
file content (91 lines) | stat: -rw-r--r-- 2,547 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**********************************************************************
 *
 * GEOS - Geometry Engine Open Source
 * http://geos.osgeo.org
 *
 * Copyright (C) 2006 Refractions Research Inc.
 * Copyright (C) 2001-2002 Vivid Solutions Inc.
 *
 * This is free software; you can redistribute and/or modify it under
 * the terms of the GNU Lesser General Public Licence as published
 * by the Free Software Foundation. 
 * See the COPYING file for more information.
 *
 **********************************************************************/

#include <geos/index/bintree/Root.h>
#include <geos/index/bintree/Node.h>
#include <geos/index/bintree/Interval.h>
#include <geos/index/quadtree/IntervalSize.h>

#include <cstddef>
#include <cassert>
#include <cstddef>

namespace geos {
namespace index { // geos.index
namespace bintree { // geos.index.bintree

using namespace std;

double Root::origin=0.0;

void
Root::insert(Interval *itemInterval,void* item)
{
	int index=getSubnodeIndex(itemInterval,origin);
	// if index is -1, itemEnv must contain the origin.
	if (index==-1) {
		add(item);
		return;
	}

	/**
	 * the item must be contained in one interval, so insert it into the
	 * tree for that interval (which may not yet exist)
	 */
	Node *node=subnode[index];

	/**
	 *  If the subnode doesn't exist or this item is not contained in it,
	 *  have to expand the tree upward to contain the item.
	 */
	if (node==NULL || !node->getInterval()->contains(itemInterval))
	{
		Node* largerNode=Node::createExpanded(node,itemInterval);
//		delete subnode[index];
		subnode[index]=largerNode;
	}
	/**
	* At this point we have a subnode which exists and must contain
	* contains the env for the item.  Insert the item into the tree.
	*/
	insertContained(subnode[index],itemInterval,item);
	//System.out.println("depth = " + root.depth() + " size = " + root.size());
}

void
Root::insertContained(Node *tree, Interval *itemInterval, void* item)
{
	using geos::index::quadtree::IntervalSize;  

	assert(tree->getInterval()->contains(itemInterval));

	/**
	 * Do NOT create a new node for zero-area intervals - this would lead
	 * to infinite recursion. Instead, use a heuristic of simply returning
	 * the smallest existing node containing the query
	 */
	bool isZeroArea=IntervalSize::isZeroWidth(itemInterval->getMin(),
			itemInterval->getMax());
	NodeBase *node;
	if (isZeroArea)
		node=tree->find(itemInterval);
	else
		node=tree->getNode(itemInterval);
	node->add(item);
}

} // namespace geos.index.bintree
} // namespace geos.index
} // namespace geos