2015-09-04 63 views
1

我不能得到一個RectF轉變成一個幾何體,然後檢測在一個點:矩形幾何不包括RectF中心

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的幾何形狀「可以包含」它的要點?

提前致謝!

回答

0

在GeometricShapeFactory.java的代碼通過使用創建包絡:

public Envelope getEnvelope() { 
    if (base != null) { 
    return new Envelope(base.x, base.x + width, base.y, base.y + height); 
    } 
    ... 
} 

Android有在左上方的原點(0,0);你必須將RectF的TOP加到它的高度以得到RectF的底部。所以基地必須是:

gsf.setBase(new Coordinate(r.left, r.top));