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;
}
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);
}
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);
}
Aggregations