Search in sources :

Example 11 with Dimension2D

use of java.awt.geom.Dimension2D in project netbeans-mmd-plugin by raydac.

the class ElementRoot method calcBlockSize.

@Override
@Nonnull
public Dimension2D calcBlockSize(@Nonnull final MindMapPanelConfig cfg, @Nonnull final Dimension2D size, final boolean childrenOnly) {
    final double insetV = cfg.getScale() * cfg.getFirstLevelVerticalInset();
    final double insetH = cfg.getScale() * cfg.getFirstLevelHorizontalInset();
    final Dimension2D result = size;
    double leftWidth = 0.0d;
    double leftHeight = 0.0d;
    double rightWidth = 0.0d;
    double rightHeight = 0.0d;
    boolean nonfirstOnLeft = false;
    boolean nonfirstOnRight = false;
    for (final Topic t : this.model.getChildren()) {
        final ElementLevelFirst w = assertNotNull((ElementLevelFirst) t.getPayload());
        w.calcBlockSize(cfg, result, false);
        if (w.isLeftDirection()) {
            leftWidth = Math.max(leftWidth, result.getWidth());
            leftHeight += result.getHeight();
            if (nonfirstOnLeft) {
                leftHeight += insetV;
            } else {
                nonfirstOnLeft = true;
            }
        } else {
            rightWidth = Math.max(rightWidth, result.getWidth());
            rightHeight += result.getHeight();
            if (nonfirstOnRight) {
                rightHeight += insetV;
            } else {
                nonfirstOnRight = true;
            }
        }
    }
    if (!childrenOnly) {
        leftWidth += nonfirstOnLeft ? insetH : 0.0d;
        rightWidth += nonfirstOnRight ? insetH : 0.0d;
    }
    this.leftBlockSize.setSize(leftWidth, leftHeight);
    this.rightBlockSize.setSize(rightWidth, rightHeight);
    if (childrenOnly) {
        result.setSize(leftWidth + rightWidth, Math.max(leftHeight, rightHeight));
    } else {
        result.setSize(leftWidth + rightWidth + this.bounds.getWidth(), Math.max(this.bounds.getHeight(), Math.max(leftHeight, rightHeight)));
    }
    return result;
}
Also used : Dimension2D(java.awt.geom.Dimension2D) Topic(com.igormaznitsa.mindmap.model.Topic) Nonnull(javax.annotation.Nonnull)

Example 12 with Dimension2D

use of java.awt.geom.Dimension2D in project litiengine by gurkenlabs.

the class GeometricUtilities method scaleRect.

public static Shape scaleRect(final Rectangle2D shape, final int max) {
    Dimension2D newDimension = scaleWithRatio(shape.getWidth(), shape.getHeight(), max);
    if (newDimension == null) {
        return shape;
    }
    final AffineTransform transform = AffineTransform.getScaleInstance(newDimension.getWidth(), newDimension.getHeight());
    return transform.createTransformedShape(shape);
}
Also used : Dimension2D(java.awt.geom.Dimension2D) AffineTransform(java.awt.geom.AffineTransform)

Example 13 with Dimension2D

use of java.awt.geom.Dimension2D in project litiengine by gurkenlabs.

the class GeometricUtilitiesTests method testScaleWithRatioWidth.

@ParameterizedTest(name = "testScaleWithRatioWidth width={0}, height={1}, max={2}, expectedValue={3}")
@CsvSource({ "16, 32, 16, 8", "32, 16, 16, 16" })
void testScaleWithRatioWidth(int width, int height, int max, int expectedValue) {
    Dimension2D newDimension = GeometricUtilities.scaleWithRatio(width, height, max);
    assertEquals(expectedValue, newDimension.getWidth(), 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