Search in sources :

Example 1 with Dimension2D

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);
}
Also used : Dimension2D(java.awt.geom.Dimension2D) Test(org.junit.jupiter.api.Test)

Example 2 with Dimension2D

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;
}
Also used : Dimension2D(java.awt.geom.Dimension2D) Nullable(javax.annotation.Nullable)

Example 3 with Dimension2D

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;
}
Also used : MMGraphics2DWrapper(com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics2DWrapper) Dimension2D(java.awt.geom.Dimension2D) MMGraphics(com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics) BufferedImage(java.awt.image.BufferedImage) Nullable(javax.annotation.Nullable)

Example 4 with Dimension2D

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;
}
Also used : Dimension2D(java.awt.geom.Dimension2D) Dimension(java.awt.Dimension)

Example 5 with Dimension2D

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);
}
Also used : Dimension2D(java.awt.geom.Dimension2D) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Dimension2D (java.awt.geom.Dimension2D)13 Nullable (javax.annotation.Nullable)4 Topic (com.igormaznitsa.mindmap.model.Topic)3 MMGraphics (com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics)2 MMGraphics2DWrapper (com.igormaznitsa.mindmap.swing.panel.ui.gfx.MMGraphics2DWrapper)2 Dimension (java.awt.Dimension)2 BufferedImage (java.awt.image.BufferedImage)2 Nonnull (javax.annotation.Nonnull)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 CsvSource (org.junit.jupiter.params.provider.CsvSource)2 java.awt (java.awt)1 AffineTransform (java.awt.geom.AffineTransform)1 java.awt.image (java.awt.image)1 MultiResolutionImage (java.awt.image.MultiResolutionImage)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1 MultiResolutionCachedImage (sun.awt.image.MultiResolutionCachedImage)1 SunWritableRaster (sun.awt.image.SunWritableRaster)1