Skip to content

Commit ee7645f

Browse files
committed
open source release 2013-03-21
1 parent 3a1dd5a commit ee7645f

302 files changed

Lines changed: 105088 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/com/esri/core/geometry/AttributeStreamBase.java

Lines changed: 506 additions & 0 deletions
Large diffs are not rendered by default.

src/com/esri/core/geometry/AttributeStreamOfDbl.java

Lines changed: 810 additions & 0 deletions
Large diffs are not rendered by default.

src/com/esri/core/geometry/AttributeStreamOfFloat.java

Lines changed: 607 additions & 0 deletions
Large diffs are not rendered by default.

src/com/esri/core/geometry/AttributeStreamOfInt16.java

Lines changed: 592 additions & 0 deletions
Large diffs are not rendered by default.

src/com/esri/core/geometry/AttributeStreamOfInt32.java

Lines changed: 714 additions & 0 deletions
Large diffs are not rendered by default.

src/com/esri/core/geometry/AttributeStreamOfInt64.java

Lines changed: 592 additions & 0 deletions
Large diffs are not rendered by default.

src/com/esri/core/geometry/AttributeStreamOfInt8.java

Lines changed: 643 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
Copyright 1995-2013 Esri
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
For additional information, contact:
17+
Environmental Systems Research Institute, Inc.
18+
Attn: Contracts Dept
19+
380 New York Street
20+
Redlands, California, USA 92373
21+
22+
email: contracts@esri.com
23+
*/
24+
package com.esri.core.geometry;
25+
26+
class Boundary {
27+
static Geometry calculate(Geometry geom, ProgressTracker progress_tracker) {
28+
int gt = geom.getType().value();
29+
if (gt == Geometry.GeometryType.Polygon) {
30+
Polyline dst = new Polyline(geom.getDescription());
31+
if (!geom.isEmpty())
32+
geom.copyTo(dst);
33+
34+
return dst;
35+
} else if (gt == Geometry.GeometryType.Polyline) {
36+
return calculatePolylineBoundary_(geom._getImpl(), progress_tracker);
37+
} else if (gt == Geometry.GeometryType.Envelope) {
38+
Polyline dst = new Polyline(geom.getDescription());
39+
if (!geom.isEmpty())
40+
dst.addEnvelope((Envelope) geom, false);
41+
42+
return dst;
43+
} else if (Geometry.isSegment(gt)) {
44+
MultiPoint mp = new MultiPoint(geom.getDescription());
45+
if (!geom.isEmpty() && !((Segment) geom).isClosed()) {
46+
Point pt = new Point();
47+
((Segment) geom).queryStart(pt);
48+
mp.add(pt);
49+
((Segment) geom).queryEnd(pt);
50+
mp.add(pt);
51+
}
52+
return mp;
53+
} else if (Geometry.isPoint(gt)) {
54+
// returns empty point for points and multipoints.
55+
return null;
56+
}
57+
58+
throw new IllegalArgumentException();
59+
}
60+
61+
private static final class MultiPathImplBoundarySorter extends ClassicSort {
62+
AttributeStreamOfDbl m_xy;
63+
64+
static final class CompareIndices extends
65+
AttributeStreamOfInt32.IntComparator {
66+
AttributeStreamOfDbl m_xy;
67+
Point2D pt1_helper;
68+
Point2D pt2_helper;
69+
70+
CompareIndices(AttributeStreamOfDbl xy) {
71+
m_xy = xy;
72+
pt1_helper = new Point2D();
73+
pt2_helper = new Point2D();
74+
}
75+
76+
@Override
77+
public int compare(int v1, int v2) {
78+
m_xy.read(2 * v1, pt1_helper);
79+
m_xy.read(2 * v2, pt2_helper);
80+
return pt1_helper.compare(pt2_helper);
81+
}
82+
}
83+
84+
MultiPathImplBoundarySorter(AttributeStreamOfDbl xy) {
85+
m_xy = xy;
86+
}
87+
88+
@Override
89+
public void userSort(int begin, int end, AttributeStreamOfInt32 indices) {
90+
indices.Sort(begin, end, new CompareIndices(m_xy));
91+
}
92+
93+
@Override
94+
public double getValue(int index) {
95+
return m_xy.read(2 * index + 1);
96+
}
97+
}
98+
99+
static MultiPoint calculatePolylineBoundary_(Object impl,
100+
ProgressTracker progress_tracker) {
101+
MultiPathImpl mpImpl = (MultiPathImpl) impl;
102+
MultiPoint dst = new MultiPoint(mpImpl.getDescription());
103+
if (!mpImpl.isEmpty()) {
104+
AttributeStreamOfInt32 indices = new AttributeStreamOfInt32(0);
105+
indices.reserve(mpImpl.getPathCount() * 2);
106+
for (int ipath = 0, nPathCount = mpImpl.getPathCount(); ipath < nPathCount; ipath++) {
107+
int path_size = mpImpl.getPathSize(ipath);
108+
if (path_size > 0 && !mpImpl.isClosedPathInXYPlane(ipath))// closed
109+
// paths
110+
// of
111+
// polyline
112+
// do
113+
// not
114+
// contribute
115+
// to
116+
// the
117+
// boundary.
118+
{
119+
int start = mpImpl.getPathStart(ipath);
120+
indices.add(start);
121+
int end = mpImpl.getPathEnd(ipath) - 1;
122+
indices.add(end);
123+
}
124+
}
125+
if (indices.size() > 0) {
126+
BucketSort sorter = new BucketSort();
127+
AttributeStreamOfDbl xy = (AttributeStreamOfDbl) (mpImpl
128+
.getAttributeStreamRef(VertexDescription.Semantics.POSITION));
129+
sorter.sort(indices, 0, indices.size(),
130+
new MultiPathImplBoundarySorter(xy));
131+
Point2D ptPrev = new Point2D();
132+
xy.read(2 * indices.get(0), ptPrev);
133+
int ind = 0;
134+
int counter = 1;
135+
Point point = new Point();
136+
Point2D pt = new Point2D();
137+
for (int i = 1, n = indices.size(); i < n; i++) {
138+
xy.read(2 * indices.get(i), pt);
139+
if (pt.isEqual(ptPrev)) {
140+
if (indices.get(ind) > indices.get(i)) {
141+
// remove duplicate point
142+
indices.set(ind, NumberUtils.intMax());
143+
ind = i;// just for the heck of it, have the first
144+
// point in the order to be added to the
145+
// boundary.
146+
} else
147+
indices.set(i, NumberUtils.intMax());
148+
149+
counter++;
150+
} else {
151+
if ((counter & 1) == 0) {// remove boundary point
152+
indices.set(ind, NumberUtils.intMax());
153+
}
154+
155+
ptPrev.setCoords(pt);
156+
ind = i;
157+
counter = 1;
158+
}
159+
}
160+
161+
if ((counter & 1) == 0) {// remove the point
162+
indices.set(ind, NumberUtils.intMax());
163+
}
164+
165+
indices.sort(0, indices.size());
166+
167+
for (int i = 0, n = indices.size(); i < n; i++) {
168+
if (indices.get(i) == NumberUtils.intMax())
169+
break;
170+
171+
mpImpl.getPointByVal(indices.get(i), point);
172+
dst.add(point);
173+
}
174+
}
175+
}
176+
177+
return dst;
178+
}
179+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
Copyright 1995-2013 Esri
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
For additional information, contact:
17+
Environmental Systems Research Institute, Inc.
18+
Attn: Contracts Dept
19+
380 New York Street
20+
Redlands, California, USA 92373
21+
22+
email: contracts@esri.com
23+
*/
24+
package com.esri.core.geometry;
25+
26+
final class BucketSort {
27+
AttributeStreamOfInt32 m_buckets;
28+
AttributeStreamOfInt32 m_bucketed_indices;
29+
double m_min_value;
30+
double m_max_value;
31+
double m_dy;
32+
33+
static int MAXBUCKETS = 65536;
34+
35+
public BucketSort() {
36+
m_buckets = new AttributeStreamOfInt32(0);
37+
m_bucketed_indices = new AttributeStreamOfInt32(0);
38+
m_min_value = 1;
39+
m_max_value = -1;
40+
m_dy = NumberUtils.TheNaN;
41+
}
42+
43+
/**
44+
* Executes sort on the Bucket_sort. The result is fed into the indices
45+
* array in the range between begin (inclusive) and end (exclusive). Uses
46+
* user supplied sorter to execute sort on each bucket. Users either supply
47+
* the sorter and use this method of Bucket_sort class, or use other methods
48+
* to form the buckets and take care of bucket sorting themselves.
49+
*/
50+
public void sort(AttributeStreamOfInt32 indices, int begin, int end,
51+
ClassicSort sorter) {
52+
if (end - begin < 32) {
53+
sorter.userSort(begin, end, indices);
54+
return;
55+
}
56+
boolean b_fallback = true;
57+
try {
58+
double miny = NumberUtils.positiveInf();
59+
double maxy = NumberUtils.negativeInf();
60+
for (int i = begin; i < end; i++) {
61+
double y = sorter.getValue(indices.get(i));
62+
if (y < miny)
63+
miny = y;
64+
if (y > maxy)
65+
maxy = y;
66+
}
67+
68+
if (reset(end - begin, miny, maxy, end - begin)) {
69+
for (int i = begin; i < end; i++) {
70+
int vertex = indices.get(i);
71+
double y = sorter.getValue(vertex);
72+
int bucket = getBucket(y);
73+
m_buckets.set(bucket, m_buckets.get(bucket) + 1);// counting
74+
// values
75+
// in a
76+
// bucket.
77+
m_bucketed_indices.write(i - begin, vertex);
78+
}
79+
80+
// Recalculate buckets to contain start positions of buckets.
81+
int c = m_buckets.get(0);
82+
m_buckets.set(0, 0);
83+
for (int i = 1, n = m_buckets.size(); i < n; i++) {
84+
int b = m_buckets.get(i);
85+
m_buckets.set(i, c);
86+
c += b;
87+
}
88+
89+
for (int i = begin; i < end; i++) {
90+
int vertex = m_bucketed_indices.read(i - begin);
91+
double y = sorter.getValue(vertex);
92+
int bucket = getBucket(y);
93+
int bucket_index = m_buckets.get(bucket);
94+
indices.set(bucket_index + begin, vertex);
95+
m_buckets.set(bucket, bucket_index + 1);
96+
}
97+
98+
b_fallback = false;
99+
}
100+
} catch (Exception e) {
101+
m_buckets.resize(0);
102+
m_bucketed_indices.resize(0);
103+
}
104+
105+
if (b_fallback) {
106+
sorter.userSort(begin, end, indices);
107+
return;
108+
}
109+
110+
int j = 0;
111+
for (int i = 0, n = m_buckets.size(); i < n; i++) {
112+
int j0 = j;
113+
j = m_buckets.get(i);
114+
if (j > j0)
115+
sorter.userSort(begin + j0, begin + j, indices);
116+
}
117+
assert (j == end);
118+
119+
if (getBucketCount() > 100) // some heuristics to preserve memory
120+
{
121+
m_buckets.resize(0);
122+
m_bucketed_indices.resize(0);
123+
}
124+
}
125+
126+
/**
127+
* Clears and resets Bucket_sort to the new state, preparing for the
128+
* accumulation of new data.
129+
*
130+
* @param bucket_count
131+
* - the number of buckets. Usually equal to the number of
132+
* elements to sort.
133+
* @param min_value
134+
* - the minimum value of elements to sort.
135+
* @param max_value
136+
* - the maximum value of elements to sort.
137+
* @param capacity
138+
* - the number of elements to sort (-1 if not known). The
139+
* bucket_count are usually equal.
140+
* @return Returns False, if the bucket sort cannot be used with the given
141+
* parameters. The method also can throw out of memory exception. In
142+
* the later case, one should fall back to the regular sort.
143+
*/
144+
private boolean reset(int bucket_count, double min_value, double max_value,
145+
int capacity) {
146+
if (bucket_count < 2 || max_value == min_value)
147+
return false;
148+
149+
int bc = Math.min(MAXBUCKETS, bucket_count);
150+
m_buckets.reserve(bc);
151+
m_buckets.resize(bc);
152+
m_buckets.setRange(0, 0, m_buckets.size());
153+
m_min_value = min_value;
154+
m_max_value = max_value;
155+
m_bucketed_indices.resize(capacity);
156+
157+
m_dy = (max_value - min_value) / (bc - 1);
158+
return true;
159+
}
160+
161+
/**
162+
* Adds new element to the bucket builder. The value must be between
163+
* min_value and max_value.
164+
*
165+
* @param The
166+
* value used for bucketing.
167+
* @param The
168+
* index of the element to store in the buffer. Usually it is an
169+
* index into some array, where the real elements are stored.
170+
*/
171+
private int getBucket(double value) {
172+
assert (value >= m_min_value && value <= m_max_value);
173+
int bucket = (int) ((value - m_min_value) / m_dy);
174+
return bucket;
175+
}
176+
177+
/**
178+
* Returns the bucket count.
179+
*/
180+
private int getBucketCount() {
181+
return m_buckets.size();
182+
}
183+
184+
}

0 commit comments

Comments
 (0)