我无法将RectF转换为Geometry,然后在其中检测到一个点:
public static Geometry RectFtoGeometry(RectF r) {
GeometricShapeFactory gsf = new GeometricShapeFactory();
gsf.setBase(new Coordinate(r.left, r.bottom));
gsf.setNumPoints(4);
gsf.setWidth(r.width());
gsf.setHeight(r.height());
Geometry rect = gsf.createRectangle(),
point = new GeometryFactory().createPoint(new Coordinate(r.centerX(), r.centerY()));
if(!rect.contains(point))
throw new IllegalArgumentException();//This gets thrown
return gsf.createRectangle();
}
如何从“可以包含”其点的RectF创建几何?
提前致谢!
最佳答案
GeometricShapeFactory.java中的代码使用以下方法创建信封:
public Envelope getEnvelope() {
if (base != null) {
return new Envelope(base.x, base.x + width, base.y, base.y + height);
}
...
}
Android的原点(0,0)在左侧的TOP处;您必须将RectF的TOP与其高度相加才能得出RectF的底部。因此,基础必须是:
gsf.setBase(new Coordinate(r.left, r.top));