bounding box snippet (with toxiclib and java custom comparator)
in
Share your Work
•
10 months ago
hi! i have just written this piece of code, mayebe here there is someone that can both optimize oder find this usefull
- private Rect getBound(ArrayList<Vec2D> vertex2) {
- Comparator<Vec2D> x_order = new Comparator<Vec2D>() {
- @Override
- public int compare(Vec2D arg0, Vec2D arg1) {
- if (arg0.x() < arg1.x()) return 1;
- if (arg0.x() > arg1.x()) return -1;
- return 0;
- }
- };
- Comparator<Vec2D> y_order = new Comparator<Vec2D>() {
- @Override
- public int compare(Vec2D arg0, Vec2D arg1) {
- if (arg0.y() < arg1.y()) return 1;
- if (arg0.y() > arg1.y()) return -1;
- return 0;
- }
- };
- Collections.sort(vertex2, x_order);
- float maxx = vertex2.get(0).x;
- float minx = vertex2.get(vertex2.size()-1).x;
- Collections.sort(vertex2, y_order);
- float maxy = vertex2.get(0).y;
- float miny = vertex2.get(vertex2.size()-1).y;
- return new Rect(minx, miny, maxx-minx, maxy-miny);
- }