I can't get to transform a RectF into a Geometry and then detect a point in it:
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();
}
How can I create a Geometry from a RectF that "can contain" its points?
Thanks in advance!
The code in GeometricShapeFactory.java creates the envelope by using:
public Envelope getEnvelope() {
if (base != null) {
return new Envelope(base.x, base.x + width, base.y, base.y + height);
}
...
}
Android has the origin (0,0) at the left TOP; you have to sum the TOP of the RectF to its height to get the bottom of the RectF. So the base must be:
gsf.setBase(new Coordinate(r.left, r.top));