Skip to content

Commit

Permalink
Optimize: Minor memory/speed optimisations
Browse files Browse the repository at this point in the history
  • Loading branch information
SonarSonic committed Mar 11, 2024
1 parent a096521 commit 82f36a1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/main/java/drawingbot/geom/shapes/GLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public void renderBresenham(BresenhamHelper helper, BresenhamHelper.IPixelSetter
helper.plotLine((int)getX1(), (int)getY1(), (int)getX2(), (int)getY2(), setter);
}

@Override
public void renderAWT(Graphics2D graphics) {
graphics.drawLine((int)getX1(), (int)getY1(), (int)getX2(), (int)getY2());
}

@Override
public IGeometry transformGeometry(AffineTransform transform) {
float[] coords = new float[]{getX1(), getY1(), getX2(), getY2()};
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/drawingbot/pfm/helpers/PFMRenderPipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import drawingbot.utils.Utils;

import java.awt.*;
import java.awt.geom.Line2D;

/**
* A basic class used for the rendering of geometries when erasing, having it as a seperate class allows for different implementations independent of the PFM.
Expand Down Expand Up @@ -77,15 +78,15 @@ public int eraseGeometry(IPixelData pixelData, IPixelData reference, IGeometry g
data.preDraw();
data.getCacheGraphics().setStroke(getDefaultStroke(lineWidth));
data.getCacheGraphics().setColor(getDefaultEraseColor(adjust));
data.getCacheGraphics().draw(geometry.getAWTShape());
geometry.renderAWT(data.getCacheGraphics());
data.postDraw(sampleTest);

colourSamples = sampleTest.getCurrentAverage();
}else{
//original method: using bresenham, fast but with non-anti aliased lines and no support for lineWidth.
sampleTest.resetColourSamples(adjust);
sampleTest.setPixelDataTargets(reference, pixelData);
bresenhamHelper.plotShape(geometry.getAWTShape(), sampleTest);//Erase the geometry and gather colour samples
geometry.renderBresenham(bresenhamHelper, sampleTest);//Erase the geometry and gather colour samples
colourSamples = sampleTest.getCurrentAverage();
}
return colourSamples;
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/drawingbot/plotting/PlottedDrawing.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@
import drawingbot.image.ImageTools;
import drawingbot.javafx.observables.ObservableDrawingPen;
import drawingbot.javafx.observables.ObservableDrawingSet;
import drawingbot.javafx.util.JFXUtils;
import drawingbot.pfm.PFMFactory;
import drawingbot.plotting.canvas.SimpleCanvas;
import drawingbot.registry.Register;
import drawingbot.utils.EnumDistributionOrder;
import drawingbot.utils.Metadata;
import drawingbot.utils.MetadataMap;
import drawingbot.utils.flags.Flags;
import javafx.application.Platform;
import org.jetbrains.annotations.Nullable;
import org.locationtech.jts.geom.Coordinate;

import java.awt.image.BufferedImage;
import java.io.File;
import java.text.NumberFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiConsumer;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/drawingbot/plotting/PlottedGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Map<ObservableDrawingPen, List<IGeometry>> getGeometriesPerPen(){
Map<ObservableDrawingPen, List<IGeometry>> newMap = new HashMap<>();
for(IGeometry geometry : geometries){
ObservableDrawingPen drawingPen = drawingSet.getPen(geometry.getPenIndex());
newMap.putIfAbsent(drawingPen, new ArrayList<>());
newMap.computeIfAbsent(drawingPen, (v) -> new ArrayList<>());
newMap.get(drawingPen).add(geometry);
}
geometriesPerPen = newMap;
Expand Down

0 comments on commit 82f36a1

Please sign in to comment.