use of java.awt.geom.Dimension2D in project litiengine by gurkenlabs.
the class GeometricUtilitiesTests method testScaleWithRatio.
@Test
public void testScaleWithRatio() {
int width1 = 16;
int height1 = 32;
int width2 = 32;
int height2 = 16;
Dimension2D newDimension1 = GeometricUtilities.scaleWithRatio(width1, height1, 16);
Dimension2D newDimension2 = GeometricUtilities.scaleWithRatio(width2, height2, 16);
assertEquals(8, newDimension1.getWidth(), 0.0001);
assertEquals(16, newDimension1.getHeight(), 0.0001);
assertEquals(16, newDimension2.getWidth(), 0.0001);
assertEquals(8, newDimension2.getHeight(), 0.0001);
}
use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.
the class MindMapPanel method layoutModelElements.
@Nullable
public static Dimension2D layoutModelElements(@Nullable final MindMap model, @Nonnull final MindMapPanelConfig cfg) {
Dimension2D result = null;
if (model != null) {
final Topic rootTopic = model.getRoot();
if (rootTopic != null) {
final AbstractElement root = (AbstractElement) rootTopic.getPayload();
if (root != null) {
root.alignElementAndChildren(cfg, true, 0, 0);
result = root.getBlockSize();
}
}
}
return result;
}
use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.
the class MindMapPanel method renderMindMapAsImage.
@Nullable
public static BufferedImage renderMindMapAsImage(@Nonnull final MindMap model, @Nonnull final MindMapPanelConfig cfg, final boolean expandAll, @Nonnull final RenderQuality quality) {
final MindMap workMap = new MindMap(model, null);
workMap.resetPayload();
if (expandAll) {
MindMapUtils.removeCollapseAttr(workMap);
}
final Dimension2D blockSize = calculateSizeOfMapInPixels(workMap, null, cfg, expandAll, quality);
if (blockSize == null) {
return null;
}
final BufferedImage img = new BufferedImage((int) blockSize.getWidth(), (int) blockSize.getHeight(), BufferedImage.TYPE_INT_ARGB);
final Graphics2D g = img.createGraphics();
final MMGraphics gfx = new MMGraphics2DWrapper(g);
try {
quality.prepare(g);
gfx.setClip(0, 0, img.getWidth(), img.getHeight());
layoutFullDiagramWithCenteringToPaper(gfx, workMap, cfg, blockSize);
drawOnGraphicsForConfiguration(gfx, cfg, workMap, false, null);
} finally {
gfx.dispose();
}
return img;
}
use of java.awt.geom.Dimension2D in project litiengine by gurkenlabs.
the class GeometricUtilities method scaleWithRatio.
public static Dimension2D scaleWithRatio(final double width, final double height, final int max) {
if (width == 0 || height == 0) {
return null;
}
double dWidth;
double dHeight;
final double ratio = width / height;
final double newHeight = width / ratio;
final double newWidth = height * ratio;
if (newWidth == newHeight) {
dWidth = max;
dHeight = max;
} else if (newWidth > newHeight) {
dWidth = max;
dHeight = height / width * max;
} else {
dHeight = max;
dWidth = width / height * max;
}
Dimension2D dim = new Dimension();
dim.setSize(dWidth, dHeight);
return dim;
}
use of java.awt.geom.Dimension2D in project litiengine by gurkenlabs.
the class GeometricUtilitiesTests method testScaleWithRatioHeight.
@ParameterizedTest(name = "testScaleWithRatioHeight width={0}, height={1}, max={2}, expectedValue={3}")
@CsvSource({ "16, 32, 16, 16", "32, 16, 16, 8" })
void testScaleWithRatioHeight(int width, int height, int max, int expectedValue) {
Dimension2D newDimension1 = GeometricUtilities.scaleWithRatio(width, height, max);
assertEquals(expectedValue, newDimension1.getHeight(), 0.0001);
}
Aggregations