Vastly improve performance of selection aree calculations, especially

with bigger layouts
This commit is contained in:
Branislav Stojkovic
2018-12-25 11:41:09 +01:00
parent 1cfe2ee99a
commit b489adf7c7
5 changed files with 2378 additions and 2349 deletions
@@ -23,7 +23,6 @@ import java.awt.Graphics2D;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
import java.awt.dnd.DnDConstants; import java.awt.dnd.DnDConstants;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
@@ -870,19 +869,33 @@ public class Presenter implements IPlugInPort {
if (selectedComponents == null || selectedComponents.isEmpty()) if (selectedComponents == null || selectedComponents.isEmpty())
return null; return null;
Area totalArea = new Area(); int minX = Integer.MAX_VALUE;
int maxX = Integer.MIN_VALUE;
int minY = Integer.MAX_VALUE;
int maxY = Integer.MIN_VALUE;
for (IDIYComponent<?> c : selectedComponents) { for (IDIYComponent<?> c : selectedComponents) {
ComponentArea compArea = drawingManager.getComponentArea(c); ComponentArea compArea = drawingManager.getComponentArea(c);
if (compArea != null && compArea.getOutlineArea() != null) if (compArea != null && compArea.getOutlineArea() != null) {
totalArea.add(compArea.getOutlineArea()); Rectangle rect = compArea.getOutlineArea().getBounds();
else if (rect.x < minX)
LOG.warn("Area is null for " + c.getName() + " of type " + c.getClass().getName()); minX = rect.x;
if (rect.x + rect.width > maxX)
maxX = rect.x + rect.width;
if (rect.y < minY)
minY = rect.y;
if (rect.y + rect.height > maxY)
maxY = rect.y + rect.height;
} else
LOG.info("Area is null for " + c.getName() + " of type "
+ c.getClass().getName());
} }
if (drawingManager.getZoomLevel() != 1 && applyZoom) { if (drawingManager.getZoomLevel() != 1 && applyZoom) {
totalArea minX *= drawingManager.getZoomLevel();
.transform(AffineTransform.getScaleInstance(drawingManager.getZoomLevel(), drawingManager.getZoomLevel())); maxX *= drawingManager.getZoomLevel();
minY *= drawingManager.getZoomLevel();
maxY *= drawingManager.getZoomLevel();
} }
return totalArea.getBounds2D(); return new Rectangle2D.Double(minX, minY, maxX - minX, maxY - minY);
} }
@Override @Override
Binary file not shown.
+1 -1
View File
@@ -7,7 +7,7 @@
<property name="jar.dir" value="${build.dir}/jar" /> <property name="jar.dir" value="${build.dir}/jar" />
<property name="report.dir" value="${build.dir}/junitreport" /> <property name="report.dir" value="${build.dir}/junitreport" />
<property name="main.class" value="org.diylc.DIYLCStarter" /> <property name="main.class" value="org.diylc.DIYLCStarter" />
<property name="diylc.version" value="3.45.0" /> <property name="diylc.version" value="3.46.0" />
<property name="classes.dir" value="${build.dir}/temp/${ant.project.name}/classes" /> <property name="classes.dir" value="${build.dir}/temp/${ant.project.name}/classes" />
<property name="test.classes.dir" value="${build.dir}/temp/${ant.project.name}/test.classes" /> <property name="test.classes.dir" value="${build.dir}/temp/${ant.project.name}/test.classes" />
Binary file not shown.
+16
View File
@@ -2029,5 +2029,21 @@
</changes> </changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url> <url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version> </org.diylc.appframework.update.Version>
<org.diylc.appframework.update.Version>
<versionNumber>
<major>3</major>
<minor>46</minor>
<build>0</build>
</versionNumber>
<releaseDate>2018-12-25 00:00:00.000 CET</releaseDate>
<name></name>
<changes>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Vastly improve performance of selection aree calculations, especially with bigger layouts</description>
</org.diylc.appframework.update.Change>
</changes>
<url>https://github.com/bancika/diy-layout-creator/releases</url>
</org.diylc.appframework.update.Version>
</a> </a>
</java.util.Arrays_-ArrayList> </java.util.Arrays_-ArrayList>