public void alignContent() { try { bounds = calculateBoundingBox(wrap(content)); } catch (Exception e) { return; } removeZeroExtends(bounds); double scale = 1; double[] e = bounds.getExtent(); double[] center = bounds.getCenter(); double objectSize = Math.max(Math.max(e[0], e[1]), e[2]); scale = contentSize / objectSize; Matrix matrix = MatrixBuilder.euclidean().scale(scale).getMatrix(); matrix.assignTo(scalingComponent); bounds = bounds.transformByMatrix(bounds, matrix.getArray()); center = bounds.getCenter(); FactoredMatrix factoredMatrix = new FactoredMatrix(transformationComponent.getTransformation()); double angle = factoredMatrix.getRotationAngle(); double[] axis = factoredMatrix.getRotationAxis(); Matrix m = MatrixBuilder.euclidean() .translate(0, verticalOffset, 0) .rotate(angle, axis) .translate(-center[0], -bounds.getMinY(), -center[2]) .getMatrix(); m.assignTo(transformationComponent); bounds = bounds.transformByMatrix(bounds, m.getArray()); }
private final void unionBox(Rectangle3D bbox) { if (bbox.isEmpty()) return; Rectangle3D tbox = bbox.transformByMatrix(null, currentTrafo); double[][] bnds = tbox.getBounds(); bound.xmin = Math.min(bound.xmin, bnds[0][0]); bound.xmax = Math.max(bound.xmax, bnds[1][0]); bound.ymin = Math.min(bound.ymin, bnds[0][1]); bound.ymax = Math.max(bound.ymax, bnds[1][1]); bound.zmin = Math.min(bound.zmin, bnds[0][2]); bound.zmax = Math.max(bound.zmax, bnds[1][2]); }