📄 webringinspector.java
字号:
package com.esri.solutions.jitk.common.geometry;
import com.esri.adf.web.data.geometry.WebPoint;
import com.esri.adf.web.data.geometry.WebRing;
public class WebRingInspector {
protected WebRing _ring;
/**
* Constructor
* @param ring {@link WebRing} converted to screen coordinates to be inspected
*/
public WebRingInspector(WebRing ring) {
_ring = ring;
}
/**
* Returns true if the {@link WebRing} repeats the last vertex
* @return true if the {@link WebRing} repeats the last vertex
*/
public boolean isLastVertexRepeated() {
WebPoint p1 = _ring.getPoints().get(0);
WebPoint p2 = _ring.getPoints().get(_ring.getPoints().size() - 1);
boolean isSame = false;
if (p1.getX() == p2.getX()) {
if (p1.getY() == p2.getY()) {
isSame = true;
}
}
return isSame;
}
protected double inverse(double d) {
return -1 * d;
}
/**
* Determines if the orientation of the passed {@Link WebRing} is clockwise.
* This method assumes the geometry has been converted to the screen coordinates,
* not geographically spatial coordinates.
* @return true if the orientation of the ring is clockwise
* @throws {@link InvalidWebGeometryException} if ring has less than 3 vertices
*/
public boolean isClockwise() throws InvalidWebGeometryException {
//Algorithm ported from http://debian.fmi.uni-sofia.bg/~sergei/cgsr/docs/clockwise.htm
if (_ring == null) {
throw new NullPointerException("ring is null");
}
if (_ring.getPoints() == null) {
throw new NullPointerException("ring point collection (list) is null");
}
double z;
int count = 0;
int vertexCount = _ring.getPoints().size();
if (isLastVertexRepeated()) {
vertexCount--;
}
if (vertexCount < 3) {
throw new InvalidWebGeometryException("Ring has less than 3 vertices");
} else {
for (int vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) {
int j = (vertexIndex + 1) % vertexCount;
int k = (vertexIndex + 2) % vertexCount;
WebPoint vertexJ = _ring.getPoints().get(j);
WebPoint vertexK = _ring.getPoints().get(k);
WebPoint vertexI = _ring.getPoints().get(vertexIndex);
z = (vertexJ.getX() - vertexI.getX()) * (inverse(vertexK.getY()) - inverse(vertexJ.getY()));
z -= (inverse(vertexJ.getY()) - inverse(vertexI.getY())) * (vertexK.getX() - vertexJ.getX());
if (z < 0) {
count--;
} else if (z > 0) {
count++;
}
}
if (count > 0) {
return false;
} else if (count < 0) {
return true;
} else {
throw new InvalidWebGeometryException("Clockwise orientation of ring could not be determined");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -