下面列出了android.graphics.RectF#sort ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static RectF trapToRect(float[] array) {
RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
for (int i = 1; i < array.length; i += 2) {
float x = round(array[i - 1] * 10) / 10.f;
float y = round(array[i] * 10) / 10.f;
r.left = (x < r.left) ? x : r.left;
r.top = (y < r.top) ? y : r.top;
r.right = (x > r.right) ? x : r.right;
r.bottom = (y > r.bottom) ? y : r.bottom;
}
r.sort();
return r;
}
/**
* Takes an array of 2D coordinates representing corners and returns the
* smallest rectangle containing those coordinates.
*
* @param array array of 2D coordinates
* @return smallest rectangle containing coordinates
*/
public static RectF trapToRect(float[] array) {
RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
for (int i = 1; i < array.length; i += 2) {
float x = Math.round(array[i - 1] * 10) / 10.f;
float y = Math.round(array[i] * 10) / 10.f;
r.left = (x < r.left) ? x : r.left;
r.top = (y < r.top) ? y : r.top;
r.right = (x > r.right) ? x : r.right;
r.bottom = (y > r.bottom) ? y : r.bottom;
}
r.sort();
return r;
}
public static RectF trapToRect(float[] array) {
RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY,
Float.NEGATIVE_INFINITY);
for (int i = 1; i < array.length; i += 2) {
float x = round(array[i - 1] * 10) / 10.f;
float y = round(array[i] * 10) / 10.f;
r.left = (x < r.left) ? x : r.left;
r.top = (y < r.top) ? y : r.top;
r.right = (x > r.right) ? x : r.right;
r.bottom = (y > r.bottom) ? y : r.bottom;
}
r.sort();
return r;
}
/**
* Takes an array of 2D coordinates representing corners and returns the
* smallest rectangle containing those coordinates.
*
* @param array array of 2D coordinates
* @return smallest rectangle containing coordinates
*/
public static RectF trapToRect(float[] array) {
RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
for (int i = 1; i < array.length; i += 2) {
float x = Math.round(array[i - 1] * 10) / 10.f;
float y = Math.round(array[i] * 10) / 10.f;
r.left = (x < r.left) ? x : r.left;
r.top = (y < r.top) ? y : r.top;
r.right = (x > r.right) ? x : r.right;
r.bottom = (y > r.bottom) ? y : r.bottom;
}
r.sort();
return r;
}
/**
* Takes an array of 2D coordinates representing corners and returns the
* smallest rectangle containing those coordinates.
*
* @param array array of 2D coordinates
* @return smallest rectangle containing coordinates
*/
public static RectF trapToRect(float[] array) {
RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
for (int i = 1; i < array.length; i += 2) {
float x = Math.round(array[i - 1] * 10) / 10.f;
float y = Math.round(array[i] * 10) / 10.f;
r.left = (x < r.left) ? x : r.left;
r.top = (y < r.top) ? y : r.top;
r.right = (x > r.right) ? x : r.right;
r.bottom = (y > r.bottom) ? y : r.bottom;
}
r.sort();
return r;
}
/**
* Takes an array of 2D coordinates representing corners and returns the
* smallest rectangle containing those coordinates.
*
* @param array array of 2D coordinates
* @return smallest rectangle containing coordinates
*/
public static RectF trapToRect(float[] array) {
RectF r = new RectF(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY,
Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
for (int i = 1; i < array.length; i += 2) {
float x = array[i - 1];
float y = array[i];
r.left = (x < r.left) ? x : r.left;
r.top = (y < r.top) ? y : r.top;
r.right = (x > r.right) ? x : r.right;
r.bottom = (y > r.bottom) ? y : r.bottom;
}
r.sort();
return r;
}
private boolean checkLinkTapped(float x, float y) {
PdfFile pdfFile = pdfView.pdfFile;
if (pdfFile == null) {
return false;
}
float mappedX = -pdfView.getCurrentXOffset() + x;
float mappedY = -pdfView.getCurrentYOffset() + y;
int page = pdfFile.getPageAtOffset(pdfView.isSwipeVertical() ? mappedY : mappedX, pdfView.getZoom());
SizeF pageSize = pdfFile.getScaledPageSize(page, pdfView.getZoom());
int pageX, pageY;
if (pdfView.isSwipeVertical()) {
pageX = (int) pdfFile.getSecondaryPageOffset(page, pdfView.getZoom());
pageY = (int) pdfFile.getPageOffset(page, pdfView.getZoom());
} else {
pageY = (int) pdfFile.getSecondaryPageOffset(page, pdfView.getZoom());
pageX = (int) pdfFile.getPageOffset(page, pdfView.getZoom());
}
for (PdfDocument.Link link : pdfFile.getPageLinks(page)) {
RectF mapped = pdfFile.mapRectToDevice(page, pageX, pageY, (int) pageSize.getWidth(),
(int) pageSize.getHeight(), link.getBounds());
mapped.sort();
if (mapped.contains(mappedX, mappedY)) {
pdfView.callbacks.callLinkHandler(new LinkTapEvent(x, y, mappedX, mappedY, mapped, link));
return true;
}
}
return false;
}
public RectF getRect() {
RectF rect = new RectF(point1.x, point1.y, point2.x, point2.y);
rect.sort();
return rect;
}