From 4e469e82e96199318124d1d7e5335f50893e6e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Fri, 8 Dec 2023 00:15:56 +0100 Subject: [PATCH 1/2] Add some support --- .../packing/api/HorizontalSupport.java | 33 +++++++++++ .../packing/api/SupportPlacement3D.java | 21 +++++++ .../packing/api/SupportStackPlacement.java | 59 +++++++++++++++++++ .../packing/api/SupportedPlacement3D.java | 23 -------- .../packing/api/SupportedStackPlacement.java | 16 ----- .../skjolber/packing/api/VerticalSupport.java | 44 ++++++++++++++ 6 files changed, 157 insertions(+), 39 deletions(-) create mode 100644 api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/SupportedPlacement3D.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/SupportedStackPlacement.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java diff --git a/api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java b/api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java new file mode 100644 index 00000000..59c3dd48 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java @@ -0,0 +1,33 @@ +package com.github.skjolber.packing.api; + +import java.io.Serializable; + +public class HorizontalSupport implements Serializable { + + private static final long serialVersionUID = 1L; + + private final SupportPlacement3D negative; + private final SupportPlacement3D positive; + + private final long area; + + public HorizontalSupport(SupportPlacement3D negative, SupportPlacement3D positive, long area) { + super(); + this.negative = negative; + this.positive = positive; + this.area = area; + } + + public SupportPlacement3D getNegative() { + return negative; + } + + public SupportPlacement3D getPositive() { + return positive; + } + + public long getArea() { + return area; + } + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java b/api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java new file mode 100644 index 00000000..2cf5eee0 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java @@ -0,0 +1,21 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +import com.github.skjolber.packing.api.Surface.Label; + +public interface SupportPlacement3D extends Placement3D { + + List getBottomSupports(); + + List getTopSupports(); + + List getLeftSupports(); + + List getRightSupports(); + + List getFrontSupports(); + + List getRearSupports(); + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java b/api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java new file mode 100644 index 00000000..1ad18cc9 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java @@ -0,0 +1,59 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +public class SupportStackPlacement extends StackPlacement implements SupportPlacement3D { + + private static final long serialVersionUID = 1L; + + protected List bottomSupports; + + protected List topSupports; + + protected List leftSupports; + + protected List rightSupports; + + protected List frontSupports; + + protected List rearSupports; + + public SupportStackPlacement() { + super(); + } + + public SupportStackPlacement(Stackable stackable, StackValue value, int x, int y, int z) { + super(stackable, value, x, y, z); + } + + @Override + public List getBottomSupports() { + return bottomSupports; + } + + @Override + public List getTopSupports() { + return topSupports; + } + + @Override + public List getLeftSupports() { + return leftSupports; + } + + @Override + public List getRightSupports() { + return rightSupports; + } + + @Override + public List getFrontSupports() { + return frontSupports; + } + + @Override + public List getRearSupports() { + return rearSupports; + } + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/SupportedPlacement3D.java b/api/src/main/java/com/github/skjolber/packing/api/SupportedPlacement3D.java deleted file mode 100644 index 3d897f46..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/SupportedPlacement3D.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.github.skjolber.packing.api; - -import java.util.List; - -import com.github.skjolber.packing.api.Surface.Label; - -public interface SupportedPlacement3D extends Placement3D { - - List getBottomSupports(); - - List getTopSupports(); - - List getLeftSupports(); - - List getRightSupports(); - - List getFrontSupports(); - - List getRearSupports(); - - List getSupports(Label label); - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/SupportedStackPlacement.java b/api/src/main/java/com/github/skjolber/packing/api/SupportedStackPlacement.java deleted file mode 100644 index 7eea82b1..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/SupportedStackPlacement.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.github.skjolber.packing.api; - -public class SupportedStackPlacement extends StackPlacement { - - private static final long serialVersionUID = 1L; - - public SupportedStackPlacement() { - super(); - } - - public SupportedStackPlacement(Stackable stackable, StackValue value, int x, int y, int z) { - super(stackable, value, x, y, z); - } - - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java b/api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java new file mode 100644 index 00000000..3cfaf4c4 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java @@ -0,0 +1,44 @@ +package com.github.skjolber.packing.api; + +import java.io.Serializable; + +public class VerticalSupport implements Serializable { + + private static final long serialVersionUID = 1L; + + private final SupportPlacement3D negative; + private final SupportPlacement3D positive; + + private final long area; + + private int weightLimit; + + public VerticalSupport(SupportPlacement3D negative, SupportPlacement3D positive, long area, int weightLimit) { + super(); + this.negative = negative; + this.positive = positive; + this.area = area; + this.weightLimit = weightLimit; + } + + public SupportPlacement3D getNegative() { + return negative; + } + + public SupportPlacement3D getPositive() { + return positive; + } + + public long getArea() { + return area; + } + + public void decrementWeightLimit(int weightLimit) { + this.weightLimit -= weightLimit; + } + + public int getWeightLimit() { + return weightLimit; + } + +} From 805e3df270ca939524e5ecf3c20599f402885d47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Skj=C3=B8lberg?= Date: Wed, 14 Aug 2024 22:48:43 +0200 Subject: [PATCH 2/2] Remove generics, various prototypes --- .../AbstractStackScopeConstraintBuilder.java | 33 ++ .../com/github/skjolber/packing/api/Box.java | 8 + .../skjolber/packing/api/BoxStackValue.java | 13 + .../packing/api/ContainerLoadStackValue.java | 31 ++ .../packing/api/ContainerLoadable.java | 74 +++++ .../packing/api/ContainerStackValue.java | 32 +- .../packing/api/DefaultContainer.java | 8 + .../api/DefaultContainerStackValue.java | 2 +- .../api/DefaultStackScopeConstraint.java | 29 ++ .../DefaultStackScopeConstraintBuilder.java | 10 + .../api/FixedOrderStackScopeConstraint.java | 11 + .../packing/api/HorizontalSupport.java | 33 -- .../skjolber/packing/api/Placement2D.java | 14 - .../skjolber/packing/api/Placement3D.java | 11 - .../skjolber/packing/api/StackFactory.java | 6 + .../skjolber/packing/api/StackPlacement.java | 9 +- .../skjolber/packing/api/StackScope.java | 10 + .../skjolber/packing/api/StackValue.java | 4 +- .../packing/api/StackableItemGroup.java | 32 ++ .../packing/api/StackablePointFilter.java | 16 + .../packing/api/StackableScopeFactory.java | 5 + .../packing/api/SupportPlacement3D.java | 21 -- .../packing/api/SupportStackPlacement.java | 59 ---- .../skjolber/packing/api/VerticalSupport.java | 44 --- .../packing/api/ep/ExtremePoints.java | 13 +- .../skjolber/packing/api/ep/Point3D.java | 186 ++++++++--- .../packing/api/ep/StackablePoints.java | 12 + .../api/packager/EnclosedStackValue.java | 31 ++ .../api/packager/EnclosedStackableItem.java | 72 ++++ .../AbstractBruteForcePackager.java | 23 +- .../bruteforce/BruteForcePackagerResult.java | 6 +- .../bruteforce/ExtremePoints3DStack.java | 14 +- .../bruteforce/FastBruteForcePackager.java | 6 +- .../bruteforce/FastExtremePoints3DStack.java | 25 +- .../AbstractLargestAreaFitFirstPackager.java | 39 +-- .../laff/FastLargestAreaFitFirstPackager.java | 50 ++- .../laff/LargestAreaFitFirstPackager.java | 45 ++- ...gestAreaFitFirstPackagerResultBuilder.java | 4 +- .../packer/laff/StackValuePointFilter.java | 27 -- .../packing/packer/laff}/StackableFilter.java | 4 +- .../packer/plain/AbstractPlainPackager.java | 4 +- .../packing/packer/plain/PlainPackager.java | 12 +- .../plain/PlainPackagerResultBuilder.java | 4 +- .../bruteforce/BruteForcePackagerTest.java | 2 +- .../FastBruteForcePackagerTest.java | 2 +- .../ParallelBruteForcePackagerTest.java | 2 +- .../laff/LargestAreaFitFirstPackagerTest.java | 2 +- .../ep/points2d/DefaultPlacement2D.java | 53 --- .../packing/ep/points2d/DefaultPoint2D.java | 25 +- .../ep/points2d/DefaultXSupportPoint2D.java | 33 +- .../ep/points2d/DefaultXYSupportPoint2D.java | 39 ++- .../ep/points2d/DefaultYSupportPoint2D.java | 33 +- .../packing/ep/points2d/ExtremePoints2D.java | 146 ++++---- .../packing/ep/points2d}/Point2D.java | 31 +- .../packing/ep/points2d/Point2DFlagList.java | 32 +- .../packing/ep/points2d/Point2DList.java | 21 +- .../packing/ep/points2d/SimplePoint2D.java | 13 +- .../ep/points3d/CustomIntXComparator.java | 8 +- .../ep/points3d/CustomIntYComparator.java | 8 +- .../ep/points3d/CustomIntZComparator.java | 8 +- .../ep/points3d/Default3DPlanePoint3D.java | 96 +++--- .../ep/points3d/DefaultPlacement3D.java | 87 ----- .../packing/ep/points3d/DefaultPoint3D.java | 44 +-- .../ep/points3d/DefaultXYPlanePoint3D.java | 52 ++- .../DefaultXYPlaneXZPlanePoint3D.java | 70 ++-- .../DefaultXYPlaneYZPlanePoint3D.java | 72 ++-- .../ep/points3d/DefaultXZPlanePoint3D.java | 52 ++- .../DefaultXZPlaneYZPlanePoint3D.java | 70 ++-- .../ep/points3d/DefaultYZPlanePoint3D.java | 52 ++- .../packing/ep/points3d/ExtremePoints3D.java | 231 ++++++------- .../packing/ep/points3d/Point3DArray.java | 20 +- .../packing/ep/points3d/Point3DFlagList.java | 32 +- .../packing/ep/points3d/Point3DList.java | 20 +- .../packing/ep/points3d/Point3DListArray.java | 19 +- .../packing/ep/points3d/SimplePoint3D.java | 20 +- .../packing/points/BouwkampConverter.java | 27 +- .../points/DefaultExtremePoints2D.java | 13 +- .../points/DefaultExtremePoints3D.java | 11 +- .../packing/points2d/ExtremePoints2DTest.java | 142 ++++---- .../assertj/AbstractPoint2DAssert.java | 5 +- .../assertj/AbstractSimplePoint2DAssert.java | 4 +- .../points2d}/assertj/Point2DAssert.java | 4 +- .../points2d/assertj/SimplePoint2DAssert.java | 2 +- .../points2d/ui/DrawBouwkampPoints2D.java | 33 -- .../points2d/ui/DrawBouwkampPoints3D.java | 71 ---- .../packing/points2d/ui/DrawPoints2D.java | 313 ------------------ .../packing/points2d/ui/DrawPoints2DTest.java | 56 ---- .../packing/points2d/ui/DrawPoints3DTest.java | 77 ----- .../packing/points2d/ui/MainPanel.java | 154 --------- .../packing/points2d/ui/ZoomPane.java | 200 ----------- .../packing/points3d/ExtremePoints3DTest.java | 102 +++--- .../packing/jmh/ep/ExtremePoint2DEntry.java | 8 +- .../packing/jmh/ep/ExtremePoint3DEntry.java | 8 +- .../packing/jmh/ep/ExtremePoints2DState.java | 15 +- .../packing/jmh/ep/ExtremePoints3DState.java | 13 +- .../assertj/AbstractPlacement2DAssert.java | 236 ------------- .../assertj/AbstractPlacement3DAssert.java | 313 ------------------ .../assertj/AbstractStackPlacementAssert.java | 305 ++++++++++++++++- .../test/assertj/Placement2DAssert.java | 15 - .../test/assertj/Placement3DAssert.java | 15 - .../test/assertj/StackPlacementAssert.java | 15 + .../assertj/StackablePlacementAssert.java | 15 - ...faultPackagingResultVisualizerFactory.java | 5 +- .../packaging/BruteForcePackagerTest.java | 2 +- .../packaging/FastBruteForcePackagerTest.java | 2 +- 105 files changed, 1844 insertions(+), 2824 deletions(-) create mode 100644 api/src/main/java/com/github/skjolber/packing/api/AbstractStackScopeConstraintBuilder.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/ContainerLoadStackValue.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/ContainerLoadable.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraint.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraintBuilder.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/FixedOrderStackScopeConstraint.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/Placement2D.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/Placement3D.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/StackFactory.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/StackScope.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/StackableItemGroup.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/StackablePointFilter.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/StackableScopeFactory.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java delete mode 100644 api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/ep/StackablePoints.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackValue.java create mode 100644 api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackableItem.java delete mode 100644 core/src/main/java/com/github/skjolber/packing/packer/laff/StackValuePointFilter.java rename {api/src/main/java/com/github/skjolber/packing/api => core/src/main/java/com/github/skjolber/packing/packer/laff}/StackableFilter.java (67%) delete mode 100644 extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPlacement2D.java rename {api/src/main/java/com/github/skjolber/packing/api/ep => extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d}/Point2D.java (85%) delete mode 100644 extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPlacement3D.java rename {test/src/main/java/com/github/skjolber/packing/test => extreme-points/src/test/java/com/github/skjolber/packing/points2d}/assertj/AbstractPoint2DAssert.java (97%) rename {test/src/main/java/com/github/skjolber/packing/test => extreme-points/src/test/java/com/github/skjolber/packing/points2d}/assertj/Point2DAssert.java (73%) delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints2D.java delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints3D.java delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2D.java delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2DTest.java delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints3DTest.java delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/MainPanel.java delete mode 100644 extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/ZoomPane.java delete mode 100644 test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement2DAssert.java delete mode 100644 test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement3DAssert.java delete mode 100644 test/src/main/java/com/github/skjolber/packing/test/assertj/Placement2DAssert.java delete mode 100644 test/src/main/java/com/github/skjolber/packing/test/assertj/Placement3DAssert.java create mode 100644 test/src/main/java/com/github/skjolber/packing/test/assertj/StackPlacementAssert.java delete mode 100644 test/src/main/java/com/github/skjolber/packing/test/assertj/StackablePlacementAssert.java diff --git a/api/src/main/java/com/github/skjolber/packing/api/AbstractStackScopeConstraintBuilder.java b/api/src/main/java/com/github/skjolber/packing/api/AbstractStackScopeConstraintBuilder.java new file mode 100644 index 00000000..38f9d928 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/AbstractStackScopeConstraintBuilder.java @@ -0,0 +1,33 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +public abstract class AbstractStackScopeConstraintBuilder> { + + protected List stackables; + protected Container container; + protected ContainerStackValue containerStackValue; + protected Stack stack; + + public B withContainer(Container container) { + this.container = container; + return (B)this; + } + + public B withStack(Stack stack) { + this.stack = stack; + return (B)this; + } + + public B withContainerStackValue(ContainerStackValue containerStackValue) { + this.containerStackValue = containerStackValue; + return (B)this; + } + + public B withStackables(List stackables) { + this.stackables = stackables; + return (B)this; + } + + public abstract StackScopeConstraint build(); +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/Box.java b/api/src/main/java/com/github/skjolber/packing/api/Box.java index 325f8bdd..25c9cd14 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/Box.java +++ b/api/src/main/java/com/github/skjolber/packing/api/Box.java @@ -60,6 +60,10 @@ public Box(String id, String name, long volume, int weight, BoxStackValue[] stac this.minimumArea = getMinimumArea(stackValues); this.maximumArea = getMinimumArea(stackValues); + + for (BoxStackValue boxStackValue : stackValues) { + boxStackValue.setStackable(this); + } } @Override @@ -78,6 +82,10 @@ public long getVolume() { @Override public Box clone() { + BoxStackValue[] stackValues = new BoxStackValue[this.stackValues.length]; + for(int i = 0; i < stackValues.length; i++) { + stackValues[i] = this.stackValues[i].clone(); + } return new Box(id, description, volume, weight, stackValues); } diff --git a/api/src/main/java/com/github/skjolber/packing/api/BoxStackValue.java b/api/src/main/java/com/github/skjolber/packing/api/BoxStackValue.java index 16b1e64d..7610a829 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/BoxStackValue.java +++ b/api/src/main/java/com/github/skjolber/packing/api/BoxStackValue.java @@ -5,6 +5,8 @@ public class BoxStackValue extends StackValue { private static final long serialVersionUID = 1L; + + private Box stackable; public BoxStackValue(int dx, int dy, int dz, StackConstraint constraint, List surfaces) { super(dx, dy, dz, constraint, surfaces); @@ -12,11 +14,22 @@ public BoxStackValue(int dx, int dy, int dz, StackConstraint constraint, List stackValues) { + this.values = new ContainerLoadStackValue[stackValues.size()]; + this.stackable = stackable; + + long minVolumeLimit = Long.MAX_VALUE; + long minAreaLimit = Long.MAX_VALUE; + + for (int i = 0; i < values.length; i++) { + StackValue stackValue = stackValues.get(i); + + values[i] = new ContainerLoadStackValue(stackable, stackValue); + + if(minVolumeLimit > stackValue.getVolume()) { + minVolumeLimit = stackValue.getVolume(); + } + + if(minAreaLimit > stackValue.getArea()) { + minAreaLimit = stackValue.getArea(); + } + } + + this.minAreaLimit = minAreaLimit; + this.minVolumeLimit = minVolumeLimit; + } + + public ContainerLoadable(ContainerLoadable clone) { + // clone working object in order to improve performance + this.values = new ContainerLoadStackValue[clone.values.length]; + this.stackable = clone.stackable.clone(); + for (int i = 0; i < values.length; i++) { + ContainerLoadStackValue permutationRotation = clone.values[i]; + values[i] = new ContainerLoadStackValue(permutationRotation.getStackable().clone(), permutationRotation.getValue().clone()); + + } + this.minAreaLimit = clone.minAreaLimit; + this.minVolumeLimit = clone.minVolumeLimit; + + } + + public ContainerLoadStackValue[] getBoxes() { + return values; + } + + public long getMinAreaLimit() { + return minAreaLimit; + } + + public long getMinVolumeLimit() { + return minVolumeLimit; + } + + public Stackable getStackable() { + return stackable; + } + + public ContainerLoadable clone() { + return new ContainerLoadable(this); + } +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/ContainerStackValue.java b/api/src/main/java/com/github/skjolber/packing/api/ContainerStackValue.java index 9af5c479..047f0919 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/ContainerStackValue.java +++ b/api/src/main/java/com/github/skjolber/packing/api/ContainerStackValue.java @@ -6,6 +6,15 @@ public abstract class ContainerStackValue extends StackValue { private static final long serialVersionUID = 1L; + private Container stackable; + + protected final int loadDx; // x + protected final int loadDy; // y + protected final int loadDz; // z + + protected final int maxLoadWeight; + protected final long maxLoadVolume; + public ContainerStackValue( int dx, int dy, int dz, StackConstraint constraint, @@ -19,14 +28,7 @@ public ContainerStackValue( this.maxLoadVolume = (long)loadDx * (long)loadDy * (long)loadDz; this.maxLoadWeight = maxLoadWeight; } - - protected final int loadDx; // x - protected final int loadDy; // y - protected final int loadDz; // z - - protected final int maxLoadWeight; - protected final long maxLoadVolume; - + protected ContainerStackValue(ContainerStackValue other) { super(other); @@ -36,6 +38,8 @@ protected ContainerStackValue(ContainerStackValue other) { this.maxLoadVolume = other.maxLoadVolume; this.maxLoadWeight = other.maxLoadWeight; + + this.stackable = other.stackable; } public long getMaxLoadVolume() { @@ -78,5 +82,17 @@ protected boolean canLoad(Stackable stackable) { public String toString() { return "ContainerStackValue [" + dx + "x" + dy + "x" + dz + " " + loadDx + "x" + loadDy + "x" + loadDz + "]"; } + + public void setStackable(Container stackable) { + this.stackable = stackable; + } + + @Override + public Container getStackable() { + return stackable; + } + + @Override + public abstract ContainerStackValue clone(); } diff --git a/api/src/main/java/com/github/skjolber/packing/api/DefaultContainer.java b/api/src/main/java/com/github/skjolber/packing/api/DefaultContainer.java index 38929563..32f97f9e 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/DefaultContainer.java +++ b/api/src/main/java/com/github/skjolber/packing/api/DefaultContainer.java @@ -14,6 +14,10 @@ public DefaultContainer(String id, String description, long volume, int emptyWei this.stackValues = stackValues; this.stack = stack; + + for (ContainerStackValue stackValue : stackValues) { + stackValue.setStackable(this); + } } @Override @@ -28,6 +32,10 @@ public Stack getStack() { @Override public DefaultContainer clone() { + ContainerStackValue[] stackValues = new ContainerStackValue[this.stackValues.length]; + for(int i = 0; i < stackValues.length; i++) { + stackValues[i] = this.stackValues[i].clone(); + } return new DefaultContainer(id, description, volume, emptyWeight, stackValues, new DefaultStack()); } diff --git a/api/src/main/java/com/github/skjolber/packing/api/DefaultContainerStackValue.java b/api/src/main/java/com/github/skjolber/packing/api/DefaultContainerStackValue.java index 17832d3c..e585c7c2 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/DefaultContainerStackValue.java +++ b/api/src/main/java/com/github/skjolber/packing/api/DefaultContainerStackValue.java @@ -5,7 +5,7 @@ public class DefaultContainerStackValue extends ContainerStackValue { private static final long serialVersionUID = 1L; - + public DefaultContainerStackValue( int dx, int dy, int dz, StackConstraint constraint, diff --git a/api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraint.java b/api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraint.java new file mode 100644 index 00000000..11e4d94a --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraint.java @@ -0,0 +1,29 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +public class DefaultStackScopeConstraint implements StackScopeConstraint { + + protected final List stackables; + protected final Container container; + protected final ContainerStackValue containerStackValue; + protected final Stack stack; + + public DefaultStackScopeConstraint(List stackables, Container container, ContainerStackValue containerStackValue, Stack stack) { + this.stackables = stackables; + this.container = container; + this.containerStackValue = containerStackValue; + this.stack = stack; + } + + @Override + public List getStackScope() { + return stackables; + } + + @Override + public void stacked(int index) { + stackables.remove(index); + } + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraintBuilder.java b/api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraintBuilder.java new file mode 100644 index 00000000..c2a28df1 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/DefaultStackScopeConstraintBuilder.java @@ -0,0 +1,10 @@ +package com.github.skjolber.packing.api; + +public class DefaultStackScopeConstraintBuilder extends AbstractStackScopeConstraintBuilder { + + @Override + public StackScopeConstraint build() { + return new DefaultStackScopeConstraint(stackables, container, containerStackValue, stack); + } + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/FixedOrderStackScopeConstraint.java b/api/src/main/java/com/github/skjolber/packing/api/FixedOrderStackScopeConstraint.java new file mode 100644 index 00000000..1cfb9583 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/FixedOrderStackScopeConstraint.java @@ -0,0 +1,11 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +public interface FixedOrderStackScopeConstraint { + + List getStackScope(); + + void stacked(int index); + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java b/api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java deleted file mode 100644 index 59c3dd48..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/HorizontalSupport.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.skjolber.packing.api; - -import java.io.Serializable; - -public class HorizontalSupport implements Serializable { - - private static final long serialVersionUID = 1L; - - private final SupportPlacement3D negative; - private final SupportPlacement3D positive; - - private final long area; - - public HorizontalSupport(SupportPlacement3D negative, SupportPlacement3D positive, long area) { - super(); - this.negative = negative; - this.positive = positive; - this.area = area; - } - - public SupportPlacement3D getNegative() { - return negative; - } - - public SupportPlacement3D getPositive() { - return positive; - } - - public long getArea() { - return area; - } - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/Placement2D.java b/api/src/main/java/com/github/skjolber/packing/api/Placement2D.java deleted file mode 100644 index f9a194fa..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/Placement2D.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.github.skjolber.packing.api; - -public interface Placement2D { - - int getAbsoluteX(); - - int getAbsoluteY(); - - int getAbsoluteEndX(); - - int getAbsoluteEndY(); - - boolean intersects2D(Placement2D point); -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/Placement3D.java b/api/src/main/java/com/github/skjolber/packing/api/Placement3D.java deleted file mode 100644 index e680da18..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/Placement3D.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.github.skjolber.packing.api; - -public interface Placement3D extends Placement2D { - - int getAbsoluteZ(); - - int getAbsoluteEndZ(); - - boolean intersects3D(Placement3D point); - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackFactory.java b/api/src/main/java/com/github/skjolber/packing/api/StackFactory.java new file mode 100644 index 00000000..331c5513 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/StackFactory.java @@ -0,0 +1,6 @@ +package com.github.skjolber.packing.api; + +public abstract class StackFactory { + + public abstract Stack build(); +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackPlacement.java b/api/src/main/java/com/github/skjolber/packing/api/StackPlacement.java index 8c28026a..41867832 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/StackPlacement.java +++ b/api/src/main/java/com/github/skjolber/packing/api/StackPlacement.java @@ -2,7 +2,7 @@ import java.io.Serializable; -public class StackPlacement implements Placement3D, Serializable { +public class StackPlacement implements Serializable { private static final long serialVersionUID = 1L; @@ -109,19 +109,18 @@ public long getVolume() { return stackable.getVolume(); } - public boolean intersects2D(Placement2D point) { + public boolean intersects2D(StackPlacement point) { return !(point.getAbsoluteEndX() < x || point.getAbsoluteX() > getAbsoluteEndX() || point.getAbsoluteEndY() < y || point.getAbsoluteY() > getAbsoluteEndY()); } - @Override - public boolean intersects3D(Placement3D point) { + public boolean intersects3D(StackPlacement point) { return !(point.getAbsoluteEndX() < x || point.getAbsoluteX() > getAbsoluteEndX() || point.getAbsoluteEndY() < y || point.getAbsoluteY() > point.getAbsoluteEndY() || point.getAbsoluteEndZ() < z || point.getAbsoluteZ() > point.getAbsoluteEndZ()); } @Override public String toString() { - return stackable.getDescription() + "[" + x + "x" + y + "x" + z + " " + getAbsoluteEndX() + "x" + getAbsoluteEndY() + "x" + getAbsoluteEndZ() + "]"; + return (stackable != null ? stackable.getDescription() : "") + "[" + x + "x" + y + "x" + z + " " + getAbsoluteEndX() + "x" + getAbsoluteEndY() + "x" + getAbsoluteEndZ() + "]"; } public void setX(int x) { diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackScope.java b/api/src/main/java/com/github/skjolber/packing/api/StackScope.java new file mode 100644 index 00000000..9cffc10c --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/StackScope.java @@ -0,0 +1,10 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +public interface StackScope { + + List getStackables(); + + void stacked(int index); +} \ No newline at end of file diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackValue.java b/api/src/main/java/com/github/skjolber/packing/api/StackValue.java index db6a9e75..5ce21b98 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/StackValue.java +++ b/api/src/main/java/com/github/skjolber/packing/api/StackValue.java @@ -24,7 +24,7 @@ public abstract class StackValue implements Serializable { protected final List surfaces; protected long volume; - + public StackValue(int dx, int dy, int dz, StackConstraint constraint, List surfaces) { this.dx = dx; this.dy = dy; @@ -101,5 +101,7 @@ public String toString() { @Override public abstract StackValue clone(); + + public abstract Stackable getStackable(); } diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackableItemGroup.java b/api/src/main/java/com/github/skjolber/packing/api/StackableItemGroup.java new file mode 100644 index 00000000..7fb7fd44 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/StackableItemGroup.java @@ -0,0 +1,32 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +/** + * + * Items which belong together, for example different parts of a single product or order. + * + */ + +public class StackableItemGroup { + + private String id; + + private List items; + + public String getId() { + return id; + } + + public List getItems() { + return items; + } + + public void setId(String id) { + this.id = id; + } + + public void setItems(List items) { + this.items = items; + } +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackablePointFilter.java b/api/src/main/java/com/github/skjolber/packing/api/StackablePointFilter.java new file mode 100644 index 00000000..ea583464 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/StackablePointFilter.java @@ -0,0 +1,16 @@ +package com.github.skjolber.packing.api; + +import java.util.List; + +import com.github.skjolber.packing.api.ep.Point3D; + +/** + * Constraint describing where a box can be placed within a stack. + * For example, a flammable item must be stacked by the door. + */ + +public interface StackablePointFilter { + + List filterPoints(List points); + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackableScopeFactory.java b/api/src/main/java/com/github/skjolber/packing/api/StackableScopeFactory.java new file mode 100644 index 00000000..9f3c6241 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/StackableScopeFactory.java @@ -0,0 +1,5 @@ +package com.github.skjolber.packing.api; + +public class StackableScopeFactory { + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java b/api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java deleted file mode 100644 index 2cf5eee0..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/SupportPlacement3D.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.github.skjolber.packing.api; - -import java.util.List; - -import com.github.skjolber.packing.api.Surface.Label; - -public interface SupportPlacement3D extends Placement3D { - - List getBottomSupports(); - - List getTopSupports(); - - List getLeftSupports(); - - List getRightSupports(); - - List getFrontSupports(); - - List getRearSupports(); - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java b/api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java deleted file mode 100644 index 1ad18cc9..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/SupportStackPlacement.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.github.skjolber.packing.api; - -import java.util.List; - -public class SupportStackPlacement extends StackPlacement implements SupportPlacement3D { - - private static final long serialVersionUID = 1L; - - protected List bottomSupports; - - protected List topSupports; - - protected List leftSupports; - - protected List rightSupports; - - protected List frontSupports; - - protected List rearSupports; - - public SupportStackPlacement() { - super(); - } - - public SupportStackPlacement(Stackable stackable, StackValue value, int x, int y, int z) { - super(stackable, value, x, y, z); - } - - @Override - public List getBottomSupports() { - return bottomSupports; - } - - @Override - public List getTopSupports() { - return topSupports; - } - - @Override - public List getLeftSupports() { - return leftSupports; - } - - @Override - public List getRightSupports() { - return rightSupports; - } - - @Override - public List getFrontSupports() { - return frontSupports; - } - - @Override - public List getRearSupports() { - return rearSupports; - } - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java b/api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java deleted file mode 100644 index 3cfaf4c4..00000000 --- a/api/src/main/java/com/github/skjolber/packing/api/VerticalSupport.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.github.skjolber.packing.api; - -import java.io.Serializable; - -public class VerticalSupport implements Serializable { - - private static final long serialVersionUID = 1L; - - private final SupportPlacement3D negative; - private final SupportPlacement3D positive; - - private final long area; - - private int weightLimit; - - public VerticalSupport(SupportPlacement3D negative, SupportPlacement3D positive, long area, int weightLimit) { - super(); - this.negative = negative; - this.positive = positive; - this.area = area; - this.weightLimit = weightLimit; - } - - public SupportPlacement3D getNegative() { - return negative; - } - - public SupportPlacement3D getPositive() { - return positive; - } - - public long getArea() { - return area; - } - - public void decrementWeightLimit(int weightLimit) { - this.weightLimit -= weightLimit; - } - - public int getWeightLimit() { - return weightLimit; - } - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/ep/ExtremePoints.java b/api/src/main/java/com/github/skjolber/packing/api/ep/ExtremePoints.java index 48e77746..9b838ed6 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/ep/ExtremePoints.java +++ b/api/src/main/java/com/github/skjolber/packing/api/ep/ExtremePoints.java @@ -1,21 +1,22 @@ package com.github.skjolber.packing.api.ep; -import java.io.Serializable; import java.util.List; -import com.github.skjolber.packing.api.Placement2D; +import com.github.skjolber.packing.api.StackPlacement; -public interface ExtremePoints

> { +public interface ExtremePoints { - boolean add(int index, P placement); + boolean add(int index, StackPlacement placement); - Point getValue(int i); + Point3D getValue(int i); - List getValues(); + List getValues(); int getValueCount(); void reset(int dx, int dy, int dz); void redo(); + + List getPlacements(); } diff --git a/api/src/main/java/com/github/skjolber/packing/api/ep/Point3D.java b/api/src/main/java/com/github/skjolber/packing/api/ep/Point3D.java index 4f0b34b0..a88224d4 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/ep/Point3D.java +++ b/api/src/main/java/com/github/skjolber/packing/api/ep/Point3D.java @@ -2,17 +2,17 @@ import java.util.Comparator; -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.StackValue; -public abstract class Point3D

extends Point2D

{ +public abstract class Point3D { private static final long serialVersionUID = 1L; - public static final Comparator> X_COMPARATOR = new Comparator>() { + public static final Comparator X_COMPARATOR = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minX < o2.minX) { return -1; } else if(o1.minX != o2.minX) { @@ -22,10 +22,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> Y_COMPARATOR = new Comparator>() { + public static final Comparator Y_COMPARATOR = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minY < o2.minY) { return -1; } else if(o1.minY != o2.minY) { @@ -36,10 +36,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> Z_COMPARATOR = new Comparator>() { + public static final Comparator Z_COMPARATOR = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minZ < o2.minZ) { return -1; } else if(o1.minZ != o2.minZ) { @@ -50,10 +50,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> COMPARATOR_X_THEN_Y_THEN_Z = new Comparator>() { + public static final Comparator COMPARATOR_X_THEN_Y_THEN_Z = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minX < o2.minX) { return -1; @@ -89,10 +89,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> COMPARATOR_X_THEN_Y = new Comparator>() { + public static final Comparator COMPARATOR_X_THEN_Y = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minX < o2.minX) { return -1; } else if(o1.minX != o2.minX) { @@ -109,10 +109,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> COMPARATOR_Y_THEN_Z_THEN_X = new Comparator>() { + public static final Comparator COMPARATOR_Y_THEN_Z_THEN_X = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minY < o2.minY) { return -1; } else if(o1.minY != o2.minY) { @@ -147,10 +147,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> COMPARATOR_Z_THEN_X_THEN_Y = new Comparator>() { + public static final Comparator COMPARATOR_Z_THEN_X_THEN_Y = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { if(o1.minZ < o2.minZ) { return -1; } else if(o1.minZ != o2.minZ) { @@ -185,10 +185,10 @@ public int compare(Point3D o1, Point3D o2) { } }; - public static final Comparator> COMPARATOR = new Comparator>() { + public static final Comparator COMPARATOR = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { int compare = X_COMPARATOR.compare(o1, o2); if(compare != 0) { return compare; @@ -202,13 +202,35 @@ public int compare(Point3D o1, Point3D o2) { return Z_COMPARATOR.compare(o1, o2); } }; + + protected final int minX; + protected final int minY; + + protected int maxY; + protected int maxX; + + protected int dx; + protected int dy; + + protected long area; + protected long volume; protected final int minZ; protected int maxZ; protected int dz; public Point3D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ) { - super(minX, minY, maxX, maxY); + + this.minX = minX; + this.minY = minY; + this.maxY = maxY; + this.maxX = maxX; + + this.dx = maxX - minX + 1; + this.dy = maxY - minY + 1; + + calculateArea(); + /* if(maxZ < minZ) { throw new IllegalArgumentException("Z: "+ maxZ + " < " + minZ); @@ -232,15 +254,27 @@ public void setMaxZ(int maxZ) { calculateVolume(); } - @Override public void setMaxX(int maxX) { - super.setMaxX(maxX); + if(maxX < 0) { + throw new RuntimeException("Cannot set max x to " + maxX + " for " + minX + "x" + minY); + } + this.maxX = maxX; + + this.dx = maxX - minX + 1; + + calculateArea(); calculateVolume(); } - @Override public void setMaxY(int maxY) { - super.setMaxY(maxY); + if(maxY < 0) { + throw new RuntimeException("Cannot set max y to " + maxY + " for " + minX + "x" + minY); + } + this.maxY = maxY; + + this.dy = maxY - minY + 1; + + calculateArea(); calculateVolume(); } @@ -255,6 +289,14 @@ public boolean isWithin(int dx, int dy, int dz) { public int getDz() { return dz; } + + public int getDy() { + return dy; + } + + public int getDx() { + return dx; + } public int getMaxZ() { return maxZ; @@ -264,11 +306,11 @@ public int getMinZ() { return minZ; } - public boolean intersects(P p) { + public boolean intersects(StackPlacement p) { return !(p.getAbsoluteEndX() < minX || p.getAbsoluteX() > maxX || p.getAbsoluteEndY() < minY || p.getAbsoluteY() > maxY || p.getAbsoluteEndZ() < minZ || p.getAbsoluteZ() > maxZ); } - public boolean intersects(Point3D point) { + public boolean intersects(Point3D point) { return !(point.getMaxX() < minX || point.getMinX() > maxX || point.getMaxY() < minY || point.getMinY() > maxY || point.getMaxZ() < minZ || point.getMinZ() > maxZ); } @@ -308,64 +350,64 @@ public boolean swallowsMinZ(int min, int max) { return min <= minZ && minZ <= max; } - public abstract Point3D

clone(int maxX, int maxY, int maxZ); - - @Override - public Point2D

clone(int maxX, int maxY) { - return clone(maxX, maxY, this.maxZ); + private void calculateArea() { + this.area = (long)dx * (long)dy; } - public boolean containsInYZPlane(Point3D

point) { + + public abstract Point3D clone(int maxX, int maxY, int maxZ); + + public boolean containsInYZPlane(Point3D point) { if(point.getMinX() == minX) { return point.swallowsMinY(minY, maxY) && point.swallowsMinZ(minZ, maxZ); } return false; } - public boolean containsInXYPlane(Point3D

point) { + public boolean containsInXYPlane(Point3D point) { if(point.getMinZ() == minZ) { return point.swallowsMinY(minY, maxY) && point.swallowsMinX(minX, maxX); } return false; } - public boolean containsInXZPlane(Point3D

point) { + public boolean containsInXZPlane(Point3D point) { if(point.getMinY() == minY) { return point.swallowsMinZ(minZ, maxZ) && point.swallowsMinX(minX, maxX); } return false; } - public boolean isInXZPlane(P point) { + public boolean isInXZPlane(StackPlacement point) { if(point.getAbsoluteY() == minY) { return fitsInXZPlane(point); } return false; } - public boolean isInXYPlane(P point) { + public boolean isInXYPlane(StackPlacement point) { if(point.getAbsoluteZ() == minZ) { return fitsInXYPlane(point); } return false; } - public boolean isInYZPlane(P point) { + public boolean isInYZPlane(StackPlacement point) { if(point.getAbsoluteX() == minX) { return fitsInYZPlane(point); } return false; } - public boolean fitsInXZPlane(P point) { + public boolean fitsInXZPlane(StackPlacement point) { return swallowsMinZ(point.getAbsoluteZ(), point.getAbsoluteEndZ()) && swallowsMinX(point.getAbsoluteX(), point.getAbsoluteEndX()); } - public boolean fitsInXYPlane(P point) { + public boolean fitsInXYPlane(StackPlacement point) { return swallowsMinY(point.getAbsoluteY(), point.getAbsoluteEndY()) && swallowsMinX(point.getAbsoluteX(), point.getAbsoluteEndX()); } - public boolean fitsInYZPlane(P point) { + public boolean fitsInYZPlane(StackPlacement point) { return swallowsMinZ(point.getAbsoluteZ(), point.getAbsoluteEndZ()) && swallowsMinY(point.getAbsoluteY(), point.getAbsoluteEndY()); } @@ -373,7 +415,7 @@ public boolean fits3D(StackValue stackValue) { return !(stackValue.getDx() > dx || stackValue.getDy() > dy || stackValue.getDz() > dz); } - public boolean isMax(Point3D

existing) { + public boolean isMax(Point3D existing) { return maxY == existing.getMaxY() && maxX == existing.getMaxX() && maxZ == existing.getMaxZ(); } @@ -387,7 +429,7 @@ public long getVolume() { return volume; } - public boolean eclipses(Point3D

point) { + public boolean eclipses(Point3D point) { return minX <= point.getMinX() && minY <= point.getMinY() && minZ <= point.getMinZ() && @@ -396,31 +438,31 @@ public boolean eclipses(Point3D

point) { point.getMaxZ() <= maxZ; } - public boolean eclipsesX(Point2D

point) { + public boolean eclipsesX(Point3D point) { return minX <= point.getMinX() && point.getMaxX() <= maxX; } - public boolean eclipsesY(Point2D

point) { + public boolean eclipsesY(Point3D point) { return minY <= point.getMinY() && point.getMaxY() <= maxY; } - public boolean eclipsesZ(Point3D

point) { + public boolean eclipsesZ(Point3D point) { return minZ <= point.getMinZ() && point.getMaxZ() <= maxZ; } - public boolean eclipsesMovedX(Point3D

point, int x) { + public boolean eclipsesMovedX(Point3D point, int x) { return minX <= x && point.getMaxX() <= maxX && eclipsesY(point) && eclipsesZ(point); } - public boolean eclipsesMovedY(Point3D

point, int y) { + public boolean eclipsesMovedY(Point3D point, int y) { return minY <= y && point.getMaxY() <= maxY && eclipsesX(point) && eclipsesZ(point); } - public boolean eclipsesMovedZ(Point3D

point, int z) { + public boolean eclipsesMovedZ(Point3D point, int z) { return minZ <= z && point.getMaxZ() <= maxZ && eclipsesX(point) && eclipsesY(point); } - public abstract Point3D

rotate(); + public abstract Point3D rotate(); public long getVolumeAtZ(int zz) { return (long)dx * (long)dy * (maxZ - zz + 1); @@ -430,5 +472,53 @@ public long getVolumeAtMaxZ(int maxZ) { return (long)dx * (long)dy * (maxZ - minZ + 1); } + public int getMinX() { + return minX; + } + + public int getMinY() { + return minY; + } + + /** + * + * Get y constraint (inclusive) + * + * @return max y + */ + + public int getMaxY() { + return maxY; + } + /** + * + * Get x constraint (inclusive) + * + * @return max x + */ + + public int getMaxX() { + return maxX; + } + + public long getArea() { + return area; + } + + public long getAreaAtX(int xx) { + return dy * (long)(maxX - xx + 1); + } + + public long getAreaAtY(int yy) { + return dx * (long)(maxY - yy + 1); + } + + public long getAreaAtMaxX(int maxX) { + return dy * (long)(maxX - minX + 1); + } + + public long getAreaAtMaxY(int maxY) { + return dx * (long)(maxY - minY + 1); + } } diff --git a/api/src/main/java/com/github/skjolber/packing/api/ep/StackablePoints.java b/api/src/main/java/com/github/skjolber/packing/api/ep/StackablePoints.java new file mode 100644 index 00000000..b734a635 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/ep/StackablePoints.java @@ -0,0 +1,12 @@ +package com.github.skjolber.packing.api.ep; + +import java.io.Serializable; +import java.util.List; + +import com.github.skjolber.packing.api.StackPlacement; + +public interface StackablePoints { + + List getStackablePoints(); + List getPlacements(); +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackValue.java b/api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackValue.java new file mode 100644 index 00000000..8753c290 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackValue.java @@ -0,0 +1,31 @@ +package com.github.skjolber.packing.api.packager; + +import com.github.skjolber.packing.api.StackValue; +import com.github.skjolber.packing.api.Stackable; + +/** + * + * A {@linkplain Stackable} in a specific {@linkplain StackValue} with certain dimensions. + * + */ + +public class EnclosedStackValue { + + private final Stackable stackable; + private final StackValue value; + + public EnclosedStackValue(Stackable stackable, StackValue value) { + super(); + this.stackable = stackable; + this.value = value; + } + + public Stackable getStackable() { + return stackable; + } + + public StackValue getValue() { + return value; + } + +} diff --git a/api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackableItem.java b/api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackableItem.java new file mode 100644 index 00000000..b56e79c7 --- /dev/null +++ b/api/src/main/java/com/github/skjolber/packing/api/packager/EnclosedStackableItem.java @@ -0,0 +1,72 @@ +package com.github.skjolber.packing.api.packager; + +import java.util.List; + +import com.github.skjolber.packing.api.StackValue; +import com.github.skjolber.packing.api.Stackable; + +/** + * + * Stackable item which fit within certain bounds, i.e. load dimensions of a container. + * + */ + + +public class EnclosedStackableItem { + + protected final List values; + protected final Stackable stackable; + + private int count; + + protected final long minVolumeLimit; + protected final long minAreaLimit; + + public EnclosedStackableItem(Stackable stackable, List stackValues, int count) { + this.values = stackValues; + this.stackable = stackable; + this.count = count; + + long minVolumeLimit = Long.MAX_VALUE; + long minAreaLimit = Long.MAX_VALUE; + + for (int i = 0; i < values.size(); i++) { + StackValue stackValue = values.get(i); + + if(minVolumeLimit > stackValue.getVolume()) { + minVolumeLimit = stackValue.getVolume(); + } + + if(minAreaLimit > stackValue.getArea()) { + minAreaLimit = stackValue.getArea(); + } + } + + this.minAreaLimit = minAreaLimit; + this.minVolumeLimit = minVolumeLimit; + } + + public List getValues() { + return values; + } + + public long getMinAreaLimit() { + return minAreaLimit; + } + + public long getMinVolumeLimit() { + return minVolumeLimit; + } + + public Stackable getStackable() { + return stackable; + } + + public int getCount() { + return count; + } + + public void decrement() { + count--; + } +} diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java index 853c50b4..ffb9fae3 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/AbstractBruteForcePackager.java @@ -77,7 +77,7 @@ public BruteForcePackagerResult pack(ExtremePoints3DStack extremePoints, List> points = packStackPlacement(extremePoints, stackPlacements, iterator, stack, interrupt, minStackableAreaIndex); + List points = packStackPlacement(extremePoints, stackPlacements, iterator, stack, interrupt, minStackableAreaIndex); if(points == null) { return null; // timeout } @@ -131,7 +131,7 @@ public BruteForcePackagerResult pack(ExtremePoints3DStack extremePoints, List> packStackPlacement(ExtremePoints3DStack extremePoints, List placements, PermutationRotationIterator iterator, Stack stack, + public List packStackPlacement(ExtremePoints3DStack extremePoints, List placements, PermutationRotationIterator iterator, Stack stack, PackagerInterruptSupplier interrupt, int minStackableAreaIndex) { if(placements.isEmpty()) { return Collections.emptyList(); @@ -154,10 +154,19 @@ public List> packStackPlacement(ExtremePoints3DStack ext } } - private List> packStackPlacement(ExtremePoints3DStack extremePointsStack, List placements, PermutationRotationIterator rotator, Stack stack, - int maxLoadWeight, int placementIndex, PackagerInterruptSupplier interrupt, StackConstraint constraint, int minStackableAreaIndex, + private List packStackPlacement( + ExtremePoints3DStack extremePointsStack, + List placements, + PermutationRotationIterator rotator, + Stack stack, + int maxLoadWeight, + int placementIndex, + PackagerInterruptSupplier interrupt, + StackConstraint constraint, + int minStackableAreaIndex, // optimize: pass best along so that we do not need to get points to known whether extracting the points is necessary - List> best) { + List best + ) { if(interrupt.getAsBoolean()) { // fit2d below might have returned due to deadline return null; @@ -191,7 +200,7 @@ private List> packStackPlacement(ExtremePoints3DStack ex int currentPointsCount = extremePointsStack.getValueCount(); for (int k = 0; k < currentPointsCount; k++) { - Point3D point3d = extremePointsStack.getValue(k); + Point3D point3d = extremePointsStack.getValue(k); if(!point3d.fits3D(stackValue)) { continue; @@ -228,7 +237,7 @@ private List> packStackPlacement(ExtremePoints3DStack ex nextMinStackableAreaIndex = minStackableAreaIndex; } - List> points = packStackPlacement(extremePointsStack, placements, rotator, stack, maxLoadWeight, placementIndex + 1, interrupt, constraint, + List points = packStackPlacement(extremePointsStack, placements, rotator, stack, maxLoadWeight, placementIndex + 1, interrupt, constraint, nextMinStackableAreaIndex, best); stack.remove(placement); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResult.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResult.java index 14a98c35..1a08c529 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResult.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerResult.java @@ -28,7 +28,7 @@ public class BruteForcePackagerResult implements PackResult { // state private PermutationRotationState state; - private List> points = Collections.emptyList(); + private List points = Collections.emptyList(); private List placements = Collections.emptyList(); private boolean dirty = true; @@ -73,7 +73,7 @@ public Container getContainer() { stackPlacement.setValue(permutationRotation.getValue()); stackPlacement.setStackable(permutationRotation.getStackable()); - Point3D point3d = points.get(i); + Point3D point3d = points.get(i); stackPlacement.setX(point3d.getMinX()); stackPlacement.setY(point3d.getMinY()); stackPlacement.setZ(point3d.getMinZ()); @@ -88,7 +88,7 @@ public PermutationRotationState getPermutationRotationIteratorForState() { return state; } - public void setState(List> items, PermutationRotationState state, List placements) { + public void setState(List items, PermutationRotationState state, List placements) { this.points = items; this.state = state; this.placements = placements; diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ExtremePoints3DStack.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ExtremePoints3DStack.java index 3de7fb36..31f6ccf4 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ExtremePoints3DStack.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/ExtremePoints3DStack.java @@ -8,14 +8,14 @@ import com.github.skjolber.packing.ep.points3d.ExtremePoints3D; import com.github.skjolber.packing.ep.points3d.Point3DFlagList; -public class ExtremePoints3DStack extends ExtremePoints3D { +public class ExtremePoints3DStack extends ExtremePoints3D { protected static class StackItem { - protected Point3DFlagList values = new Point3DFlagList<>(); - protected Point3DFlagList otherValues = new Point3DFlagList<>(); + protected Point3DFlagList values = new Point3DFlagList(); + protected Point3DFlagList otherValues = new Point3DFlagList(); protected ArrayList placements = new ArrayList<>(); protected StackPlacement stackPlacement = new StackPlacement(); - protected Point3D point; + protected Point3D point; protected long minVolumeLimit; protected long minAreaLimit; } @@ -103,9 +103,9 @@ private void loadCurrent() { this.minVolumeLimit = stackItem.minVolumeLimit; } - public List> getPoints() { + public List getPoints() { // item 0 is always empty - List> list = new ArrayList<>(stackIndex + 1); + List list = new ArrayList<>(stackIndex + 1); for (int i = 1; i < stackIndex + 1; i++) { StackItem stackItem = stackItems.get(i); list.add(stackItem.point); @@ -138,7 +138,7 @@ public void reset(int dx, int dy, int dz) { } @Override - protected void saveValues(Point3DFlagList values, Point3DFlagList otherValues) { + protected void saveValues(Point3DFlagList values, Point3DFlagList otherValues) { // override because of the way the stack works, super.saveValues(values, otherValues); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java index 9d577a7f..6e7fc827 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackager.java @@ -345,7 +345,7 @@ public int packStackPlacement(FastExtremePoints3DStack extremePoints3D, List point3d = extremePoints3D.getValue(k); + Point3D point3d = extremePoints3D.getValue(k); if(!point3d.fits3D(stackValue)) { continue; } @@ -354,7 +354,7 @@ public int packStackPlacement(FastExtremePoints3DStack extremePoints3D, List bestPoint = extremePoints3D.getValue(bestPointIndex); + Point3D bestPoint = extremePoints3D.getValue(bestPointIndex); if(bestPoint.getArea() < point3d.getArea()) { continue; } else if(bestPoint.getArea() == point3d.getArea() && bestPoint.getVolume() < point3d.getVolume()) { @@ -368,7 +368,7 @@ public int packStackPlacement(FastExtremePoints3DStack extremePoints3D, List point3d = extremePoints3D.getValue(bestPointIndex); + Point3D point3d = extremePoints3D.getValue(bestPointIndex); placement.setStackable(stackable); placement.setStackValue(stackValue); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastExtremePoints3DStack.java b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastExtremePoints3DStack.java index baf3d0f3..45688b06 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastExtremePoints3DStack.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/bruteforce/FastExtremePoints3DStack.java @@ -4,43 +4,42 @@ import java.util.ArrayList; import java.util.List; -import com.github.skjolber.packing.api.Placement3D; import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; import com.github.skjolber.packing.ep.points3d.ExtremePoints3D; import com.github.skjolber.packing.ep.points3d.Point3DFlagList; -public class FastExtremePoints3DStack extends ExtremePoints3D { +public class FastExtremePoints3DStack extends ExtremePoints3D { - private static class StackItem

{ + private static class StackItem { // value for extraction - protected Point3D point; + protected Point3D point; // adding a point might affect any index in the values array - protected Point3DFlagList

values = new Point3DFlagList<>(); + protected Point3DFlagList values = new Point3DFlagList(); protected long minVolumeLimit; protected long minAreaLimit; } private int stackSize = 0; - private List> stackItems; + private List stackItems; public FastExtremePoints3DStack(int dx, int dy, int dz, int capacity) { super(dx, dy, dz, true); - stackItems = new ArrayList>(capacity); + stackItems = new ArrayList(capacity); for (int i = 0; i < capacity; i++) { - stackItems.add(new StackItem()); + stackItems.add(new StackItem()); } } @Override public boolean add(int index, StackPlacement placement) { // copy state before it is updated - Point3D point3d = values.get(index); + Point3D point3d = values.get(index); - StackItem stackItem = stackItems.get(stackSize); + StackItem stackItem = stackItems.get(stackSize); stackItem.point = point3d; stackItem.minVolumeLimit = minVolumeLimit; stackItem.minAreaLimit = minAreaLimit; @@ -51,8 +50,8 @@ public boolean add(int index, StackPlacement placement) { return super.add(index, placement); } - public List> getPoints() { - List> results = new ArrayList>(stackSize); + public List getPoints() { + List results = new ArrayList(stackSize); for (int i = 0; i < stackSize; i++) { results.add(stackItems.get(i).point); } @@ -79,7 +78,7 @@ public void setStackSize(int size) { } private void reload() { - StackItem stackItem = stackItems.get(stackSize); + StackItem stackItem = stackItems.get(stackSize); stackItem.values.copyInto(values); minVolumeLimit = stackItem.minVolumeLimit; minAreaLimit = stackItem.minAreaLimit; diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java index 54268a87..36f4037f 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/AbstractLargestAreaFitFirstPackager.java @@ -9,11 +9,8 @@ import com.github.skjolber.packing.api.ContainerItem; import com.github.skjolber.packing.api.PackResultComparator; import com.github.skjolber.packing.api.Stack; -import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.Stackable; -import com.github.skjolber.packing.api.StackableFilter; import com.github.skjolber.packing.api.StackableItem; -import com.github.skjolber.packing.api.ep.Point2D; import com.github.skjolber.packing.deadline.PackagerInterruptSupplier; import com.github.skjolber.packing.packer.AbstractPackager; import com.github.skjolber.packing.packer.AbstractPackagerAdapter; @@ -25,7 +22,7 @@ *
* Thread-safe implementation. The input Boxes must however only be used in a single thread at a time. */ -public abstract class AbstractLargestAreaFitFirstPackager

> extends AbstractPackager { +public abstract class AbstractLargestAreaFitFirstPackager extends AbstractPackager { public static StackableFilter FIRST_STACKABLE_FILTER = (best, candidate) -> { // return true if the candidate might be better than the current best @@ -35,39 +32,7 @@ public abstract class AbstractLargestAreaFitFirstPackager

{ // return true if the candidate might be better than the current best return candidate.getVolume() >= best.getVolume(); - }; - - public static StackValuePointFilter DEFAULT_STACK_VALUE_POINT_FILTER = (stackable1, point1, stackValue1, stackable2, point2, stackValue2) -> { - if(stackable2.getVolume() == stackable1.getVolume()) { - if(stackValue1.getArea() == stackValue2.getArea()) { - // closest distance to a wall is better - - int distance1 = Math.min(point1.getDx() - stackValue1.getDx(), point1.getDy() - stackValue1.getDy()); - int distance2 = Math.min(point2.getDx() - stackValue2.getDx(), point2.getDy() - stackValue2.getDy()); - - return distance2 < distance1; // closest is better - } - return stackValue2.getArea() < stackValue1.getArea(); // smaller is better - } - return stackable2.getVolume() > stackable1.getVolume(); // larger volume is better - }; - - public static StackValuePointFilter FIRST_STACK_VALUE_POINT_FILTER = (stackable1, point1, stackValue1, stackable2, point2, stackValue2) -> { - if(stackValue1.getArea() == stackValue2.getArea()) { - if(stackValue1.getVolume() == stackValue2.getVolume()) { - // closest distance to a wall is better - - int distance1 = Math.min(point1.getDx() - stackValue1.getDx(), point1.getDy() - stackValue1.getDy()); - int distance2 = Math.min(point2.getDx() - stackValue2.getDx(), point2.getDy() - stackValue2.getDy()); - - return distance2 < distance1; // closest is better - } - return stackValue1.getVolume() < stackValue2.getVolume(); // larger volume is better - - } - return stackValue1.getArea() < stackValue2.getArea(); // larger area is better - }; - + }; public AbstractLargestAreaFitFirstPackager(PackResultComparator packResultComparator) { super(packResultComparator); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java index e36635c3..057cd40d 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/FastLargestAreaFitFirstPackager.java @@ -15,9 +15,11 @@ import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.StackValue; import com.github.skjolber.packing.api.Stackable; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.ep.Point3D; import com.github.skjolber.packing.deadline.PackagerInterruptSupplier; import com.github.skjolber.packing.ep.points2d.ExtremePoints2D; +import com.github.skjolber.packing.ep.points2d.Point2D; +import com.github.skjolber.packing.ep.points2d.SimplePoint2D; import com.github.skjolber.packing.packer.AbstractPackagerBuilder; import com.github.skjolber.packing.packer.DefaultPackResult; import com.github.skjolber.packing.packer.DefaultPackResultComparator; @@ -29,8 +31,40 @@ * Thread-safe implementation. The input boxes must however only be used in a single thread at a time. */ -public class FastLargestAreaFitFirstPackager extends AbstractLargestAreaFitFirstPackager> { +public class FastLargestAreaFitFirstPackager extends AbstractLargestAreaFitFirstPackager { + public static boolean betterAsFirst(Stackable stackable1, Point2D point1, StackValue stackValue1, Stackable stackable2, Point2D point2, StackValue stackValue2) { + if(stackValue1.getArea() == stackValue2.getArea()) { + if(stackValue1.getVolume() == stackValue2.getVolume()) { + // closest distance to a wall is better + + int distance1 = Math.min(point1.getDx() - stackValue1.getDx(), point1.getDy() - stackValue1.getDy()); + int distance2 = Math.min(point2.getDx() - stackValue2.getDx(), point2.getDy() - stackValue2.getDy()); + + return distance2 < distance1; // closest is better + } + return stackValue1.getVolume() < stackValue2.getVolume(); // larger volume is better + + } + return stackValue1.getArea() < stackValue2.getArea(); // larger area is better + }; + + public static boolean betterAsNext(Stackable stackable1, Point2D point1, StackValue stackValue1, Stackable stackable2, Point2D point2, StackValue stackValue2) { + if(stackable2.getVolume() == stackable1.getVolume()) { + if(stackValue1.getArea() == stackValue2.getArea()) { + // closest distance to a wall is better + + int distance1 = Math.min(point1.getDx() - stackValue1.getDx(), point1.getDy() - stackValue1.getDy()); + int distance2 = Math.min(point2.getDx() - stackValue2.getDx(), point2.getDy() - stackValue2.getDy()); + + return distance2 < distance1; // closest is better + } + return stackValue2.getArea() < stackValue1.getArea(); // smaller is better + } + return stackable2.getVolume() > stackable1.getVolume(); // larger volume is better + }; + + public static LargestAreaFitFirstPackagerBuilder newBuilder() { return new LargestAreaFitFirstPackagerBuilder(); } @@ -66,7 +100,7 @@ public DefaultPackResult pack(List stackables, Container targetContai .filter(s -> constraint == null || constraint.canAccept(s)) .collect(Collectors.toList()); - ExtremePoints2D extremePoints2D = new ExtremePoints2D<>(containerStackValue.getLoadDx(), containerStackValue.getLoadDy()); + ExtremePoints2D extremePoints2D = new ExtremePoints2D(containerStackValue.getLoadDx(), containerStackValue.getLoadDy()); extremePoints2D.setMinArea(getMinStackableArea(scopedStackables)); @@ -83,7 +117,7 @@ public DefaultPackResult pack(List stackables, Container targetContai int maxHeight = containerStackValue.getLoadDz() - levelOffset; // there is only point, spanning the free space in the level - Point2D firstPoint = extremePoints2D.getValue(0); + SimplePoint2D firstPoint = extremePoints2D.getValue(0); int bestFirstIndex = -1; StackValue bestFirstStackValue = null; @@ -111,7 +145,7 @@ public DefaultPackResult pack(List stackables, Container targetContai if(constraint != null && !constraint.supports(stack, box, stackValue, 0, 0, levelOffset)) { continue; } - if(bestFirstStackValue != null && !FIRST_STACK_VALUE_POINT_FILTER.accept(bestFirstBox, firstPoint, bestFirstStackValue, box, firstPoint, stackValue)) { + if(bestFirstStackValue != null && !betterAsFirst(bestFirstBox, firstPoint, bestFirstStackValue, box, firstPoint, stackValue)) { continue; } bestFirstIndex = i; @@ -183,7 +217,7 @@ public DefaultPackResult pack(List stackables, Container targetContai // pick the best point / stackable combination int pointCount = extremePoints2D.getValueCount(); for (int k = 0; k < pointCount; k++) { - Point2D point2d = extremePoints2D.getValue(k); + SimplePoint2D point2d = extremePoints2D.getValue(k); if(point2d.getArea() < stackValue.getArea()) { continue; } @@ -192,7 +226,7 @@ public DefaultPackResult pack(List stackables, Container targetContai continue; } - if(bestIndex != -1 && !DEFAULT_STACK_VALUE_POINT_FILTER.accept(bestStackable, extremePoints2D.getValue(bestPointIndex), bestStackValue, box, point2d, stackValue)) { + if(bestIndex != -1 && !betterAsNext(bestStackable, extremePoints2D.getValue(bestPointIndex), bestStackValue, box, point2d, stackValue)) { continue; } if(constraint != null && !constraint.supports(stack, box, stackValue, point2d.getMinX(), point2d.getMinY(), levelOffset)) { @@ -214,7 +248,7 @@ public DefaultPackResult pack(List stackables, Container targetContai Stackable remove = scopedStackables.remove(bestIndex); remainingStackables.remove(remove); - Point2D point = extremePoints2D.getValue(bestPointIndex); + SimplePoint2D point = extremePoints2D.getValue(bestPointIndex); StackPlacement stackPlacement = new StackPlacement(remove, bestStackValue, point.getMinX(), point.getMinY(), 0); levelStack.add(stackPlacement); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java index fa39ec3d..eb7c974e 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackager.java @@ -29,8 +29,39 @@ * Thread-safe implementation. The input Boxes must however only be used in a single thread at a time. */ -public class LargestAreaFitFirstPackager extends AbstractLargestAreaFitFirstPackager> { +public class LargestAreaFitFirstPackager extends AbstractLargestAreaFitFirstPackager { + + public static boolean betterAsFirst(Stackable stackable1, Point3D point1, StackValue stackValue1, Stackable stackable2, Point3D point2, StackValue stackValue2) { + if(stackValue1.getArea() == stackValue2.getArea()) { + if(stackValue1.getVolume() == stackValue2.getVolume()) { + // closest distance to a wall is better + int distance1 = Math.min(point1.getDx() - stackValue1.getDx(), point1.getDy() - stackValue1.getDy()); + int distance2 = Math.min(point2.getDx() - stackValue2.getDx(), point2.getDy() - stackValue2.getDy()); + + return distance2 < distance1; // closest is better + } + return stackValue1.getVolume() < stackValue2.getVolume(); // larger volume is better + + } + return stackValue1.getArea() < stackValue2.getArea(); // larger area is better + }; + + public static boolean betterAsNext(Stackable stackable1, Point3D point1, StackValue stackValue1, Stackable stackable2, Point3D point2, StackValue stackValue2) { + if(stackable2.getVolume() == stackable1.getVolume()) { + if(stackValue1.getArea() == stackValue2.getArea()) { + // closest distance to a wall is better + + int distance1 = Math.min(point1.getDx() - stackValue1.getDx(), point1.getDy() - stackValue1.getDy()); + int distance2 = Math.min(point2.getDx() - stackValue2.getDx(), point2.getDy() - stackValue2.getDy()); + + return distance2 < distance1; // closest is better + } + return stackValue2.getArea() < stackValue1.getArea(); // smaller is better + } + return stackable2.getVolume() > stackable1.getVolume(); // larger volume is better + }; + public static LargestAreaFitFirstPackagerBuilder newBuilder() { return new LargestAreaFitFirstPackagerBuilder(); } @@ -66,7 +97,7 @@ public DefaultPackResult pack(List stackables, Container targetContai .filter(s -> constraint == null || constraint.canAccept(s)) .collect(Collectors.toList()); - ExtremePoints3D extremePoints3D = new ExtremePoints3D<>(containerStackValue.getLoadDx(), containerStackValue.getLoadDy(), containerStackValue.getLoadDz()); + ExtremePoints3D extremePoints3D = new ExtremePoints3D(containerStackValue.getLoadDx(), containerStackValue.getLoadDy(), containerStackValue.getLoadDz()); extremePoints3D.setMinimumAreaAndVolumeLimit(getMinStackableArea(scopedStackables), getMinStackableVolume(scopedStackables)); int levelOffset = 0; @@ -81,7 +112,7 @@ public DefaultPackResult pack(List stackables, Container targetContai int maxWeight = stack.getFreeWeightLoad(); // there is only point, spanning the free space in the level - Point3D firstPoint = extremePoints3D.getValue(0); + Point3D firstPoint = extremePoints3D.getValue(0); int firstIndex = -1; StackValue firstStackValue = null; @@ -103,7 +134,7 @@ public DefaultPackResult pack(List stackables, Container targetContai if(!firstPoint.fits3D(stackValue)) { continue; } - if(firstStackValue != null && !FIRST_STACK_VALUE_POINT_FILTER.accept(firstBox, firstPoint, firstStackValue, box, firstPoint, stackValue)) { + if(firstStackValue != null && !betterAsFirst(firstBox, firstPoint, firstStackValue, box, firstPoint, stackValue)) { continue; } @@ -169,12 +200,12 @@ public DefaultPackResult pack(List stackables, Container targetContai int currentPointsCount = extremePoints3D.getValueCount(); for (int k = 0; k < currentPointsCount; k++) { - Point3D point3d = extremePoints3D.getValue(k); + Point3D point3d = extremePoints3D.getValue(k); if(!point3d.fits3D(stackValue)) { continue; } - if(bestIndex != -1 && !DEFAULT_STACK_VALUE_POINT_FILTER.accept(bestStackable, extremePoints3D.getValue(bestPointIndex), bestStackValue, box, point3d, stackValue)) { + if(bestIndex != -1 && !betterAsNext(bestStackable, extremePoints3D.getValue(bestPointIndex), bestStackValue, box, point3d, stackValue)) { continue; } if(constraint != null && !constraint.supports(stack, box, stackValue, point3d.getMinX(), point3d.getMinY(), levelOffset + point3d.getMinZ())) { @@ -195,7 +226,7 @@ public DefaultPackResult pack(List stackables, Container targetContai Stackable remove = scopedStackables.remove(bestIndex); remainingStackables.remove(remove); - Point3D point = extremePoints3D.getValue(bestPointIndex); + Point3D point = extremePoints3D.getValue(bestPointIndex); StackPlacement stackPlacement = new StackPlacement(remove, bestStackValue, point.getMinX(), point.getMinY(), point.getMinZ()); levelStack.add(stackPlacement); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java index b1a34559..04af11c8 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerResultBuilder.java @@ -11,9 +11,9 @@ public class LargestAreaFitFirstPackagerResultBuilder extends PackagerResultBuilder { - private AbstractLargestAreaFitFirstPackager packager; + private AbstractLargestAreaFitFirstPackager packager; - public LargestAreaFitFirstPackagerResultBuilder withPackager(AbstractLargestAreaFitFirstPackager packager) { + public LargestAreaFitFirstPackagerResultBuilder withPackager(AbstractLargestAreaFitFirstPackager packager) { this.packager = packager; return this; } diff --git a/core/src/main/java/com/github/skjolber/packing/packer/laff/StackValuePointFilter.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/StackValuePointFilter.java deleted file mode 100644 index b34ded7d..00000000 --- a/core/src/main/java/com/github/skjolber/packing/packer/laff/StackValuePointFilter.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.github.skjolber.packing.packer.laff; - -import com.github.skjolber.packing.api.StackValue; -import com.github.skjolber.packing.api.Stackable; -import com.github.skjolber.packing.api.ep.Point2D; - -@SuppressWarnings("rawtypes") -@FunctionalInterface -public interface StackValuePointFilter { - - /** - * Check whether to let 2 replace 1 as the best. - * - * @param stackable1 first stackable - * @param point1 first point - * @param stackValue1 first stack value - * @param stackable2 second stackable - * @param point2 second point - * @param stackValue2 second stack value - * @return true if point2 is superior to point1 - * @throws ClassCastException if the arguments' types prevent them from - * being compared by this filter. - */ - - boolean accept(Stackable stackable1, T point1, StackValue stackValue1, Stackable stackable2, T point2, StackValue stackValue2); - -} diff --git a/api/src/main/java/com/github/skjolber/packing/api/StackableFilter.java b/core/src/main/java/com/github/skjolber/packing/packer/laff/StackableFilter.java similarity index 67% rename from api/src/main/java/com/github/skjolber/packing/api/StackableFilter.java rename to core/src/main/java/com/github/skjolber/packing/packer/laff/StackableFilter.java index 4f047f7d..71f27fe1 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/StackableFilter.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/laff/StackableFilter.java @@ -1,4 +1,6 @@ -package com.github.skjolber.packing.api; +package com.github.skjolber.packing.packer.laff; + +import com.github.skjolber.packing.api.Stackable; @FunctionalInterface public interface StackableFilter { diff --git a/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java index e5cc5a43..4f9edf5c 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/plain/AbstractPlainPackager.java @@ -9,10 +9,8 @@ import com.github.skjolber.packing.api.ContainerItem; import com.github.skjolber.packing.api.PackResultComparator; import com.github.skjolber.packing.api.Stack; -import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.Stackable; import com.github.skjolber.packing.api.StackableItem; -import com.github.skjolber.packing.api.ep.Point2D; import com.github.skjolber.packing.deadline.PackagerInterruptSupplier; import com.github.skjolber.packing.packer.AbstractPackager; import com.github.skjolber.packing.packer.AbstractPackagerAdapter; @@ -24,7 +22,7 @@ *
* Thread-safe implementation. The input Boxes must however only be used in a single thread at a time. */ -public abstract class AbstractPlainPackager

> extends AbstractPackager { +public abstract class AbstractPlainPackager extends AbstractPackager { public AbstractPlainPackager(PackResultComparator packResultComparator) { super(packResultComparator); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java index 2479b893..3dcf7e9b 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackager.java @@ -28,7 +28,7 @@ * Thread-safe implementation. The input Boxes must however only be used in a single thread at a time. */ -public class PlainPackager extends AbstractPlainPackager> { +public class PlainPackager extends AbstractPlainPackager { public static Builder newBuilder() { return new Builder(); @@ -65,7 +65,7 @@ public DefaultPackResult pack(List stackables, Container targetContai .filter(s -> constraint == null || constraint.canAccept(s)) .collect(Collectors.toList()); - ExtremePoints3D extremePoints3D = new ExtremePoints3D<>(containerStackValue.getLoadDx(), containerStackValue.getLoadDy(), containerStackValue.getLoadDz()); + ExtremePoints3D extremePoints3D = new ExtremePoints3D(containerStackValue.getLoadDx(), containerStackValue.getLoadDy(), containerStackValue.getLoadDz()); extremePoints3D.setMinimumAreaAndVolumeLimit(getMinStackableArea(scopedStackables), getMinStackableVolume(scopedStackables)); int maxRemainingWeight = containerStackValue.getMaxLoadWeight(); @@ -115,7 +115,7 @@ public DefaultPackResult pack(List stackables, Container targetContai } for (int k = 0; k < currentPointsCount; k++) { - Point3D point3d = extremePoints3D.getValue(k); + Point3D point3d = extremePoints3D.getValue(k); if(!point3d.fits3D(stackValue)) { continue; @@ -123,7 +123,7 @@ public DefaultPackResult pack(List stackables, Container targetContai long pointSupportPercent; // cache for costly measurement if(bestIndex != -1) { - Point3D bestPoint = extremePoints3D.getValue(bestPointIndex); + Point3D bestPoint = extremePoints3D.getValue(bestPointIndex); if(point3d.getMinZ() > bestPoint.getMinZ()) { continue; @@ -164,7 +164,7 @@ public DefaultPackResult pack(List stackables, Container targetContai scopedStackables.remove(bestIndex); remainingStackables.remove(bestStackable); - Point3D point = extremePoints3D.getValue(bestPointIndex); + Point3D point = extremePoints3D.getValue(bestPointIndex); StackPlacement stackPlacement = new StackPlacement(bestStackable, bestStackValue, point.getMinX(), point.getMinY(), point.getMinZ()); stack.add(stackPlacement); @@ -189,7 +189,7 @@ public DefaultPackResult pack(List stackables, Container targetContai stack, remainingStackables.isEmpty(), index); } - protected long calculateXYSupportPercent(ExtremePoints3D extremePoints3D, Point3D referencePoint, StackValue stackValue) { + protected long calculateXYSupportPercent(ExtremePoints3D extremePoints3D, Point3D referencePoint, StackValue stackValue) { long sum = 0; int minX = referencePoint.getMinX(); diff --git a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java index 0dd89a2b..1a3fa9a3 100644 --- a/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java +++ b/core/src/main/java/com/github/skjolber/packing/packer/plain/PlainPackagerResultBuilder.java @@ -11,9 +11,9 @@ public class PlainPackagerResultBuilder extends PackagerResultBuilder { - private AbstractPlainPackager packager; + private AbstractPlainPackager packager; - public PlainPackagerResultBuilder withPackager(AbstractPlainPackager packager) { + public PlainPackagerResultBuilder withPackager(AbstractPlainPackager packager) { this.packager = packager; return this; } diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java index 4c374006..55364ebf 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/BruteForcePackagerTest.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.packer.bruteforce; -import static com.github.skjolber.packing.test.assertj.StackablePlacementAssert.assertThat; +import static com.github.skjolber.packing.test.assertj.StackPlacementAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java index 94fc7e8e..d13bba29 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/FastBruteForcePackagerTest.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.packer.bruteforce; -import static com.github.skjolber.packing.test.assertj.StackablePlacementAssert.assertThat; +import static com.github.skjolber.packing.test.assertj.StackPlacementAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java index 38c78ed8..d26b5462 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/bruteforce/ParallelBruteForcePackagerTest.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.packer.bruteforce; -import static com.github.skjolber.packing.test.assertj.StackablePlacementAssert.assertThat; +import static com.github.skjolber.packing.test.assertj.StackPlacementAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; diff --git a/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java b/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java index c2e386ee..fac9be26 100644 --- a/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java +++ b/core/src/test/java/com/github/skjolber/packing/packer/laff/LargestAreaFitFirstPackagerTest.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.packer.laff; -import static com.github.skjolber.packing.test.assertj.StackablePlacementAssert.assertThat; +import static com.github.skjolber.packing.test.assertj.StackPlacementAssert.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPlacement2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPlacement2D.java deleted file mode 100644 index 096e5e92..00000000 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPlacement2D.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.github.skjolber.packing.ep.points2d; - -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement2D; - -public class DefaultPlacement2D implements Placement2D, Serializable { - - private static final long serialVersionUID = 1L; - - protected final int x; - protected final int y; - protected final int endX; - protected final int endY; - - public DefaultPlacement2D(int x, int y, int endX, int endY) { - this.x = x; - this.y = y; - this.endX = endX; - this.endY = endY; - } - - @Override - public int getAbsoluteX() { - return x; - } - - @Override - public int getAbsoluteY() { - return y; - } - - @Override - public int getAbsoluteEndX() { - return endX; - } - - @Override - public int getAbsoluteEndY() { - return endY; - } - - @Override - public String toString() { - return getClass().getSimpleName() + "[" + x + "x" + y + ", " + endX + "x" + endY + "]"; - } - - @Override - public boolean intersects2D(Placement2D point) { - return !(point.getAbsoluteEndX() < x || point.getAbsoluteX() > endX || point.getAbsoluteEndY() < y || point.getAbsoluteY() > endY); - } - -} diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPoint2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPoint2D.java index b1b30899..c4ea0ae3 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPoint2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultPoint2D.java @@ -2,10 +2,9 @@ import java.io.Serializable; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.StackPlacement; -public class DefaultPoint2D

extends SimplePoint2D

{ +public class DefaultPoint2D extends SimplePoint2D { private static final long serialVersionUID = 1L; @@ -23,28 +22,28 @@ public boolean isYSupport(int y) { return false; } - public SimplePoint2D

clone(int maxX, int maxY) { - return new DefaultPoint2D<>(minX, minY, maxX, maxY); + public SimplePoint2D clone(int maxX, int maxY) { + return new DefaultPoint2D(minX, minY, maxX, maxY); } @Override - public SimplePoint2D

moveX(int x) { - return new DefaultPoint2D<>(x, minY, maxX, maxY); + public SimplePoint2D moveX(int x) { + return new DefaultPoint2D(x, minY, maxX, maxY); } @Override - public SimplePoint2D

moveY(int y) { - return new DefaultPoint2D<>(minX, y, maxX, maxY); + public SimplePoint2D moveY(int y) { + return new DefaultPoint2D(minX, y, maxX, maxY); } @Override - public SimplePoint2D

moveX(int x, P ySupport) { - return new DefaultYSupportPoint2D<>(x, minY, maxY, maxY, ySupport); + public SimplePoint2D moveX(int x, StackPlacement ySupport) { + return new DefaultYSupportPoint2D(x, minY, maxY, maxY, ySupport); } @Override - public SimplePoint2D

moveY(int y, P xSupport) { - return new DefaultXSupportPoint2D<>(minX, y, maxX, maxX, xSupport); + public SimplePoint2D moveY(int y, StackPlacement xSupport) { + return new DefaultXSupportPoint2D(minX, y, maxX, maxX, xSupport); } } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXSupportPoint2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXSupportPoint2D.java index ed72eb6a..10ae68fa 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXSupportPoint2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXSupportPoint2D.java @@ -2,16 +2,15 @@ import java.io.Serializable; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.StackPlacement; -public class DefaultXSupportPoint2D

extends SimplePoint2D

implements XSupportPoint2D { +public class DefaultXSupportPoint2D extends SimplePoint2D implements XSupportPoint2D { private static final long serialVersionUID = 1L; /** range constrained to current minY */ - private final P xSupport; + private final StackPlacement xSupport; - public DefaultXSupportPoint2D(int minX, int minY, int maxX, int maxY, P xSupport) { + public DefaultXSupportPoint2D(int minX, int minY, int maxX, int maxY, StackPlacement xSupport) { super(minX, minY, maxX, maxY); this.xSupport = xSupport; } @@ -35,8 +34,8 @@ public String toString() { + ", xSupportMinX=" + getXSupportMinX() + ", xSupportMaxX=" + getXSupportMaxX() + "]"; } - public Point2D

clone(int maxX, int maxY) { - return new DefaultXSupportPoint2D<>(minX, minY, maxX, maxY, xSupport); + public Point2D clone(int maxX, int maxY) { + return new DefaultXSupportPoint2D(minX, minY, maxX, maxY, xSupport); } @Override @@ -50,28 +49,28 @@ public int getSupportedMinX() { } @Override - public SimplePoint2D

moveX(int x) { + public SimplePoint2D moveX(int x) { if(x <= xSupport.getAbsoluteEndX()) { - return new DefaultXSupportPoint2D<>(x, minY, maxX, maxY, xSupport); + return new DefaultXSupportPoint2D(x, minY, maxX, maxY, xSupport); } - return new DefaultPoint2D<>(x, minY, maxX, maxY); + return new DefaultPoint2D(x, minY, maxX, maxY); } @Override - public SimplePoint2D

moveX(int x, P ySupport) { + public SimplePoint2D moveX(int x, StackPlacement ySupport) { if(x <= xSupport.getAbsoluteEndX()) { - return new DefaultXYSupportPoint2D<>(x, minY, maxX, maxY, xSupport, ySupport); + return new DefaultXYSupportPoint2D(x, minY, maxX, maxY, xSupport, ySupport); } - return new DefaultYSupportPoint2D<>(x, minY, maxX, maxY, ySupport); + return new DefaultYSupportPoint2D(x, minY, maxX, maxY, ySupport); } @Override - public SimplePoint2D

moveY(int y) { - return new DefaultPoint2D<>(minX, y, maxX, maxY); + public SimplePoint2D moveY(int y) { + return new DefaultPoint2D(minX, y, maxX, maxY); } @Override - public SimplePoint2D

moveY(int y, P xSupport) { - return new DefaultXSupportPoint2D<>(minX, y, maxX, maxY, xSupport); + public SimplePoint2D moveY(int y, StackPlacement xSupport) { + return new DefaultXSupportPoint2D(minX, y, maxX, maxY, xSupport); } } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXYSupportPoint2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXYSupportPoint2D.java index 22f079f3..840df131 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXYSupportPoint2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultXYSupportPoint2D.java @@ -2,16 +2,15 @@ import java.io.Serializable; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.StackPlacement; -public class DefaultXYSupportPoint2D

extends SimplePoint2D

implements XSupportPoint2D, YSupportPoint2D { +public class DefaultXYSupportPoint2D extends SimplePoint2D implements XSupportPoint2D, YSupportPoint2D { private static final long serialVersionUID = 1L; - private final P xSupport; - private final P ySupport; + private final StackPlacement xSupport; + private final StackPlacement ySupport; - public DefaultXYSupportPoint2D(int minX, int minY, int maxX, int maxY, P xSupport, P ySupport) { + public DefaultXYSupportPoint2D(int minX, int minY, int maxX, int maxY, StackPlacement xSupport, StackPlacement ySupport) { super(minX, minY, maxX, maxY); if(minX < 0) { @@ -64,8 +63,8 @@ public String toString() { + ", ySupportMinY=" + getYSupportMinY() + ", ySupportMaxY=" + getYSupportMaxY() + "]"; } - public SimplePoint2D

clone(int maxX, int maxY) { - return new DefaultXYSupportPoint2D

(minX, minY, maxX, maxY, xSupport, ySupport); + public SimplePoint2D clone(int maxX, int maxY) { + return new DefaultXYSupportPoint2D(minX, minY, maxX, maxY, xSupport, ySupport); } @Override @@ -89,35 +88,35 @@ public int getSupportedMinX() { } @Override - public SimplePoint2D

moveY(int y) { + public SimplePoint2D moveY(int y) { if(y <= ySupport.getAbsoluteEndY()) { - return new DefaultYSupportPoint2D

(minX, y, maxX, maxY, ySupport); + return new DefaultYSupportPoint2D(minX, y, maxX, maxY, ySupport); } - return new DefaultPoint2D

(minX, y, maxX, maxY); + return new DefaultPoint2D(minX, y, maxX, maxY); } @Override - public SimplePoint2D

moveX(int x) { + public SimplePoint2D moveX(int x) { if(x <= xSupport.getAbsoluteEndX()) { - return new DefaultXSupportPoint2D

(x, minY, maxX, maxY, xSupport); + return new DefaultXSupportPoint2D(x, minY, maxX, maxY, xSupport); } - return new DefaultPoint2D<>(x, minY, maxX, maxY); + return new DefaultPoint2D(x, minY, maxX, maxY); } @Override - public SimplePoint2D

moveX(int x, P ySupport) { + public SimplePoint2D moveX(int x, StackPlacement ySupport) { if(x <= xSupport.getAbsoluteEndX()) { - return new DefaultXYSupportPoint2D

(x, minY, maxX, maxY, xSupport, ySupport); + return new DefaultXYSupportPoint2D(x, minY, maxX, maxY, xSupport, ySupport); } - return new DefaultYSupportPoint2D

(x, minY, maxX, maxY, ySupport); + return new DefaultYSupportPoint2D(x, minY, maxX, maxY, ySupport); } @Override - public SimplePoint2D

moveY(int y, P xSupport) { + public SimplePoint2D moveY(int y, StackPlacement xSupport) { if(y <= ySupport.getAbsoluteEndY()) { - return new DefaultXYSupportPoint2D

(minX, y, maxX, maxY, xSupport, ySupport); + return new DefaultXYSupportPoint2D(minX, y, maxX, maxY, xSupport, ySupport); } - return new DefaultXSupportPoint2D

(minX, y, maxX, maxY, xSupport); + return new DefaultXSupportPoint2D(minX, y, maxX, maxY, xSupport); } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultYSupportPoint2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultYSupportPoint2D.java index be1e0dac..d03cc800 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultYSupportPoint2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/DefaultYSupportPoint2D.java @@ -2,16 +2,15 @@ import java.io.Serializable; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.StackPlacement; -public class DefaultYSupportPoint2D

extends SimplePoint2D

implements YSupportPoint2D { +public class DefaultYSupportPoint2D extends SimplePoint2D implements YSupportPoint2D { private static final long serialVersionUID = 1L; /** range constrained to current minX */ - private final P ySupport; + private final StackPlacement ySupport; - public DefaultYSupportPoint2D(int minX, int minY, int maxX, int maxY, P ySupport) { + public DefaultYSupportPoint2D(int minX, int minY, int maxX, int maxY, StackPlacement ySupport) { super(minX, minY, maxX, maxY); this.ySupport = ySupport; } @@ -35,8 +34,8 @@ public String toString() { + ", ySupportMinY=" + getYSupportMinY() + ", ySupportMaxY=" + getYSupportMaxY() + "]"; } - public Point2D

clone(int maxX, int maxY) { - return new DefaultYSupportPoint2D<>(minX, minY, maxX, maxY, ySupport); + public Point2D clone(int maxX, int maxY) { + return new DefaultYSupportPoint2D(minX, minY, maxX, maxY, ySupport); } @Override @@ -50,29 +49,29 @@ public int getSupportedMinY() { } @Override - public SimplePoint2D

moveY(int y) { + public SimplePoint2D moveY(int y) { if(y <= ySupport.getAbsoluteEndY()) { - return new DefaultYSupportPoint2D

(minX, y, maxX, maxY, ySupport); + return new DefaultYSupportPoint2D(minX, y, maxX, maxY, ySupport); } - return new DefaultPoint2D

(minX, y, maxX, maxY); + return new DefaultPoint2D(minX, y, maxX, maxY); } @Override - public SimplePoint2D

moveY(int y, P xSupport) { + public SimplePoint2D moveY(int y, StackPlacement xSupport) { if(y <= ySupport.getAbsoluteEndY()) { - return new DefaultXYSupportPoint2D<>(minX, y, maxX, maxY, xSupport, ySupport); + return new DefaultXYSupportPoint2D(minX, y, maxX, maxY, xSupport, ySupport); } - return new DefaultXSupportPoint2D<>(minX, y, maxX, maxY, xSupport); + return new DefaultXSupportPoint2D(minX, y, maxX, maxY, xSupport); } @Override - public SimplePoint2D

moveX(int x, P ySupport) { - return new DefaultYSupportPoint2D<>(x, minY, maxX, maxY, ySupport); + public SimplePoint2D moveX(int x, StackPlacement ySupport) { + return new DefaultYSupportPoint2D(x, minY, maxX, maxY, ySupport); } @Override - public SimplePoint2D

moveX(int x) { - return new DefaultPoint2D<>(x, minY, maxX, maxY); + public SimplePoint2D moveX(int x) { + return new DefaultPoint2D(x, minY, maxX, maxY); } } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/ExtremePoints2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/ExtremePoints2D.java index c3a9efa7..cf8a22ef 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/ExtremePoints2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/ExtremePoints2D.java @@ -1,6 +1,5 @@ package com.github.skjolber.packing.ep.points2d; -import java.io.Serializable; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -8,9 +7,8 @@ import org.eclipse.collections.api.block.comparator.primitive.IntComparator; import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.ExtremePoints; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; /** * @@ -18,12 +16,12 @@ * */ -public class ExtremePoints2D

implements ExtremePoints> { +public class ExtremePoints2D { - public static final Comparator> COMPARATOR_X = new Comparator>() { + public static final Comparator COMPARATOR_X = new Comparator() { @Override - public int compare(Point2D o1, Point2D o2) { + public int compare(Point2D o1, Point2D o2) { return Integer.compare(o1.getMinX(), o2.getMinX()); } }; @@ -31,17 +29,17 @@ public int compare(Point2D o1, Point2D o2) { protected int containerMaxX; protected int containerMaxY; - protected final Point2DFlagList

values = new Point2DFlagList<>(); - protected final List

placements = new ArrayList<>(); + protected final Point2DFlagList values = new Point2DFlagList(); + protected final List placements = new ArrayList<>(); // reuse working variables - protected final Point2DList> addXX = new Point2DList<>(); - protected final Point2DList> addYY = new Point2DList<>(); + protected final Point2DList addXX = new Point2DList(); + protected final Point2DList addYY = new Point2DList(); protected final IntArrayList moveToYY = new IntArrayList(); protected final IntArrayList moveToXX = new IntArrayList(); - protected P containerPlacement; + protected StackPlacement containerPlacement; protected long minAreaLimit = 0; @@ -70,14 +68,16 @@ private void setSize(int dx, int dy) { this.containerMaxX = dx - 1; this.containerMaxY = dy - 1; - this.containerPlacement = (P)new DefaultPlacement2D(0, 0, containerMaxX, containerMaxY); + BoxStackValue stackValue = new BoxStackValue(containerMaxX + 1, containerMaxY + 1, 0, null, null); + + this.containerPlacement = new StackPlacement(null, stackValue, 0, 0, 0); } private void addFirstPoint() { - values.add(new DefaultXYSupportPoint2D

(0, 0, containerMaxX, containerMaxY, containerPlacement, containerPlacement)); + values.add(new DefaultXYSupportPoint2D(0, 0, containerMaxX, containerMaxY, containerPlacement, containerPlacement)); } - public boolean add(int index, P placement) { + public boolean add(int index, StackPlacement placement) { // overall approach: // Do not iterate over placements to find point max / mins, rather // project existing points. @@ -88,7 +88,7 @@ public boolean add(int index, P placement) { // remove points which are eclipsed by others // keep track of placement borders, where possible - Point2D

source = values.get(index); + Point2D source = values.get(index); boolean xSupport = source.isXSupport(source.getMinX()); boolean ySupport = source.isYSupport(source.getMinY()); @@ -177,7 +177,7 @@ public boolean add(int index, P placement) { addYY.ensureAdditionalCapacity(values.size()); for (int i = pointIndex; i < endIndex; i++) { - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinY() > placement.getAbsoluteEndY()) { // @@ -286,18 +286,18 @@ public boolean add(int index, P placement) { moveToXX.sortThis(COMPARATOR_MOVE_TO_XX); add: for (int i = 0; i < moveToXX.size(); i++) { - SimplePoint2D

p = values.get(moveToXX.get(i)); + SimplePoint2D p = values.get(moveToXX.get(i)); // add point on the other side // with x support for (int k = 0; k < addXX.size(); k++) { - Point2D

add = addXX.get(k); + Point2D add = addXX.get(k); if(add.eclipsesMovedX(p, xx)) { continue add; } } // note: the new point might shadow one of the previous points - SimplePoint2D

moveX = p.moveX(xx, placement); + SimplePoint2D moveX = p.moveX(xx, placement); addXX.add(moveX); } } @@ -306,18 +306,18 @@ public boolean add(int index, P placement) { moveToYY.sortThis(COMPARATOR_MOVE_TO_YY); add: for (int i = 0; i < moveToYY.size(); i++) { - SimplePoint2D

p = values.get(moveToYY.get(i)); + SimplePoint2D p = values.get(moveToYY.get(i)); // add point on the other side // with x support for (int k = 0; k < addYY.size(); k++) { - Point2D

add = addYY.get(k); + Point2D add = addYY.get(k); if(add.eclipsesMovedY(p, yy)) { continue add; } } - SimplePoint2D

moveY = p.moveY(yy, placement); + SimplePoint2D moveY = p.moveY(yy, placement); addYY.add(moveY); } } @@ -421,18 +421,18 @@ public boolean add(int index, P placement) { return !values.isEmpty(); } - private void constrainMaxXWithClone(P placement, int pointIndex, int endIndex) { + private void constrainMaxXWithClone(StackPlacement placement, int pointIndex, int endIndex) { for (int i = pointIndex; i < endIndex; i++) { if(values.isFlag(i)) { continue; } - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinX() < placement.getAbsoluteX() && withinY(point.getMinY(), placement)) { if(point.getMaxX() >= placement.getAbsoluteX()) { int limitX = placement.getAbsoluteX() - 1; if(!isConstrainedAtMaxX(point, limitX)) { - Point2D

clone = point.clone(limitX, point.getMaxY()); + Point2D clone = point.clone(limitX, point.getMaxY()); addXX.add(clone); } @@ -443,18 +443,18 @@ private void constrainMaxXWithClone(P placement, int pointIndex, int endIndex) { } } - private void constrainMaxYWithClone(P placement, int pointIndex, int endIndex) { + private void constrainMaxYWithClone(StackPlacement placement, int pointIndex, int endIndex) { for (int i = pointIndex; i < endIndex; i++) { if(values.isFlag(i)) { continue; } - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinY() < placement.getAbsoluteY() && withinX(point.getMinX(), placement)) { if(point.getMaxY() >= placement.getAbsoluteY()) { int limitY = placement.getAbsoluteY() - 1; if(!isConstrainedAtMaxY(point, limitY)) { - Point2D

clone = point.clone(point.getMaxX(), limitY); + Point2D clone = point.clone(point.getMaxX(), limitY); addXX.add(clone); } @@ -464,13 +464,13 @@ private void constrainMaxYWithClone(P placement, int pointIndex, int endIndex) { } } - private void constrainMaxX(P placement, int pointIndex, int endIndex) { + private void constrainMaxX(StackPlacement placement, int pointIndex, int endIndex) { for (int i = pointIndex; i < endIndex; i++) { if(values.isFlag(i)) { continue; } - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinX() < placement.getAbsoluteX() && withinY(point.getMinY(), placement)) { if(point.getMaxX() >= placement.getAbsoluteX()) { point.setMaxX(placement.getAbsoluteX() - 1); @@ -482,13 +482,13 @@ private void constrainMaxX(P placement, int pointIndex, int endIndex) { } } - private void constrainMaxY(P placement, int pointIndex, int endIndex) { + private void constrainMaxY(StackPlacement placement, int pointIndex, int endIndex) { for (int i = pointIndex; i < endIndex; i++) { if(values.isFlag(i)) { continue; } - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinY() < placement.getAbsoluteY() && withinX(point.getMinX(), placement)) { if(point.getMaxY() >= placement.getAbsoluteY()) { point.setMaxY(placement.getAbsoluteY() - 1); @@ -506,7 +506,7 @@ protected void removeEclipsed(int limit) { // | new | existing / current | // |----------|----------------------|--> x - Point2DFlagList

values = this.values; + Point2DFlagList values = this.values; int size = values.size(); @@ -514,13 +514,13 @@ protected void removeEclipsed(int limit) { if(values.isFlag(i)) { continue; } - Point2D

unsorted = values.get(i); + Point2D unsorted = values.get(i); for (int index = limit; index < size; index++) { if(values.isFlag(index)) { continue; } - Point2D

sorted = values.get(index); + Point2D sorted = values.get(index); if(sorted.getMinX() > unsorted.getMinX()) { // so sorted cannot contain unsorted // at this index or later @@ -541,11 +541,11 @@ protected void removeEclipsed(int limit) { } } - protected void constrainFloatingMaxWithClone(P placement, int limit) { + protected void constrainFloatingMaxWithClone(StackPlacement placement, int limit) { - Point2DFlagList

values = this.values; - Point2DList> addXX = this.addXX; - Point2DList> addYY = this.addYY; + Point2DFlagList values = this.values; + Point2DList addXX = this.addXX; + Point2DList addYY = this.addYY; addXX.ensureAdditionalCapacity(limit); addYY.ensureAdditionalCapacity(limit); @@ -555,7 +555,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { continue; } - Point2D

point = values.get(i); + Point2D point = values.get(i); if( placement.getAbsoluteEndY() < point.getMinY() || @@ -616,14 +616,14 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { addX: if(point.getMinX() < placement.getAbsoluteX()) { int limitX = placement.getAbsoluteX() - 1; if(!isConstrainedAtMaxX(point, limitX)) { - Point2D

clone = point.clone(limitX, point.getMaxY()); + Point2D clone = point.clone(limitX, point.getMaxY()); // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { if(values.isFlag(j)) { continue; } - Point2D

point3d = values.get(j); + Point2D point3d = values.get(j); if(point3d.getMinX() > clone.getMinX()) { break; } @@ -637,7 +637,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { // is the point now eclipsed by new points? for (int j = 0; j < addXX.size(); j++) { - Point2D

point3d = addXX.get(j); + Point2D point3d = addXX.get(j); if(point3d.getArea() >= clone.getArea()) { if(point3d.eclipses(clone)) { @@ -653,14 +653,14 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { addY: if(point.getMinY() < placement.getAbsoluteY()) { int limitY = placement.getAbsoluteY() - 1; if(!isConstrainedAtMaxY(point, limitY)) { - Point2D

clone = point.clone(point.getMaxX(), limitY); + Point2D clone = point.clone(point.getMaxX(), limitY); // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { if(values.isFlag(j)) { continue; } - Point2D

point3d = values.get(j); + Point2D point3d = values.get(j); if(point3d.getMinX() > clone.getMinX()) { break; } @@ -674,7 +674,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { // is the point now eclipsed by new points? for (int j = 0; j < addYY.size(); j++) { - Point2D

point3d = addYY.get(j); + Point2D point3d = addYY.get(j); if(point3d.getArea() >= clone.getArea()) { if(point3d.eclipses(clone)) { @@ -691,11 +691,11 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { } } - protected void constrainFloatingMax(P placement, int limit) { + protected void constrainFloatingMax(StackPlacement placement, int limit) { - Point2DFlagList

values = this.values; - Point2DList> addXX = this.addXX; - Point2DList> addYY = this.addYY; + Point2DFlagList values = this.values; + Point2DList addXX = this.addXX; + Point2DList addYY = this.addYY; long minAreaLimit = this.minAreaLimit; addXX.ensureAdditionalCapacity(limit); @@ -712,7 +712,7 @@ protected void constrainFloatingMax(P placement, int limit) { continue; } - Point2D

point = values.get(i); + Point2D point = values.get(i); if( placement.getAbsoluteEndY() < point.getMinY() || @@ -739,7 +739,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(values.isFlag(j)) { continue; } - Point2D

point3d = values.get(j); + Point2D point3d = values.get(j); if(point3d.getMinX() > point.getMinX()) { break; } @@ -756,7 +756,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(splitXX) { // is the point now eclipsed by new points? for (int j = startAddXX; j < addXX.size(); j++) { - Point2D

point3d = addXX.get(j); + Point2D point3d = addXX.get(j); if(point3d.getArea() >= point.getArea()) { if(point3d.eclipses(point)) { @@ -790,7 +790,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(values.isFlag(j)) { continue; } - Point2D

point3d = values.get(j); + Point2D point3d = values.get(j); if(point3d.getMinX() > point.getMinX()) { break; } @@ -807,7 +807,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(splitYY) { // is the point now eclipsed by new points? for (int j = startAddYY; j < addYY.size(); j++) { - Point2D

point3d = addYY.get(j); + Point2D point3d = addYY.get(j); if(point3d.getArea() >= point.getArea()) { if(point3d.eclipses(point)) { @@ -893,13 +893,13 @@ protected void constrainFloatingMax(P placement, int limit) { // if(!isConstrainedAtMaxX(point, placement.getAbsoluteX() - 1)) { - Point2D

clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY()); + Point2D clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY()); addXX.add(clone); splitXX = true; } if(!isConstrainedAtMaxY(point, placement.getAbsoluteY() - 1)) { - Point2D

clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1); + Point2D clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1); addYY.add(clone); splitYY = true; @@ -909,19 +909,19 @@ protected void constrainFloatingMax(P placement, int limit) { } } - private boolean isConstrainedAtMaxX(Point2D

p, int maxX) { + private boolean isConstrainedAtMaxX(Point2D p, int maxX) { return p.getAreaAtMaxX(maxX) < minAreaLimit; } - private boolean isConstrainedAtMaxY(Point2D

p, int maxY) { + private boolean isConstrainedAtMaxY(Point2D p, int maxY) { return p.getAreaAtMaxY(maxY) < minAreaLimit; } - protected boolean withinX(int x, P placement) { + protected boolean withinX(int x, StackPlacement placement) { return placement.getAbsoluteX() <= x && x <= placement.getAbsoluteEndX(); } - protected boolean withinY(int y, P placement) { + protected boolean withinY(int y, StackPlacement placement) { return placement.getAbsoluteY() <= y && y <= placement.getAbsoluteEndY(); } @@ -938,19 +938,18 @@ public String toString() { return "ExtremePoints2D [" + containerMaxX + "x" + containerMaxY + ": " + values + "]"; } - public List

getPlacements() { + public List getPlacements() { return placements; } - public SimplePoint2D

getValue(int i) { + public SimplePoint2D getValue(int i) { return values.get(i); } - public List> getValues() { + public List getValues() { return values.toList(); } - @Override public int getValueCount() { return values.size(); } @@ -958,7 +957,7 @@ public int getValueCount() { public int getMinY() { int min = 0; for (int i = 1; i < values.size(); i++) { - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinY() < values.get(min).getMinY()) { min = i; @@ -970,7 +969,7 @@ public int getMinY() { public int getMinX() { int min = 0; for (int i = 1; i < values.size(); i++) { - Point2D

point = values.get(i); + Point2D point = values.get(i); if(point.getMinX() < values.get(min).getMinX()) { min = i; @@ -986,7 +985,7 @@ public boolean isEmpty() { public long getMaxArea() { long maxPointArea = -1L; for (int i = 0; i < values.size(); i++) { - Point2D

point = values.get(i); + Point2D point = values.get(i); if(maxPointArea < point.getArea()) { maxPointArea = point.getArea(); } @@ -1001,7 +1000,6 @@ public void redo() { addFirstPoint(); } - @Override public void reset(int dx, int dy, int dz) { setSize(dx, dy); @@ -1010,7 +1008,7 @@ public void reset(int dx, int dy, int dz) { public int findPoint(int x, int y) { for (int i = 0; i < values.size(); i++) { - Point2D

point2d = values.get(i); + Point2D point2d = values.get(i); if(point2d.getMinX() == x && point2d.getMinY() == y) { return i; } @@ -1097,7 +1095,7 @@ public void setMinArea(long minArea) { private void filterMinimums() { for (int i = 0; i < values.size(); i++) { - Point2D

p = values.get(i); + Point2D p = values.get(i); if(p.getArea() < minAreaLimit) { values.flag(i); @@ -1106,14 +1104,14 @@ private void filterMinimums() { values.removeFlagged(); } - private boolean canMoveX(Point2D

p, int xx) { + private boolean canMoveX(Point2D p, int xx) { if(p.getMaxX() < xx) { return false; } return p.getAreaAtX(xx) >= minAreaLimit; } - private boolean canMoveY(Point2D

p, int yy) { + private boolean canMoveY(Point2D p, int yy) { if(p.getMaxY() < yy) { return false; } diff --git a/api/src/main/java/com/github/skjolber/packing/api/ep/Point2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2D.java similarity index 85% rename from api/src/main/java/com/github/skjolber/packing/api/ep/Point2D.java rename to extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2D.java index 64e73f2b..bf010758 100644 --- a/api/src/main/java/com/github/skjolber/packing/api/ep/Point2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2D.java @@ -1,19 +1,18 @@ -package com.github.skjolber.packing.api.ep; +package com.github.skjolber.packing.ep.points2d; import java.io.Serializable; import java.util.Comparator; -import com.github.skjolber.packing.api.Placement2D; import com.github.skjolber.packing.api.StackValue; -public abstract class Point2D

implements Serializable { +public abstract class Point2D implements Serializable { private static final long serialVersionUID = 1L; - public static final Comparator> COMPARATOR_X_THEN_Y = new Comparator>() { + public static final Comparator COMPARATOR_X_THEN_Y = new Comparator() { @Override - public int compare(Point2D o1, Point2D o2) { + public int compare(Point2D o1, Point2D o2) { if(o1.minX < o2.minX) { return -1; } else if(o1.minX != o2.minX) { @@ -36,10 +35,10 @@ public int compare(Point2D o1, Point2D o2) { } }; - public static final Comparator> COMPARATOR_MOVE_YY = new Comparator>() { + public static final Comparator COMPARATOR_MOVE_YY = new Comparator() { @Override - public int compare(Point2D o1, Point2D o2) { + public int compare(Point2D o1, Point2D o2) { if(o1.minX < o2.minX) { return -1; } else if(o1.minX != o2.minX) { @@ -56,10 +55,10 @@ public int compare(Point2D o1, Point2D o2) { } }; - public static final Comparator> COMPARATOR_MOVE_XX = new Comparator>() { + public static final Comparator COMPARATOR_MOVE_XX = new Comparator() { @Override - public int compare(Point2D o1, Point2D o2) { + public int compare(Point2D o1, Point2D o2) { if(o1.minY < o2.minY) { return -1; } else if(o1.minY != o2.minY) { @@ -207,7 +206,7 @@ public int getDx() { return dx; } - public boolean intersects(Point2D

point) { + public boolean intersects(Point2D point) { return !(point.getMaxX() < minX || point.getMinX() > maxX || point.getMaxY() < minY || point.getMinY() > maxY); } @@ -268,28 +267,28 @@ public String toString() { return "Point2D [" + minX + "x" + minY + " " + maxX + "x" + maxY + "]"; } - public abstract Point2D

clone(int maxX, int maxY); + public abstract Point2D clone(int maxX, int maxY); - public boolean eclipses(Point2D

point) { + public boolean eclipses(Point2D point) { return minY <= point.getMinY() && minX <= point.getMinX() && point.getMaxX() <= maxX && point.getMaxY() <= maxY; } - public boolean eclipsesMovedX(Point2D

point, int x) { + public boolean eclipsesMovedX(Point2D point, int x) { return minX <= x && point.getMaxX() <= maxX && eclipsesY(point); } - public boolean eclipsesMovedY(Point2D

point, int y) { + public boolean eclipsesMovedY(Point2D point, int y) { return minY <= y && point.getMaxY() <= maxY && eclipsesX(point); } - public boolean eclipsesX(Point2D

point) { + public boolean eclipsesX(Point2D point) { return minX <= point.getMinX() && point.getMaxX() <= maxX; } - public boolean eclipsesY(Point2D

point) { + public boolean eclipsesY(Point2D point) { return minY <= point.getMinY() && point.getMaxY() <= maxY; } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DFlagList.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DFlagList.java index d0998d9c..93b9b961 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DFlagList.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DFlagList.java @@ -1,14 +1,10 @@ package com.github.skjolber.packing.ep.points2d; -import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.List; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; - /** * * Custom list for working with to-be-removed points. @@ -16,10 +12,10 @@ */ @SuppressWarnings("unchecked") -public class Point2DFlagList

{ +public class Point2DFlagList { private int size = 0; - private SimplePoint2D

[] points = new SimplePoint2D[16]; + private SimplePoint2D[] points = new SimplePoint2D[16]; private boolean[] flag = new boolean[16]; public void ensureAdditionalCapacity(int count) { @@ -28,7 +24,7 @@ public void ensureAdditionalCapacity(int count) { public void ensureCapacity(int size) { if(points.length < size) { - SimplePoint2D

[] nextPoints = new SimplePoint2D[size]; + SimplePoint2D[] nextPoints = new SimplePoint2D[size]; System.arraycopy(this.points, 0, nextPoints, 0, this.size); boolean[] nextFlag = new boolean[size]; @@ -39,12 +35,12 @@ public void ensureCapacity(int size) { } } - public void add(SimplePoint2D

point) { + public void add(SimplePoint2D point) { points[size] = point; size++; } - public void sort(Comparator> comparator) { + public void sort(Comparator comparator) { Arrays.sort(points, 0, size, comparator); } @@ -52,7 +48,7 @@ public int size() { return size; } - public SimplePoint2D

get(int i) { + public SimplePoint2D get(int i) { return points[i]; } @@ -95,7 +91,7 @@ public void move(int offset) { this.size += offset; } - public void copyInto(Point2DFlagList

destination) { + public void copyInto(Point2DFlagList destination) { destination.ensureCapacity(size); System.arraycopy(points, 0, destination.points, 0, size); @@ -120,22 +116,22 @@ public int removeFlagged() { return index - offset; } - public List> toList() { - List> list = new ArrayList<>(); + public List toList() { + List list = new ArrayList<>(); for (int i = 0; i < size; i++) { list.add(points[i]); } return list; } - public SimplePoint2D

[] getPoints() { + public SimplePoint2D[] getPoints() { return points; } /** * Returns the hash code value for this list. * - *

+ * * This implementation uses exactly the code that is used to define the * list hash function in the documentation for the {@link List#hashCode} * method. @@ -155,7 +151,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if(obj instanceof Point2DFlagList) { - Point2DFlagList

other = (Point2DFlagList

)obj; + Point2DFlagList other = (Point2DFlagList)obj; if(other.size() == size) { for (int i = 0; i < size; i++) { if(!points[i].equals(other.get(i))) { @@ -171,7 +167,7 @@ public boolean equals(Object obj) { return super.equals(obj); } - public void setAll(Point2DList> add, int offset) { + public void setAll(Point2DList add, int offset) { System.arraycopy(add.getPoints(), 0, points, offset, add.size()); int limit = offset + add.size(); for (int i = offset; i < limit; i++) { @@ -180,7 +176,7 @@ public void setAll(Point2DList> add, int offset) { } - public void sort(Comparator> comparator, int maxSize) { + public void sort(Comparator comparator, int maxSize) { Arrays.sort(points, 0, maxSize, comparator); } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DList.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DList.java index 4dd7293f..2b04dbd1 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DList.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/Point2DList.java @@ -2,9 +2,6 @@ import java.util.List; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; - /** * * Custom list for working with points. @@ -12,10 +9,10 @@ */ @SuppressWarnings("unchecked") -public class Point2DList

> { +public class Point2DList { private int size = 0; - private Point2D

[] points = new Point2D[16]; + private Point2D[] points = new Point2D[16]; public void ensureAdditionalCapacity(int count) { ensureCapacity(size + count); @@ -23,13 +20,13 @@ public void ensureAdditionalCapacity(int count) { public void ensureCapacity(int size) { if(points.length < size) { - Point2D

[] nextPoints = new Point2D[size]; + Point2D[] nextPoints = new Point2D[size]; System.arraycopy(this.points, 0, nextPoints, 0, this.size); this.points = nextPoints; } } - public void add(Point point) { + public void add(Point2D point) { points[size] = point; size++; } @@ -45,8 +42,8 @@ public void reset() { size = 0; } - public Point get(int i) { - return (Point)points[i]; + public Point2D get(int i) { + return points[i]; } public boolean isEmpty() { @@ -60,7 +57,7 @@ public void clear() { /** * Returns the hash code value for this list. * - *

+ * * This implementation uses exactly the code that is used to define the * list hash function in the documentation for the {@link List#hashCode} * method. @@ -78,7 +75,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if(obj instanceof Point2DList) { - Point2DList other = (Point2DList)obj; + Point2DList other = (Point2DList)obj; if(other.size() == size) { for (int i = 0; i < size; i++) { if(!points[i].equals(other.get(i))) { @@ -91,7 +88,7 @@ public boolean equals(Object obj) { return super.equals(obj); } - public Point2D

[] getPoints() { + public Point2D[] getPoints() { return points; } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/SimplePoint2D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/SimplePoint2D.java index 0a1004ea..8748b344 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/SimplePoint2D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points2d/SimplePoint2D.java @@ -2,10 +2,9 @@ import java.io.Serializable; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.StackPlacement; -public abstract class SimplePoint2D

extends Point2D

{ +public abstract class SimplePoint2D extends Point2D { public SimplePoint2D(int minX, int minY, int maxX, int maxY) { super(minX, minY, maxX, maxY); @@ -28,7 +27,7 @@ public SimplePoint2D(int minX, int minY, int maxX, int maxY) { // |---------x=================== // - public abstract SimplePoint2D

moveX(int x); + public abstract SimplePoint2D moveX(int x); // | // | @@ -49,7 +48,7 @@ public SimplePoint2D(int minX, int minY, int maxX, int maxY) { // |---------x=================== // - public abstract SimplePoint2D

moveX(int x, P ySupport); + public abstract SimplePoint2D moveX(int x, StackPlacement ySupport); // // | â•‘ @@ -79,7 +78,7 @@ public SimplePoint2D(int minX, int minY, int maxX, int maxY) { // | // |--------------------------- - public abstract SimplePoint2D

moveY(int y); + public abstract SimplePoint2D moveY(int y); // // | â•‘ @@ -109,6 +108,6 @@ public SimplePoint2D(int minX, int minY, int maxX, int maxY) { // | // |--------------------------- - public abstract SimplePoint2D

moveY(int y, P xSupport); + public abstract SimplePoint2D moveY(int y, StackPlacement xSupport); } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntXComparator.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntXComparator.java index b22e3e77..6ccc8786 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntXComparator.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntXComparator.java @@ -8,13 +8,13 @@ public class CustomIntXComparator implements IntComparator { private static final long serialVersionUID = 1L; - private Point3DFlagList values; + private Point3DFlagList values; private int xx; @Override public int compare(int value1, int value2) { - Point3D o1 = values.get(value1); - Point3D o2 = values.get(value2); + Point3D o1 = values.get(value1); + Point3D o2 = values.get(value2); if(o1.getMinY() < o2.getMinY()) { return -1; @@ -38,7 +38,7 @@ public void setXx(int xx) { this.xx = xx; } - public void setValues(Point3DFlagList values) { + public void setValues(Point3DFlagList values) { this.values = values; } } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntYComparator.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntYComparator.java index 9c21a055..fc670f2c 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntYComparator.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntYComparator.java @@ -8,13 +8,13 @@ public class CustomIntYComparator implements IntComparator { private static final long serialVersionUID = 1L; - private Point3DFlagList values; + private Point3DFlagList values; private int yy; @Override public int compare(int value1, int value2) { - Point3D o1 = values.get(value1); - Point3D o2 = values.get(value2); + Point3D o1 = values.get(value1); + Point3D o2 = values.get(value2); if(o1.getMinZ() < o2.getMinZ()) { return -1; @@ -38,7 +38,7 @@ public void setYy(int yy) { this.yy = yy; } - public void setValues(Point3DFlagList values) { + public void setValues(Point3DFlagList values) { this.values = values; } } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntZComparator.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntZComparator.java index bd244ec6..c5d3bea0 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntZComparator.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/CustomIntZComparator.java @@ -8,13 +8,13 @@ public class CustomIntZComparator implements IntComparator { private static final long serialVersionUID = 1L; - private Point3DFlagList values; + private Point3DFlagList values; private int zz; @Override public int compare(int value1, int value2) { - Point3D o1 = values.get(value1); - Point3D o2 = values.get(value2); + Point3D o1 = values.get(value1); + Point3D o2 = values.get(value2); if(o1.getMinX() < o2.getMinX()) { return -1; @@ -38,7 +38,7 @@ public void setZz(int zz) { this.zz = zz; } - public void setValues(Point3DFlagList values) { + public void setValues(Point3DFlagList values) { this.values = values; } } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Default3DPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Default3DPlanePoint3D.java index ccaf37fa..52f965be 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Default3DPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Default3DPlanePoint3D.java @@ -1,29 +1,27 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class Default3DPlanePoint3D

extends SimplePoint3D

implements XZPlanePoint3D, YZPlanePoint3D, XYPlanePoint3D { +public class Default3DPlanePoint3D extends SimplePoint3D implements XZPlanePoint3D, YZPlanePoint3D, XYPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minX */ - private final P yzPlane; + private final StackPlacement yzPlane; /** range constrained to current minY */ - private final P xzPlane; + private final StackPlacement xzPlane; /** range constrained to current minZ */ - private final P xyPlane; + private final StackPlacement xyPlane; public Default3DPlanePoint3D( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P yzPlane, - P xzPlane, - P xyPlane) { + StackPlacement yzPlane, + StackPlacement xzPlane, + StackPlacement xyPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.yzPlane = yzPlane; @@ -125,129 +123,129 @@ public boolean isXYPlaneEdgeY(int y) { } @Override - public Default3DPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new Default3DPlanePoint3D<>(minX, minY, minZ, + public Default3DPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new Default3DPlanePoint3D(minX, minY, minZ, maxX, maxY, maxZ, yzPlane, xzPlane, xyPlane); } - public Placement3D getXZPlane() { + public StackPlacement getXZPlane() { return xzPlane; } - public Placement3D getYZPlane() { + public StackPlacement getYZPlane() { return yzPlane; } - public Placement3D getXYPlane() { + public StackPlacement getXYPlane() { return xyPlane; } @Override - public Default3DPlanePoint3D

clone() { - return new Default3DPlanePoint3D<>(minX, minY, minZ, maxX, maxY, maxZ, yzPlane, xzPlane, xyPlane); + public Default3DPlanePoint3D clone() { + return new Default3DPlanePoint3D(minX, minY, minZ, maxX, maxY, maxZ, yzPlane, xzPlane, xyPlane); } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { boolean withinXYPlane = x <= xyPlane.getAbsoluteEndX(); boolean withinXZPlane = x <= xzPlane.getAbsoluteEndX(); // yz plane support lost if(withinXYPlane && withinXZPlane) { - return new DefaultXYPlaneXZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane, xyPlane); + return new DefaultXYPlaneXZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xyPlane); } else if(withinXZPlane) { - return new DefaultXZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane); } - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { boolean withinXYPlane = x <= xyPlane.getAbsoluteEndX(); boolean withinXZPlane = x <= xzPlane.getAbsoluteEndX(); // yz plane support lost if(withinXYPlane && withinXZPlane) { - return new Default3DPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xzPlane, xyPlane); + return new Default3DPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xzPlane, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); + return new DefaultXYPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); } else if(withinXZPlane) { - return new DefaultXZPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); + return new DefaultXZPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); } - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { boolean withinXYPlane = y <= xyPlane.getAbsoluteEndY(); boolean withinYZPlane = y <= yzPlane.getAbsoluteEndY(); // xz plane support lost if(withinXYPlane && withinYZPlane) { - return new DefaultXYPlaneYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xyPlane); + return new DefaultXYPlaneYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xyPlane); } else if(withinYZPlane) { - return new DefaultYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane); } - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { boolean withinXYPlane = y <= xyPlane.getAbsoluteEndY(); boolean withinYZPlane = y <= yzPlane.getAbsoluteEndY(); if(withinXYPlane && withinYZPlane) { - return new Default3DPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xzSupport, xyPlane); + return new Default3DPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xzSupport, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); + return new DefaultXYPlaneXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); } else if(withinYZPlane) { - return new DefaultXZPlaneYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); + return new DefaultXZPlaneYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); } - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { boolean withinXZPlane = z <= xzPlane.getAbsoluteEndZ(); boolean withinYZPlane = z <= yzPlane.getAbsoluteEndZ(); // xy plane support lost if(withinXZPlane && withinYZPlane) { - return new DefaultXZPlaneYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane, yzPlane); + return new DefaultXZPlaneYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane, yzPlane); } else if(withinXZPlane) { - return new DefaultXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane); } else if(withinYZPlane) { - return new DefaultYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane); } // all previous support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { boolean withinXZPlane = z <= xzPlane.getAbsoluteEndZ(); boolean withinYZPlane = z <= yzPlane.getAbsoluteEndZ(); if(withinXZPlane && withinYZPlane) { - return new Default3DPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane, xzPlane, xySupport); + return new Default3DPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane, xzPlane, xySupport); } else if(withinXZPlane) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); + return new DefaultXYPlaneXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); } else if(withinYZPlane) { - return new DefaultXYPlaneYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); + return new DefaultXYPlaneYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); } // all previous support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -257,8 +255,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPlacement3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPlacement3D.java deleted file mode 100644 index ff12243a..00000000 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPlacement3D.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.github.skjolber.packing.ep.points3d; - -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.Placement3D; - -public class DefaultPlacement3D implements Placement3D, Serializable { - - private static final long serialVersionUID = 1L; - - protected final int x; - protected final int y; - protected final int z; - protected final int endX; - protected final int endY; - protected final int endZ; - - // protected final List supports; - - public DefaultPlacement3D(int x, int y, int z, int endX, int endY, int endZ) { - this.x = x; - this.y = y; - this.z = z; - this.endX = endX; - this.endY = endY; - this.endZ = endZ; - } - - @Override - public int getAbsoluteX() { - return x; - } - - @Override - public int getAbsoluteY() { - return y; - } - - @Override - public int getAbsoluteEndX() { - return endX; - } - - @Override - public int getAbsoluteEndY() { - return endY; - } - - @Override - public boolean intersects2D(Placement2D point) { - return !(point.getAbsoluteEndX() < x || point.getAbsoluteX() > endX || point.getAbsoluteEndY() < y || point.getAbsoluteY() > endY); - } - - @Override - public boolean intersects3D(Placement3D point) { - return !(point.getAbsoluteEndX() < x || point.getAbsoluteX() > endX || point.getAbsoluteEndY() < y || point.getAbsoluteY() > endY || point.getAbsoluteEndZ() < z - || point.getAbsoluteZ() > endZ); - } - - @Override - public int getAbsoluteZ() { - return z; - } - - @Override - public int getAbsoluteEndZ() { - return endZ; - } - - @Override - public String toString() { - return "DefaultPlacement3D [" + x + "x" + y + "x" + z + " " + endX + "x" + endY + "x" + endZ + "]"; - } - - /* - @Override - public List getSupports3D() { - return (List) supports; - } - - @Override - public List getSupports2D() { - return supports; - } - */ -} diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPoint3D.java index 3c092a86..aa269aed 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultPoint3D.java @@ -1,12 +1,9 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultPoint3D

extends SimplePoint3D

{ +public class DefaultPoint3D extends SimplePoint3D { private static final long serialVersionUID = 1L; @@ -15,43 +12,38 @@ public DefaultPoint3D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ } @Override - public DefaultPoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultPoint3D<>(minX, minY, minZ, maxX, maxY, maxZ); - } - - @Override - public Point2D

clone(int maxX, int maxY) { - return clone(maxX, maxY, this.maxZ); + public DefaultPoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultPoint3D(minX, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x) { - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + public SimplePoint3D moveX(int x) { + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + public SimplePoint3D moveY(int y) { + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + public SimplePoint3D moveZ(int z) { + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -61,8 +53,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlanePoint3D.java index 39d27237..dac407a2 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlanePoint3D.java @@ -1,21 +1,19 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultXYPlanePoint3D

extends SimplePoint3D

implements XYPlanePoint3D { +public class DefaultXYPlanePoint3D extends SimplePoint3D implements XYPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minZ */ - private final P xyPlane; + private final StackPlacement xyPlane; public DefaultXYPlanePoint3D( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P xyPlane) { + StackPlacement xyPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.xyPlane = xyPlane; } @@ -51,64 +49,64 @@ public boolean isXYPlaneEdgeY(int y) { return xyPlane.getAbsoluteEndY() == y - 1; } - public Placement3D getXYPlane() { + public StackPlacement getXYPlane() { return xyPlane; } @Override - public DefaultXYPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultXYPlanePoint3D<>( + public DefaultXYPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultXYPlanePoint3D( minX, minY, minZ, maxX, maxY, maxZ, xyPlane); } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { if(x <= xyPlane.getAbsoluteEndX()) { - return new DefaultXYPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xyPlane); } // xyPlane support is lost - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { if(x <= xyPlane.getAbsoluteEndX()) { - return new DefaultXYPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); + return new DefaultXYPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); } // xyPlane support is lost - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { if(y <= xyPlane.getAbsoluteEndY()) { - return new DefaultXYPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xyPlane); } // xyPlane support is lost - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { if(y <= xyPlane.getAbsoluteEndY()) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); + return new DefaultXYPlaneXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); } // xyPlane support is lost - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { // xyPlane support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { // xyPlane support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -118,8 +116,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneXZPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneXZPlanePoint3D.java index 6f772d1d..dadb0238 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneXZPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneXZPlanePoint3D.java @@ -1,25 +1,23 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultXYPlaneXZPlanePoint3D

extends SimplePoint3D

implements XYPlanePoint3D, XZPlanePoint3D { +public class DefaultXYPlaneXZPlanePoint3D extends SimplePoint3D implements XYPlanePoint3D, XZPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minY */ - private final P xzPlane; + private final StackPlacement xzPlane; /** range constrained to current minZ */ - private final P xyPlane; + private final StackPlacement xyPlane; public DefaultXYPlaneXZPlanePoint3D( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P xzPlane, - P xyPlane) { + StackPlacement xzPlane, + StackPlacement xyPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.xzPlane = xzPlane; @@ -89,87 +87,87 @@ public boolean isXYPlaneEdgeY(int y) { } @Override - public DefaultXYPlaneXZPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, minY, minZ, maxX, maxY, maxZ, xzPlane, xyPlane); + public DefaultXYPlaneXZPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultXYPlaneXZPlanePoint3D(minX, minY, minZ, maxX, maxY, maxZ, xzPlane, xyPlane); } - public Placement3D getXZPlane() { + public StackPlacement getXZPlane() { return xzPlane; } - public Placement3D getXYPlane() { + public StackPlacement getXYPlane() { return xyPlane; } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { boolean withinXYPlane = x <= xyPlane.getAbsoluteEndX(); boolean withinXZPlane = x <= xzPlane.getAbsoluteEndX(); if(withinXYPlane && withinXZPlane) { - return new DefaultXYPlaneXZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane, xyPlane); + return new DefaultXYPlaneXZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xyPlane); } else if(withinXZPlane) { - return new DefaultXZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane); } - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { boolean withinXYPlane = x <= xyPlane.getAbsoluteEndX(); boolean withinXZPlane = x <= xzPlane.getAbsoluteEndX(); if(withinXYPlane && withinXZPlane) { - return new Default3DPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xzPlane, xyPlane); + return new Default3DPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xzPlane, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); + return new DefaultXYPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); } else if(withinXZPlane) { - return new DefaultXZPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); + return new DefaultXZPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); } - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { // xz plane support is lost if(y <= xyPlane.getAbsoluteEndY()) { - return new DefaultXYPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xyPlane); } // all previous support is lost - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { // xz plane support is lost if(y <= xyPlane.getAbsoluteEndY()) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); + return new DefaultXYPlaneXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); } // all previous support is lost - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { // xy plane support is lost if(z <= xzPlane.getAbsoluteEndZ()) { - return new DefaultXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane); } // all previous support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { if(z <= xzPlane.getAbsoluteEndZ()) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); + return new DefaultXYPlaneXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); } // all previous support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -179,8 +177,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneYZPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneYZPlanePoint3D.java index 4a2509e4..f795bad7 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneYZPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXYPlaneYZPlanePoint3D.java @@ -1,23 +1,21 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultXYPlaneYZPlanePoint3D

extends SimplePoint3D

implements XYPlanePoint3D, YZPlanePoint3D { +public class DefaultXYPlaneYZPlanePoint3D extends SimplePoint3D implements XYPlanePoint3D, YZPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minX */ - private final P yzPlane; + private final StackPlacement yzPlane; /** range constrained to current minZ */ - private final P xyPlane; - + private final StackPlacement xyPlane; + public DefaultXYPlaneYZPlanePoint3D(int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P yzPlane, - P xyPlane) { + StackPlacement yzPlane, + StackPlacement xyPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.yzPlane = yzPlane; @@ -55,7 +53,7 @@ public boolean isYZPlaneEdgeY(int y) { return yzPlane.getAbsoluteEndY() == y - 1; } - public Placement3D getYZPlane() { + public StackPlacement getYZPlane() { return yzPlane; } @@ -90,87 +88,87 @@ public boolean isXYPlaneEdgeY(int y) { return xyPlane.getAbsoluteEndY() == y - 1; } - public Placement3D getXYPlane() { + public StackPlacement getXYPlane() { return xyPlane; } @Override - public DefaultXYPlaneYZPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultXYPlaneYZPlanePoint3D<>( + public DefaultXYPlaneYZPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultXYPlaneYZPlanePoint3D( minX, minY, minZ, maxX, maxY, maxZ, yzPlane, xyPlane); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { boolean withinXYPlane = y <= xyPlane.getAbsoluteEndY(); boolean withinYZPlane = y <= yzPlane.getAbsoluteEndY(); if(withinXYPlane && withinYZPlane) { - return new DefaultXYPlaneYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xyPlane); + return new DefaultXYPlaneYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xyPlane); } else if(withinYZPlane) { - return new DefaultYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane); } - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { boolean withinXYPlane = y <= xyPlane.getAbsoluteEndY(); boolean withinYZPlane = y <= yzPlane.getAbsoluteEndY(); if(withinXYPlane && withinYZPlane) { - return new Default3DPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xzSupport, xyPlane); + return new Default3DPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane, xzSupport, xyPlane); } else if(withinXYPlane) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); + return new DefaultXYPlaneXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, xyPlane); } else if(withinYZPlane) { - return new DefaultXZPlaneYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); + return new DefaultXZPlaneYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); } - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { // yz plane support is lost if(x <= xyPlane.getAbsoluteEndX()) { - return new DefaultXYPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xyPlane); + return new DefaultXYPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xyPlane); } // all previous support is lost - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { if(x <= xyPlane.getAbsoluteEndX()) { - return new DefaultXYPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); + return new DefaultXYPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport, xyPlane); } // all previous support is lost - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { // xy plane support is lost if(z <= yzPlane.getAbsoluteEndZ()) { - return new DefaultYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane); } // all previous support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { // xy plane support is lost if(z <= yzPlane.getAbsoluteEndZ()) { - return new DefaultXYPlaneYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); + return new DefaultXYPlaneYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); } // all previous support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -180,8 +178,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlanePoint3D.java index d9d25c32..bbf7a36d 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlanePoint3D.java @@ -1,22 +1,20 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultXZPlanePoint3D

extends SimplePoint3D

implements XZPlanePoint3D { +public class DefaultXZPlanePoint3D extends SimplePoint3D implements XZPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minY */ - private final P xzPlane; + private final StackPlacement xzPlane; public DefaultXZPlanePoint3D( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P xzPlane) { + StackPlacement xzPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.xzPlane = xzPlane; @@ -54,63 +52,63 @@ public boolean isXZPlaneEdgeZ(int z) { } @Override - public DefaultXZPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultXZPlanePoint3D<>( + public DefaultXZPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultXZPlanePoint3D( minX, minY, minZ, maxX, maxY, maxZ, xzPlane); } - public Placement3D getXZPlane() { + public StackPlacement getXZPlane() { return xzPlane; } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { if(x <= xzPlane.getAbsoluteEndX()) { - return new DefaultXZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane); } // xzPlane support is lost - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { if(x <= xzPlane.getAbsoluteEndX()) { - return new DefaultXZPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); + return new DefaultXZPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); } // xzPlane support is lost - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { // xzPlane support is lost - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { // xzPlane support is lost - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { if(z <= xzPlane.getAbsoluteEndZ()) { - return new DefaultXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane); } // all previous plane support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { if(z <= xzPlane.getAbsoluteEndZ()) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); + return new DefaultXYPlaneXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); } // all previous plane support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -120,8 +118,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlaneYZPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlaneYZPlanePoint3D.java index a1750cde..1cd82530 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlaneYZPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultXZPlaneYZPlanePoint3D.java @@ -1,25 +1,23 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultXZPlaneYZPlanePoint3D

extends SimplePoint3D

implements XZPlanePoint3D, YZPlanePoint3D { +public class DefaultXZPlaneYZPlanePoint3D extends SimplePoint3D implements XZPlanePoint3D, YZPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minY */ - private final P xzPlane; + private final StackPlacement xzPlane; /** range constrained to current minX */ - private final P yzPlane; + private final StackPlacement yzPlane; public DefaultXZPlaneYZPlanePoint3D( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P xzPlane, - P yzPlane) { + StackPlacement xzPlane, + StackPlacement yzPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.xzPlane = xzPlane; @@ -97,90 +95,90 @@ public boolean isYZPlaneEdgeY(int y) { } @Override - public DefaultXZPlaneYZPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultXZPlaneYZPlanePoint3D<>( + public DefaultXZPlaneYZPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultXZPlaneYZPlanePoint3D( minX, minY, minZ, maxX, maxY, maxZ, xzPlane, yzPlane); } - public Placement3D getXZPlane() { + public StackPlacement getXZPlane() { return xzPlane; } - public Placement3D getYZPlane() { + public StackPlacement getYZPlane() { return yzPlane; } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { // yzPlane support is lost if(x <= xzPlane.getAbsoluteEndX()) { - return new DefaultXZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane); } // all previous support is lost - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { if(x <= xzPlane.getAbsoluteEndX()) { - return new DefaultXZPlaneYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); + return new DefaultXZPlaneYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, xzPlane, yzSupport); } // xzPlane support is lost - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { if(y <= yzPlane.getAbsoluteEndY()) { - return new DefaultYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane); } // all previous support is lost - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { if(y <= yzPlane.getAbsoluteEndY()) { - return new DefaultXZPlaneYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); + return new DefaultXZPlaneYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); } // yz plane support is lost - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { boolean withinXZPlane = z <= xzPlane.getAbsoluteEndZ(); boolean withinYZPlane = z <= yzPlane.getAbsoluteEndZ(); if(withinXZPlane && withinYZPlane) { - return new DefaultXZPlaneYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane, yzPlane); + return new DefaultXZPlaneYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane, yzPlane); } else if(withinXZPlane) { - return new DefaultXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane); + return new DefaultXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane); } else if(withinYZPlane) { - return new DefaultYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane); } // all previous support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { boolean withinXZPlane = z <= xzPlane.getAbsoluteEndZ(); boolean withinYZPlane = z <= yzPlane.getAbsoluteEndZ(); if(withinXZPlane && withinYZPlane) { - return new Default3DPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane, xzPlane, xySupport); + return new Default3DPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane, xzPlane, xySupport); } else if(withinXZPlane) { - return new DefaultXYPlaneXZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); + return new DefaultXYPlaneXZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xzPlane, xySupport); } else if(withinYZPlane) { - return new DefaultXYPlaneYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); + return new DefaultXYPlaneYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); } // all previous support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -190,8 +188,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultYZPlanePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultYZPlanePoint3D.java index 30cb3c6d..44aa158f 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultYZPlanePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/DefaultYZPlanePoint3D.java @@ -1,21 +1,19 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public class DefaultYZPlanePoint3D

extends SimplePoint3D

implements YZPlanePoint3D { +public class DefaultYZPlanePoint3D extends SimplePoint3D implements YZPlanePoint3D { private static final long serialVersionUID = 1L; /** range constrained to current minX */ - private final P yzPlane; + private final StackPlacement yzPlane; public DefaultYZPlanePoint3D( int minX, int minY, int minZ, int maxX, int maxY, int maxZ, - P yzPlane) { + StackPlacement yzPlane) { super(minX, minY, minZ, maxX, maxY, maxZ); this.yzPlane = yzPlane; @@ -52,61 +50,61 @@ public boolean isYZPlaneEdgeY(int y) { return yzPlane.getAbsoluteEndY() == y - 1; } - public Placement3D getYZPlane() { + public StackPlacement getYZPlane() { return yzPlane; } @Override - public DefaultYZPlanePoint3D

clone(int maxX, int maxY, int maxZ) { - return new DefaultYZPlanePoint3D<>(minX, minY, minZ, maxX, maxY, maxZ, yzPlane); + public DefaultYZPlanePoint3D clone(int maxX, int maxY, int maxZ) { + return new DefaultYZPlanePoint3D(minX, minY, minZ, maxX, maxY, maxZ, yzPlane); } @Override - public SimplePoint3D

moveX(int x) { + public SimplePoint3D moveX(int x) { // xzPlane support is lost - return new DefaultPoint3D<>(x, minY, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(x, minY, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveX(int x, P yzSupport) { + public SimplePoint3D moveX(int x, StackPlacement yzSupport) { // xzPlane support is lost - return new DefaultYZPlanePoint3D<>(x, minY, minZ, maxX, maxY, maxZ, yzSupport); + return new DefaultYZPlanePoint3D(x, minY, minZ, maxX, maxY, maxZ, yzSupport); } @Override - public SimplePoint3D

moveY(int y) { + public SimplePoint3D moveY(int y) { // xzPlane support is lost if(y <= yzPlane.getAbsoluteEndY()) { - return new DefaultYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, yzPlane); } - return new DefaultPoint3D<>(minX, y, minZ, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, y, minZ, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveY(int y, P xzSupport) { + public SimplePoint3D moveY(int y, StackPlacement xzSupport) { // xzPlane support is lost if(y <= yzPlane.getAbsoluteEndY()) { - return new DefaultXZPlaneYZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); + return new DefaultXZPlaneYZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport, yzPlane); } - return new DefaultXZPlanePoint3D<>(minX, y, minZ, maxX, maxY, maxZ, xzSupport); + return new DefaultXZPlanePoint3D(minX, y, minZ, maxX, maxY, maxZ, xzSupport); } @Override - public SimplePoint3D

moveZ(int z) { + public SimplePoint3D moveZ(int z) { if(z <= yzPlane.getAbsoluteEndZ()) { - return new DefaultYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane); + return new DefaultYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane); } // all previous plane support is lost - return new DefaultPoint3D<>(minX, minY, z, maxX, maxY, maxZ); + return new DefaultPoint3D(minX, minY, z, maxX, maxY, maxZ); } @Override - public SimplePoint3D

moveZ(int z, P xySupport) { + public SimplePoint3D moveZ(int z, StackPlacement xySupport) { if(z <= yzPlane.getAbsoluteEndZ()) { - return new DefaultXYPlaneYZPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); + return new DefaultXYPlaneYZPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, yzPlane, xySupport); } // all previous plane support is lost - return new DefaultXYPlanePoint3D<>(minX, minY, z, maxX, maxY, maxZ, xySupport); + return new DefaultXYPlanePoint3D(minX, minY, z, maxX, maxY, maxZ, xySupport); } /** @@ -116,8 +114,8 @@ public SimplePoint3D

moveZ(int z, P xySupport) { */ @Override - public Point3D

rotate() { - return new DefaultPoint3D<>(minY, minZ, minX, maxY, maxZ, maxX); + public Point3D rotate() { + return new DefaultPoint3D(minY, minZ, minX, maxY, maxZ, maxX); } @Override diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/ExtremePoints3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/ExtremePoints3D.java index 1c30e46e..eed91184 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/ExtremePoints3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/ExtremePoints3D.java @@ -1,13 +1,13 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList; -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.ExtremePoints; import com.github.skjolber.packing.api.ep.Point3D; @@ -17,11 +17,11 @@ * */ -public class ExtremePoints3D

implements ExtremePoints> { - public static final Comparator> COMPARATOR_X = new Comparator>() { +public class ExtremePoints3D implements ExtremePoints { + public static final Comparator COMPARATOR_X = new Comparator() { @Override - public int compare(Point3D o1, Point3D o2) { + public int compare(Point3D o1, Point3D o2) { return Integer.compare(o1.getMinX(), o2.getMinX()); } }; @@ -34,32 +34,32 @@ public int compare(Point3D o1, Point3D o2) { protected long minVolumeLimit = 0; protected long minAreaLimit = 0; - protected Point3DFlagList

values = new Point3DFlagList<>(); // i.e. current (input) values - protected Point3DFlagList

otherValues = new Point3DFlagList<>(); // i.e. next (output) values + protected Point3DFlagList values = new Point3DFlagList(); // i.e. current (input) values + protected Point3DFlagList otherValues = new Point3DFlagList(); // i.e. next (output) values - protected ArrayList

placements = new ArrayList<>(); + protected ArrayList placements = new ArrayList<>(); // reuse working variables - protected final Point3DListArray

addXX = new Point3DListArray<>(); - protected final Point3DListArray

addYY = new Point3DListArray<>(); - protected final Point3DListArray

addZZ = new Point3DListArray<>(); + protected final Point3DListArray addXX = new Point3DListArray(); + protected final Point3DListArray addYY = new Point3DListArray(); + protected final Point3DListArray addZZ = new Point3DListArray(); - protected final Point3DArray

constrainXX = new Point3DArray<>(); - protected final Point3DArray

constrainYY = new Point3DArray<>(); - protected final Point3DArray

constrainZZ = new Point3DArray<>(); + protected final Point3DArray constrainXX = new Point3DArray(); + protected final Point3DArray constrainYY = new Point3DArray(); + protected final Point3DArray constrainZZ = new Point3DArray(); protected final IntArrayList moveToXX = new IntArrayList(); protected final IntArrayList moveToYY = new IntArrayList(); protected final IntArrayList moveToZZ = new IntArrayList(); - protected final List> addedXX = new ArrayList<>(128); - protected final List> addedYY = new ArrayList<>(128); - protected final List> addedZZ = new ArrayList<>(128); + protected final List addedXX = new ArrayList<>(128); + protected final List addedYY = new ArrayList<>(128); + protected final List addedZZ = new ArrayList<>(128); protected final boolean cloneOnConstrain; - protected P containerPlacement; - protected Default3DPlanePoint3D

firstPoint; + protected StackPlacement containerPlacement; + protected Default3DPlanePoint3D firstPoint; protected CustomIntXComparator xxComparator = new CustomIntXComparator(); protected CustomIntYComparator yyComparator = new CustomIntYComparator(); @@ -83,7 +83,7 @@ protected void setSize(int dx, int dy, int dz) { this.containerPlacement = createContainerPlacement(); - this.firstPoint = new Default3DPlanePoint3D<>( + this.firstPoint = new Default3DPlanePoint3D( 0, 0, 0, containerMaxX, containerMaxY, containerMaxZ, containerPlacement, @@ -92,11 +92,14 @@ protected void setSize(int dx, int dy, int dz) { } @SuppressWarnings("unchecked") - private P createContainerPlacement() { - return (P)new DefaultPlacement3D(0, 0, 0, containerMaxX, containerMaxY, containerMaxZ); + private StackPlacement createContainerPlacement() { + + BoxStackValue value = new BoxStackValue(containerMaxX + 1, containerMaxY + 1, containerMaxY + 1, null, null); + + return new StackPlacement(null, value, 0, 0, 0); } - public boolean add(int index, P placement) { + public boolean add(int index, StackPlacement placement) { // overall approach: // Do not iterate over placements to find point max / mins, rather @@ -110,10 +113,10 @@ public boolean add(int index, P placement) { // keep track of placement borders, where possible // copy intensively used items to local variables - Point3DFlagList

values = this.values; - Point3DFlagList

otherValues = this.otherValues; + Point3DFlagList values = this.values; + Point3DFlagList otherValues = this.otherValues; - SimplePoint3D

source = values.get(index); + SimplePoint3D source = values.get(index); values.flag(index); int xx = placement.getAbsoluteEndX() + 1; @@ -183,7 +186,7 @@ public boolean add(int index, P placement) { } for (int i = pointIndex; i < endIndex; i++) { - Point3D

point = values.get(i); + Point3D point = values.get(i); if(point.getMinY() > placement.getAbsoluteEndY() || point.getMinZ() > placement.getAbsoluteEndZ()) { // @@ -297,17 +300,17 @@ public boolean add(int index, P placement) { add: for (int i = 0; i < moveToXXSize; i++) { int currentIndex = moveToXX.get(i); - SimplePoint3D

p = values.get(currentIndex); + SimplePoint3D p = values.get(currentIndex); // add point on the other side // with x support for (int k = 0; k < addedXX.size(); k++) { - Point3D

add = addedXX.get(k); + Point3D add = addedXX.get(k); if(add.eclipsesMovedX(p, xx)) { continue add; } } - SimplePoint3D

added; + SimplePoint3D added; if(p.getMinY() < placement.getAbsoluteY() || p.getMinZ() < placement.getAbsoluteZ()) { // too low, no support added = p.moveX(xx); @@ -339,18 +342,18 @@ public boolean add(int index, P placement) { add: for (int i = 0; i < moveToYY.size(); i++) { int currentIndex = moveToYY.get(i); - SimplePoint3D

p = values.get(currentIndex); + SimplePoint3D p = values.get(currentIndex); // add point on the other side // with x support for (int k = 0; k < addedYY.size(); k++) { - Point3D

add = addedYY.get(k); + Point3D add = addedYY.get(k); if(add.eclipsesMovedY(p, yy)) { continue add; } } - SimplePoint3D

added; + SimplePoint3D added; if(p.getMinX() < placement.getAbsoluteX() || p.getMinZ() < placement.getAbsoluteZ()) { // too low, no support added = p.moveY(yy); @@ -384,17 +387,17 @@ public boolean add(int index, P placement) { add: for (int i = 0; i < moveToZZ.size(); i++) { int currentIndex = moveToZZ.get(i); - SimplePoint3D

p = values.get(currentIndex); + SimplePoint3D p = values.get(currentIndex); // add point on the other side for (int k = 0; k < addedZZ.size(); k++) { - Point3D

add = addedZZ.get(k); + Point3D add = addedZZ.get(k); if(add.eclipsesMovedZ(p, zz)) { continue add; } } - SimplePoint3D

added; + SimplePoint3D added; if(p.getMinX() < placement.getAbsoluteX() || p.getMinY() < placement.getAbsoluteY()) { // too low, no support added = p.moveZ(zz); @@ -463,10 +466,10 @@ public boolean add(int index, P placement) { for (int i = 0; i < endIndex; i++) { - Point3DList

addZZPoint3d = addZZ.get(i); + Point3DList addZZPoint3d = addZZ.get(i); if(!addZZPoint3d.isEmpty()) { for (int k = 0; k < addZZPoint3d.size(); k++) { - SimplePoint3D

p = addZZPoint3d.get(k); + SimplePoint3D p = addZZPoint3d.get(k); if(!isEclipsed(p)) { otherValues.add(p); } @@ -474,10 +477,10 @@ public boolean add(int index, P placement) { addZZPoint3d.clear(); } - Point3DList

addYYPoint3d = addYY.get(i); + Point3DList addYYPoint3d = addYY.get(i); if(!addYYPoint3d.isEmpty()) { for (int k = 0; k < addYYPoint3d.size(); k++) { - SimplePoint3D

p = addYYPoint3d.get(k); + SimplePoint3D p = addYYPoint3d.get(k); if(!isEclipsed(p)) { otherValues.add(p); } @@ -489,7 +492,7 @@ public boolean add(int index, P placement) { otherValues.add(values.get(i)); } - SimplePoint3D

constrainXXPoint = constrainXX.get(i); + SimplePoint3D constrainXXPoint = constrainXX.get(i); if(constrainXXPoint != null) { if(!isEclipsed(constrainXXPoint)) { otherValues.add(constrainXXPoint); @@ -497,7 +500,7 @@ public boolean add(int index, P placement) { // clean up here so we do not need to reset the array constrainXX.clear(i); } - SimplePoint3D

constrainYYPoint = constrainYY.get(i); + SimplePoint3D constrainYYPoint = constrainYY.get(i); if(constrainYYPoint != null) { if(!isEclipsed(constrainYYPoint)) { otherValues.add(constrainYYPoint); @@ -505,7 +508,7 @@ public boolean add(int index, P placement) { // clean up here so we do not need to reset the array constrainYY.clear(i); } - SimplePoint3D

constrainZZPoint = constrainZZ.get(i); + SimplePoint3D constrainZZPoint = constrainZZ.get(i); if(constrainZZPoint != null) { if(!isEclipsed(constrainZZPoint)) { otherValues.add(constrainZZPoint); @@ -515,10 +518,10 @@ public boolean add(int index, P placement) { } } - Point3DList

addZZPoint3d = addZZ.get(endIndex); + Point3DList addZZPoint3d = addZZ.get(endIndex); if(!addZZPoint3d.isEmpty()) { for (int k = 0; k < addZZPoint3d.size(); k++) { - SimplePoint3D

p = addZZPoint3d.get(k); + SimplePoint3D p = addZZPoint3d.get(k); if(!isEclipsed(p)) { otherValues.add(p); } @@ -526,10 +529,10 @@ public boolean add(int index, P placement) { addZZPoint3d.clear(); } - Point3DList

addYYPoint3d = addYY.get(endIndex); + Point3DList addYYPoint3d = addYY.get(endIndex); if(!addYYPoint3d.isEmpty()) { for (int k = 0; k < addYYPoint3d.size(); k++) { - SimplePoint3D

p = addYYPoint3d.get(k); + SimplePoint3D p = addYYPoint3d.get(k); if(!isEclipsed(p)) { otherValues.add(p); } @@ -538,10 +541,10 @@ public boolean add(int index, P placement) { } for (int i = endIndex; i < values.size(); i++) { - Point3DList

addXXPoint3d = addXX.get(i); + Point3DList addXXPoint3d = addXX.get(i); if(!addXXPoint3d.isEmpty()) { for (int k = 0; k < addXXPoint3d.size(); k++) { - SimplePoint3D

p = addXXPoint3d.get(k); + SimplePoint3D p = addXXPoint3d.get(k); if(p.isSupportedYZPlane()) { if(!isEclipsedAtXX(p, xx)) { otherValues.add(p); @@ -561,10 +564,10 @@ public boolean add(int index, P placement) { } // get the last element, if any - Point3DList

addXXPoint3d = addXX.get(values.size()); + Point3DList addXXPoint3d = addXX.get(values.size()); if(!addXXPoint3d.isEmpty()) { for (int k = 0; k < addXXPoint3d.size(); k++) { - SimplePoint3D

p = addXXPoint3d.get(k); + SimplePoint3D p = addXXPoint3d.get(k); if(p.isSupportedYZPlane()) { if(!isEclipsedAtXX(p, xx)) { @@ -593,7 +596,7 @@ public boolean add(int index, P placement) { return !values.isEmpty(); } - protected void saveValues(Point3DFlagList

values, Point3DFlagList

otherValues) { + protected void saveValues(Point3DFlagList values, Point3DFlagList otherValues) { // Copy output to input + reset current input and set as next output. // this saves a good bit of cleanup this.values = otherValues; @@ -602,10 +605,10 @@ protected void saveValues(Point3DFlagList

values, Point3DFlagList

otherVal this.otherValues = values; } - private boolean isEclipsed(Point3D

point) { + private boolean isEclipsed(Point3D point) { // check if one of the existing values contains the new value for (int index = 0; index < otherValues.size(); index++) { - Point3D

otherValue = otherValues.get(index); + Point3D otherValue = otherValues.get(index); if(point.getVolume() <= otherValue.getVolume() && point.getArea() <= otherValue.getArea()) { if(otherValue.eclipses(point)) { @@ -617,10 +620,10 @@ private boolean isEclipsed(Point3D

point) { return false; } - private boolean isEclipsedAtXX(Point3D

point, int xx) { + private boolean isEclipsedAtXX(Point3D point, int xx) { // check if one of the existing values contains the new value for (int index = otherValues.size() - 1; index >= 0; index--) { - Point3D

otherValue = otherValues.get(index); + Point3D otherValue = otherValues.get(index); if(otherValue.getMinX() < xx) { return false; } @@ -634,7 +637,7 @@ private boolean isEclipsedAtXX(Point3D

point, int xx) { return false; } - private void constrainMax(P placement, int endIndex) { + private void constrainMax(StackPlacement placement, int endIndex) { constrainXX.ensureAdditionalCapacity(endIndex); constrainYY.ensureAdditionalCapacity(endIndex); constrainZZ.ensureAdditionalCapacity(endIndex); @@ -644,7 +647,7 @@ private void constrainMax(P placement, int endIndex) { continue; } - SimplePoint3D

point = values.get(i); + SimplePoint3D point = values.get(i); if(!withinX(point.getMinX(), placement)) { if(withinZ(point.getMinZ(), placement) && withinY(point.getMinY(), placement)) { if(point.getMinX() < placement.getAbsoluteX()) { @@ -695,7 +698,7 @@ private void constrainMax(P placement, int endIndex) { } } - private void constrainMaxWithClone(P placement, int endIndex) { + private void constrainMaxWithClone(StackPlacement placement, int endIndex) { constrainXX.ensureAdditionalCapacity(endIndex); constrainYY.ensureAdditionalCapacity(endIndex); constrainZZ.ensureAdditionalCapacity(endIndex); @@ -705,7 +708,7 @@ private void constrainMaxWithClone(P placement, int endIndex) { continue; } - SimplePoint3D

point = values.get(i); + SimplePoint3D point = values.get(i); if(!withinX(point.getMinX(), placement)) { if(withinZ(point.getMinZ(), placement) && withinY(point.getMinY(), placement)) { if(point.getMinX() < placement.getAbsoluteX()) { @@ -714,7 +717,7 @@ private void constrainMaxWithClone(P placement, int endIndex) { long area = (placement.getAbsoluteX() - point.getMinX()) * (long)point.getDy(); if(area >= minAreaLimit) { - SimplePoint3D

clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY(), point.getMaxZ()); + SimplePoint3D clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY(), point.getMaxZ()); constrainXX.set(clone, i); } values.flag(i); @@ -728,7 +731,7 @@ private void constrainMaxWithClone(P placement, int endIndex) { long area = (placement.getAbsoluteY() - point.getMinY()) * (long)point.getDx(); if(area >= minAreaLimit) { - SimplePoint3D

clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1, point.getMaxZ()); + SimplePoint3D clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1, point.getMaxZ()); constrainYY.set(clone, i); } values.flag(i); @@ -737,7 +740,7 @@ private void constrainMaxWithClone(P placement, int endIndex) { } } else if(point.getMinZ() < placement.getAbsoluteZ()) { // i.e. if(!withinZ(point.getMinZ(), placement)) { if(point.getMaxZ() >= placement.getAbsoluteZ()) { - SimplePoint3D

clone = point.clone(point.getMaxX(), point.getMaxY(), placement.getAbsoluteZ() - 1); + SimplePoint3D clone = point.clone(point.getMaxX(), point.getMaxY(), placement.getAbsoluteZ() - 1); constrainZZ.set(clone, i); values.flag(i); } @@ -745,25 +748,25 @@ private void constrainMaxWithClone(P placement, int endIndex) { } } - private boolean canMoveZ(Point3D

p, int zz) { + private boolean canMoveZ(Point3D p, int zz) { if(p.getMaxZ() < zz) { return false; } return !isConstrainedAtZ(p, zz); } - private boolean isConstrainedAtZ(Point3D

p, int zz) { + private boolean isConstrainedAtZ(Point3D p, int zz) { return p.getVolumeAtZ(zz) < minVolumeLimit; } - private boolean canMoveX(Point3D

p, int xx) { + private boolean canMoveX(Point3D p, int xx) { if(p.getMaxX() < xx) { return false; } return !isConstrainedAtX(p, xx); } - private boolean isConstrainedAtX(Point3D

p, int xx) { + private boolean isConstrainedAtX(Point3D p, int xx) { long areaAtX = p.getAreaAtX(xx); if(areaAtX >= minAreaLimit) { return false; @@ -771,7 +774,7 @@ private boolean isConstrainedAtX(Point3D

p, int xx) { return areaAtX * p.getDz() < minVolumeLimit; } - private boolean isConstrainedAtMaxX(Point3D

p, int maxX) { + private boolean isConstrainedAtMaxX(Point3D p, int maxX) { long areaAtMaxX = p.getAreaAtMaxX(maxX); if(areaAtMaxX >= minAreaLimit) { return false; @@ -779,7 +782,7 @@ private boolean isConstrainedAtMaxX(Point3D

p, int maxX) { return areaAtMaxX * p.getDz() < minVolumeLimit; } - private boolean isConstrainedAtMaxY(Point3D

p, int maxY) { + private boolean isConstrainedAtMaxY(Point3D p, int maxY) { long areaAtMaxY = p.getAreaAtMaxY(maxY); if(areaAtMaxY >= minAreaLimit) { return false; @@ -787,18 +790,18 @@ private boolean isConstrainedAtMaxY(Point3D

p, int maxY) { return areaAtMaxY * p.getDz() < minVolumeLimit; } - private boolean isConstrainedAtMaxZ(Point3D

p, int maxZ) { + private boolean isConstrainedAtMaxZ(Point3D p, int maxZ) { return p.getVolumeAtMaxZ(maxZ) < minVolumeLimit; } - private boolean canMoveY(Point3D

p, int yy) { + private boolean canMoveY(Point3D p, int yy) { if(p.getMaxY() < yy) { return false; } return !isConstraintedAtY(p, yy); } - private boolean isConstraintedAtY(Point3D

p, int yy) { + private boolean isConstraintedAtY(Point3D p, int yy) { long areaAtY = p.getAreaAtY(yy); if(areaAtY >= minAreaLimit) { return false; @@ -809,7 +812,7 @@ private boolean isConstraintedAtY(Point3D

p, int yy) { private void filterMinimums() { boolean flagged = false; for (int i = 0; i < values.size(); i++) { - Point3D

p = values.get(i); + Point3D p = values.get(i); if(p.getVolume() < minVolumeLimit || p.getArea() < minAreaLimit) { values.flag(i); @@ -831,12 +834,12 @@ protected void removeEclipsed(int limit) { // | new | existing current | // |----------|----------------------|--> x - Point3DFlagList

values = this.otherValues; + Point3DFlagList values = this.otherValues; int size = values.size(); added: for (int i = 0; i < limit; i++) { - Point3D

unsorted = values.get(i); + Point3D unsorted = values.get(i); // check if one of the existing values contains the new value for (int index = limit; index < size; index++) { @@ -844,7 +847,7 @@ protected void removeEclipsed(int limit) { continue; } - Point3D

sorted = values.get(index); + Point3D sorted = values.get(index); if(sorted.getMinX() > unsorted.getMinX()) { // so sorted cannot contain unsorted // at this index or later @@ -867,7 +870,7 @@ protected void removeEclipsed(int limit) { } } - protected void constrainFloatingMaxWithClone(P placement, int limit) { + protected void constrainFloatingMaxWithClone(StackPlacement placement, int limit) { /* addXX.ensureAdditionalCapacity(limit); addYY.ensureAdditionalCapacity(limit); @@ -875,7 +878,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { */ for (int i = 0; i < limit; i++) { - SimplePoint3D

point = values.get(i); + SimplePoint3D point = values.get(i); if( placement.getAbsoluteEndX() < point.getMinX() || @@ -957,14 +960,14 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { addX: if(point.getMinX() < placement.getAbsoluteX()) { if(!isConstrainedAtMaxX(point, placement.getAbsoluteX() - 1)) { - SimplePoint3D

clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY(), point.getMaxZ()); + SimplePoint3D clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY(), point.getMaxZ()); // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { if(values.isFlag(j)) { continue; } - SimplePoint3D

point3d = values.get(j); + SimplePoint3D point3d = values.get(j); if(point3d.getDx() > clone.getMinX()) { break; } @@ -978,7 +981,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { // is the point now eclipsed by new points? for (int j = 0; j < addedXX.size(); j++) { - SimplePoint3D

point3d = addedXX.get(j); + SimplePoint3D point3d = addedXX.get(j); if(point3d.getVolume() >= clone.getVolume()) { if(point3d.eclipses(clone)) { @@ -994,14 +997,14 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { addY: if(point.getMinY() < placement.getAbsoluteY()) { if(!isConstrainedAtMaxY(point, placement.getAbsoluteY() - 1)) { - SimplePoint3D

clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1, point.getMaxZ()); + SimplePoint3D clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1, point.getMaxZ()); // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { if(values.isFlag(j)) { continue; } - SimplePoint3D

point3d = values.get(j); + SimplePoint3D point3d = values.get(j); if(point3d.getDx() > clone.getMinX()) { break; } @@ -1015,7 +1018,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { // is the point now eclipsed by new points? for (int j = 0; j < addedYY.size(); j++) { - SimplePoint3D

point3d = addedYY.get(j); + SimplePoint3D point3d = addedYY.get(j); if(point3d.getVolume() >= clone.getVolume()) { if(point3d.eclipses(clone)) { @@ -1031,14 +1034,14 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { addZ: if(point.getMinZ() < placement.getAbsoluteZ()) { if(!isConstrainedAtMaxZ(point, placement.getAbsoluteZ() - 1)) { - SimplePoint3D

clone = point.clone(point.getMaxX(), point.getMaxY(), placement.getAbsoluteZ() - 1); + SimplePoint3D clone = point.clone(point.getMaxX(), point.getMaxY(), placement.getAbsoluteZ() - 1); // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { if(values.isFlag(j)) { continue; } - SimplePoint3D

point3d = values.get(j); + SimplePoint3D point3d = values.get(j); if(point3d.getDx() > clone.getMinX()) { break; } @@ -1052,7 +1055,7 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { // is the point now eclipsed by new points? for (int j = 0; j < addedZZ.size(); j++) { - SimplePoint3D

point3d = addedZZ.get(j); + SimplePoint3D point3d = addedZZ.get(j); if(point3d.getVolume() >= clone.getVolume()) { if(point3d.eclipses(clone)) { @@ -1070,9 +1073,9 @@ protected void constrainFloatingMaxWithClone(P placement, int limit) { } - protected void constrainFloatingMax(P placement, int limit) { + protected void constrainFloatingMax(StackPlacement placement, int limit) { - Point3DFlagList

values = this.values; + Point3DFlagList values = this.values; long minAreaLimit = this.minAreaLimit; long minVolumeLimit = this.minVolumeLimit; @@ -1183,7 +1186,7 @@ protected void constrainFloatingMax(P placement, int limit) { // limitLoop: for (int i = 0; i < limit; i++) { - SimplePoint3D

point = values.get(i); + SimplePoint3D point = values.get(i); if( placement.getAbsoluteEndZ() < point.getMinZ() || @@ -1209,7 +1212,7 @@ protected void constrainFloatingMax(P placement, int limit) { // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { - Point3D

point3d = values.get(j); + Point3D point3d = values.get(j); if(point3d.getMinX() > point.getMinX()) { break; } @@ -1225,7 +1228,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(splitXX) { // is the point now eclipsed by new points? for (int j = startAddXX; j < addedXX.size(); j++) { - Point3D

point3d = addedXX.get(j); + Point3D point3d = addedXX.get(j); if(point3d.getVolume() >= point.getVolume()) { if(point3d.eclipses(point)) { @@ -1254,7 +1257,7 @@ protected void constrainFloatingMax(P placement, int limit) { // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { - Point3D

point3d = values.get(j); + Point3D point3d = values.get(j); if(point3d.getMinX() > point.getMinX()) { break; } @@ -1270,7 +1273,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(splitYY) { // is the point now eclipsed by new points? for (int j = startAddYY; j < addedYY.size(); j++) { - Point3D

point3d = addedYY.get(j); + Point3D point3d = addedYY.get(j); if(point3d.getVolume() >= point.getVolume()) { if(point3d.eclipses(point)) { @@ -1300,7 +1303,7 @@ protected void constrainFloatingMax(P placement, int limit) { // is the point now eclipsed by current points? for (int j = 0; j < i - 1; j++) { - Point3D

point3d = values.get(j); + Point3D point3d = values.get(j); if(point3d.getMinX() > point.getMinX()) { break; } @@ -1316,7 +1319,7 @@ protected void constrainFloatingMax(P placement, int limit) { if(splitZZ) { // is the point now eclipsed by new points? for (int j = startAddZZ; j < addedZZ.size(); j++) { - Point3D

point3d = addedZZ.get(j); + Point3D point3d = addedZZ.get(j); if(point3d.getVolume() >= point.getVolume()) { if(point3d.eclipses(point)) { @@ -1337,20 +1340,20 @@ protected void constrainFloatingMax(P placement, int limit) { // fall through: must add multiple points if(!isConstrainedAtMaxX(point, placement.getAbsoluteX() - 1)) { - SimplePoint3D

clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY(), point.getMaxZ()); + SimplePoint3D clone = point.clone(placement.getAbsoluteX() - 1, point.getMaxY(), point.getMaxZ()); constrainXX.set(clone, i); addedXX.add(clone); splitXX = true; } if(!isConstrainedAtMaxY(point, placement.getAbsoluteY() - 1)) { - SimplePoint3D

clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1, point.getMaxZ()); + SimplePoint3D clone = point.clone(point.getMaxX(), placement.getAbsoluteY() - 1, point.getMaxZ()); constrainYY.set(clone, i); addedYY.add(clone); splitYY = true; } if(!isConstrainedAtMaxZ(point, placement.getAbsoluteZ() - 1)) { - SimplePoint3D

clone = point.clone(point.getMaxX(), point.getMaxY(), placement.getAbsoluteZ() - 1); + SimplePoint3D clone = point.clone(point.getMaxX(), point.getMaxY(), placement.getAbsoluteZ() - 1); constrainZZ.set(clone, i); addedZZ.add(clone); splitZZ = true; @@ -1360,15 +1363,15 @@ protected void constrainFloatingMax(P placement, int limit) { } - protected boolean withinX(int x, P placement) { + protected boolean withinX(int x, StackPlacement placement) { return placement.getAbsoluteX() <= x && x <= placement.getAbsoluteEndX(); } - protected boolean withinY(int y, P placement) { + protected boolean withinY(int y, StackPlacement placement) { return placement.getAbsoluteY() <= y && y <= placement.getAbsoluteEndY(); } - protected boolean withinZ(int z, P placement) { + protected boolean withinZ(int z, StackPlacement placement) { return placement.getAbsoluteZ() <= z && z <= placement.getAbsoluteEndZ(); } @@ -1389,15 +1392,15 @@ public String toString() { return "ExtremePoints3D [width=" + containerMaxX + ", depth=" + containerMaxY + ", values=" + values + "]"; } - public List

getPlacements() { + public List getPlacements() { return placements; } - public SimplePoint3D

getValue(int i) { + public SimplePoint3D getValue(int i) { return values.get(i); } - public List> getValues() { + public List getValues() { return values.toList(); } @@ -1406,14 +1409,14 @@ public int getValueCount() { return values.size(); } - public List> getValuesAsList() { + public List getValuesAsList() { return values.toList(); } public int getMinY() { int min = 0; for (int i = 1; i < values.size(); i++) { - Point3D

point = values.get(i); + Point3D point = values.get(i); if(point.getMinY() < values.get(min).getMinY()) { min = i; @@ -1425,7 +1428,7 @@ public int getMinY() { public int getMinX() { int min = 0; for (int i = 1; i < values.size(); i++) { - Point3D

point = values.get(i); + Point3D point = values.get(i); if(point.getMinX() < values.get(min).getMinX()) { min = i; @@ -1437,7 +1440,7 @@ public int getMinX() { public int getMinZ() { int min = 0; for (int i = 1; i < values.size(); i++) { - Point3D

point2d = values.get(i); + Point3D point2d = values.get(i); if(point2d.getMinZ() < values.get(min).getMinZ()) { min = i; @@ -1448,7 +1451,7 @@ public int getMinZ() { public int get(int x, int y, int z) { for (int i = 0; i < values.size(); i++) { - Point3D

point2d = values.get(i); + Point3D point2d = values.get(i); if(point2d.getMinY() == y && point2d.getMinX() == x && point2d.getMinZ() == z) { return i; @@ -1464,7 +1467,7 @@ public boolean isEmpty() { public long getMaxArea() { long maxPointArea = -1L; for (int i = 0; i < values.size(); i++) { - Point3D

point = values.get(i); + Point3D point = values.get(i); if(maxPointArea < point.getArea()) { maxPointArea = point.getArea(); } @@ -1488,7 +1491,7 @@ public void reset(int dx, int dy, int dz) { public int findPoint(int x, int y, int z) { for (int i = 0; i < values.size(); i++) { - Point3D

point = values.get(i); + Point3D point = values.get(i); if(point.getMinX() == x && point.getMinY() == y && point.getMinZ() == z) { return i; } @@ -1530,7 +1533,7 @@ public int binarySearchPlusMinY(int key) { return low; } - public int binarySearchPlusMinX(Point3DFlagList

values, int low, int key) { + public int binarySearchPlusMinX(Point3DFlagList values, int low, int key) { // return exclusive result int high = values.size() - 1; @@ -1598,7 +1601,7 @@ public int binarySearchMinusMinX(int key) { public long getMaxVolume() { long maxPointVolume = -1L; for (int i = 0; i < values.size(); i++) { - Point3D

point = values.get(i); + Point3D point = values.get(i); if(maxPointVolume < point.getVolume()) { maxPointVolume = point.getVolume(); } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DArray.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DArray.java index 8aeea79b..27c452cc 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DArray.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DArray.java @@ -1,11 +1,9 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; import java.util.Arrays; import java.util.Comparator; import java.util.List; -import com.github.skjolber.packing.api.Placement3D; import com.github.skjolber.packing.api.ep.Point3D; /** @@ -15,10 +13,10 @@ */ @SuppressWarnings("unchecked") -public class Point3DArray

{ +public class Point3DArray { private int size = 0; - private SimplePoint3D

[] points = new SimplePoint3D[16]; + private SimplePoint3D[] points = new SimplePoint3D[16]; public void ensureAdditionalCapacity(int count) { ensureCapacity(size + count); @@ -26,13 +24,13 @@ public void ensureAdditionalCapacity(int count) { public void ensureCapacity(int size) { if(points.length < size) { - SimplePoint3D

[] nextPoints = new SimplePoint3D[size]; + SimplePoint3D[] nextPoints = new SimplePoint3D[size]; System.arraycopy(this.points, 0, nextPoints, 0, this.points.length); this.points = nextPoints; } } - public void set(SimplePoint3D

point, int index) { + public void set(SimplePoint3D point, int index) { points[index] = point; size++; } @@ -51,7 +49,7 @@ public void reset() { size = 0; } - public SimplePoint3D

get(int i) { + public SimplePoint3D get(int i) { return points[i]; } @@ -66,7 +64,7 @@ public void clear() { /** * Returns the hash code value for this list. * - *

+ * * This implementation uses exactly the code that is used to define the * list hash function in the documentation for the {@link List#hashCode} * method. @@ -84,7 +82,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if(obj instanceof Point3DList) { - Point3DList

other = (Point3DList

)obj; + Point3DList other = (Point3DList)obj; if(other.size() == size) { for (int i = 0; i < size; i++) { if(!points[i].equals(other.get(i))) { @@ -97,11 +95,11 @@ public boolean equals(Object obj) { return super.equals(obj); } - public Point3D

[] getPoints() { + public Point3D[] getPoints() { return points; } - public void sort(Comparator> comparator) { + public void sort(Comparator comparator) { Arrays.sort(points, 0, size, comparator); } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DFlagList.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DFlagList.java index f0a5df61..f0483ca0 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DFlagList.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DFlagList.java @@ -6,8 +6,6 @@ import java.util.Comparator; import java.util.List; -import com.github.skjolber.packing.api.Placement3D; -import com.github.skjolber.packing.api.ep.Point2D; import com.github.skjolber.packing.api.ep.Point3D; /** @@ -17,12 +15,12 @@ */ @SuppressWarnings("unchecked") -public class Point3DFlagList

implements Serializable { +public class Point3DFlagList implements Serializable { private static final long serialVersionUID = 1L; private int size = 0; - private SimplePoint3D

[] points = new SimplePoint3D[16]; + private SimplePoint3D[] points = new SimplePoint3D[16]; private boolean[] flag = new boolean[16]; public void ensureAdditionalCapacity(int count) { @@ -31,7 +29,7 @@ public void ensureAdditionalCapacity(int count) { public void ensureCapacity(int size) { if(points.length < size) { - SimplePoint3D

[] nextPoints = new SimplePoint3D[size]; + SimplePoint3D[] nextPoints = new SimplePoint3D[size]; System.arraycopy(this.points, 0, nextPoints, 0, this.size); boolean[] nextFlag = new boolean[size]; @@ -42,17 +40,17 @@ public void ensureCapacity(int size) { } } - public void add(SimplePoint3D

point) { + public void add(SimplePoint3D point) { points[size] = point; size++; } - public void add(SimplePoint3D

point, int index) { + public void add(SimplePoint3D point, int index) { points[index] = point; flag[index] = false; } - public void sort(Comparator> comparator, int maxSize) { + public void sort(Comparator comparator, int maxSize) { Arrays.sort(points, 0, maxSize, comparator); } @@ -108,8 +106,8 @@ public int removeFlagged() { return index - offset; } - public List> toList() { - List> list = new ArrayList<>(size); + public List toList() { + List list = new ArrayList<>(size); for (int i = 0; i < size; i++) { list.add(points[i]); } @@ -131,11 +129,11 @@ public void move(int offset) { this.size += offset; } - public void copyFrom(Point3DFlagList

source) { + public void copyFrom(Point3DFlagList source) { source.copyInto(this); } - public void copyInto(Point3DFlagList

destination) { + public void copyInto(Point3DFlagList destination) { destination.ensureCapacity(size); System.arraycopy(points, 0, destination.points, 0, size); @@ -148,14 +146,14 @@ public void copyInto(Point3DFlagList

destination) { } } - public Point3D

[] getPoints() { + public Point3D[] getPoints() { return points; } /** * Returns the hash code value for this list. * - *

+ * * This implementation uses exactly the code that is used to define the * list hash function in the documentation for the {@link List#hashCode} * method. @@ -173,7 +171,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if(obj instanceof Point3DFlagList) { - Point3DFlagList

other = (Point3DFlagList

)obj; + Point3DFlagList other = (Point3DFlagList)obj; if(other.size() == size) { for (int i = 0; i < size; i++) { if(!points[i].equals(other.get(i))) { @@ -189,7 +187,7 @@ public boolean equals(Object obj) { return super.equals(obj); } - public void setAll(Point3DList

add, int offset) { + public void setAll(Point3DList add, int offset) { System.arraycopy(add.getPoints(), 0, points, offset, add.size()); int limit = offset + add.size(); for (int i = offset; i < limit; i++) { @@ -202,7 +200,7 @@ public void unflag(int i) { flag[i] = false; } - public void set(SimplePoint3D

point, int i) { + public void set(SimplePoint3D point, int i) { points[i] = point; } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DList.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DList.java index 3a30ab70..c84a5e25 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DList.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DList.java @@ -1,11 +1,9 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; import java.util.Arrays; import java.util.Comparator; import java.util.List; -import com.github.skjolber.packing.api.Placement3D; import com.github.skjolber.packing.api.ep.Point3D; /** @@ -15,10 +13,10 @@ */ @SuppressWarnings("unchecked") -public class Point3DList

{ +public class Point3DList { private int size = 0; - private SimplePoint3D

[] points; + private SimplePoint3D[] points; public Point3DList() { this(16); @@ -34,13 +32,13 @@ public void ensureAdditionalCapacity(int count) { public void ensureCapacity(int size) { if(points.length < size) { - SimplePoint3D

[] nextPoints = new SimplePoint3D[size]; + SimplePoint3D[] nextPoints = new SimplePoint3D[size]; System.arraycopy(this.points, 0, nextPoints, 0, this.size); this.points = nextPoints; } } - public void add(SimplePoint3D

point) { + public void add(SimplePoint3D point) { points[size] = point; size++; } @@ -54,7 +52,7 @@ public void reset() { size = 0; } - public SimplePoint3D

get(int i) { + public SimplePoint3D get(int i) { return points[i]; } @@ -69,7 +67,7 @@ public void clear() { /** * Returns the hash code value for this list. * - *

+ * * This implementation uses exactly the code that is used to define the * list hash function in the documentation for the {@link List#hashCode} * method. @@ -87,7 +85,7 @@ public int hashCode() { @Override public boolean equals(Object obj) { if(obj instanceof Point3DList) { - Point3DList

other = (Point3DList

)obj; + Point3DList other = (Point3DList)obj; if(other.size() == size) { for (int i = 0; i < size; i++) { if(!points[i].equals(other.get(i))) { @@ -100,11 +98,11 @@ public boolean equals(Object obj) { return super.equals(obj); } - public SimplePoint3D

[] getPoints() { + public SimplePoint3D[] getPoints() { return points; } - public void sort(Comparator> comparator) { + public void sort(Comparator comparator) { Arrays.sort(points, 0, size, comparator); } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DListArray.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DListArray.java index a7e130ae..725f708e 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DListArray.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/Point3DListArray.java @@ -1,10 +1,5 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; -import com.github.skjolber.packing.api.ep.Point3D; - /** * * Custom list array for working with points. @@ -12,31 +7,31 @@ */ @SuppressWarnings("unchecked") -public class Point3DListArray

{ +public class Point3DListArray { private static final int INITIAL_CAPACITY = 8; - private Point3DList

[] points = new Point3DList[16]; + private Point3DList[] points = new Point3DList[16]; public Point3DListArray() { points = new Point3DList[16]; for (int i = 0; i < points.length; i++) { - points[i] = new Point3DList<>(INITIAL_CAPACITY); + points[i] = new Point3DList(INITIAL_CAPACITY); } } public void ensureCapacity(int size) { if(points.length < size) { - Point3DList

[] nextPoints = new Point3DList[size]; + Point3DList[] nextPoints = new Point3DList[size]; System.arraycopy(this.points, 0, nextPoints, 0, this.points.length); for (int i = this.points.length; i < size; i++) { - nextPoints[i] = new Point3DList<>(INITIAL_CAPACITY); + nextPoints[i] = new Point3DList(INITIAL_CAPACITY); } this.points = nextPoints; } } - public void add(SimplePoint3D

point, int index) { + public void add(SimplePoint3D point, int index) { points[index].add(point); } @@ -50,7 +45,7 @@ public boolean isEmpty(int index) { return points[index].isEmpty(); } - public Point3DList

get(int i) { + public Point3DList get(int i) { return points[i]; } diff --git a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/SimplePoint3D.java b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/SimplePoint3D.java index 07ecbc8d..175934fe 100644 --- a/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/SimplePoint3D.java +++ b/extreme-points/src/main/java/com/github/skjolber/packing/ep/points3d/SimplePoint3D.java @@ -1,11 +1,9 @@ package com.github.skjolber.packing.ep.points3d; -import java.io.Serializable; - -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -public abstract class SimplePoint3D

extends Point3D

{ +public abstract class SimplePoint3D extends Point3D { private static final long serialVersionUID = 1L; @@ -55,7 +53,7 @@ public boolean isSupportedXZPlane() { // i.e. y is fixed // |---------x=================== // - public abstract SimplePoint3D

moveX(int x); + public abstract SimplePoint3D moveX(int x); // | // | @@ -76,7 +74,7 @@ public boolean isSupportedXZPlane() { // i.e. y is fixed // |---------x=================== // - public abstract SimplePoint3D

moveX(int x, P yzSupport); + public abstract SimplePoint3D moveX(int x, StackPlacement yzSupport); // // | â•‘ @@ -106,7 +104,7 @@ public boolean isSupportedXZPlane() { // i.e. y is fixed // | // |--------------------------- - public abstract SimplePoint3D

moveY(int y); + public abstract SimplePoint3D moveY(int y); // // | â•‘ @@ -136,13 +134,13 @@ public boolean isSupportedXZPlane() { // i.e. y is fixed // | // |--------------------------- - public abstract SimplePoint3D

moveY(int y, P xzSupport); + public abstract SimplePoint3D moveY(int y, StackPlacement xzSupport); - public abstract SimplePoint3D

moveZ(int z); + public abstract SimplePoint3D moveZ(int z); - public abstract SimplePoint3D

moveZ(int z, P xySupport); + public abstract SimplePoint3D moveZ(int z, StackPlacement xySupport); - public abstract SimplePoint3D

clone(int maxX, int maxY, int maxZ); + public abstract SimplePoint3D clone(int maxX, int maxY, int maxZ); public abstract long calculateXYSupport(int dx, int dy); diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points/BouwkampConverter.java b/extreme-points/src/test/java/com/github/skjolber/packing/points/BouwkampConverter.java index 30939ca1..62fe4c84 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points/BouwkampConverter.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points/BouwkampConverter.java @@ -2,10 +2,11 @@ import java.util.List; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.api.Box; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -import com.github.skjolber.packing.ep.points2d.DefaultPlacement2D; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; +import com.github.skjolber.packing.ep.points2d.Point2D; import com.github.skjolber.packing.test.bouwkamp.BouwkampCode; import com.github.skjolber.packing.test.bouwkamp.BouwkampCodeLine; @@ -17,6 +18,18 @@ public class BouwkampConverter { public BouwkampConverter(boolean throwException) { this.throwException = throwException; } + + private StackPlacement createStackPlacement(int x, int y, int endX, int endY) { + return createStackPlacement(x, y, 0, endX, endY, 0); + } + + private StackPlacement createStackPlacement(int x, int y, int z, int endX, int endY, int endZ) { + BoxStackValue stackValue = new BoxStackValue(endX + 1 - x, endY + 1 - y, endZ + 1 - z, null, null); + + Box box = Box.newBuilder().withSize(endX + 1 - x, endY + 1 - y, endZ + 1 - z).withWeight(0).build(); + + return new StackPlacement(box, stackValue, x, y, z); + } public DefaultExtremePoints2D convert2D(BouwkampCode bkpLine, int factor) { @@ -41,7 +54,7 @@ public DefaultExtremePoints2D convert2D(BouwkampCode bkpLine, int factor) { int factoredSquare = factor * square; - points.add(nextY, new DefaultPlacement2D(offset, value.getMinY(), offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1)); + points.add(nextY, createStackPlacement(offset, value.getMinY(), offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1)); offset += factoredSquare; @@ -97,7 +110,7 @@ public DefaultExtremePoints3D convert3DXYPlane(BouwkampCode bkpLine, int factor) Integer square = squares.get(i); int factoredSquare = factor * square; - points.add(nextY, new DefaultPlacement3D(offset, value.getMinY(), 0, offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1, factor - 1)); + points.add(nextY, createStackPlacement(offset, value.getMinY(), 0, offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1, factor - 1)); offset += factoredSquare; @@ -152,7 +165,7 @@ public DefaultExtremePoints3D convert3DXZPlane(BouwkampCode bkpLine, int factor) Integer square = squares.get(i); int factoredSquare = factor * square; - points.add(nextZ, new DefaultPlacement3D(offset, 0, value.getMinZ(), offset + factoredSquare - 1, factor - 1, value.getMinZ() + factoredSquare - 1)); + points.add(nextZ, createStackPlacement(offset, 0, value.getMinZ(), offset + factoredSquare - 1, factor - 1, value.getMinZ() + factoredSquare - 1)); offset += factoredSquare; @@ -206,7 +219,7 @@ public DefaultExtremePoints3D convert3DYZPlane(BouwkampCode bkpLine, int factor) Integer square = squares.get(i); int factoredSquare = factor * square; - points.add(nextZ, new DefaultPlacement3D(0, offset, value.getMinZ(), factor - 1, offset + factoredSquare - 1, value.getMinZ() + factoredSquare - 1)); + points.add(nextZ, createStackPlacement(0, offset, value.getMinZ(), factor - 1, offset + factoredSquare - 1, value.getMinZ() + factoredSquare - 1)); offset += factoredSquare; diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints2D.java b/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints2D.java index 8d04fc0c..4c6d2ff9 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints2D.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints2D.java @@ -1,26 +1,25 @@ package com.github.skjolber.packing.points; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; -import com.github.skjolber.packing.ep.points2d.DefaultPlacement2D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.ep.points2d.ExtremePoints2D; +import com.github.skjolber.packing.ep.points2d.Point2D; -public class DefaultExtremePoints2D extends ExtremePoints2D { +public class DefaultExtremePoints2D extends ExtremePoints2D { public DefaultExtremePoints2D(int dx, int dy) { super(dx, dy); } @Override - public boolean add(int index, DefaultPlacement2D placement) { + public boolean add(int index, StackPlacement placement) { boolean add = super.add(index, placement); validate(placement); return add; } - private void validate(Placement2D target) { + private void validate(StackPlacement target) { - for (Placement2D p : placements) { + for (StackPlacement p : placements) { for (int i = 0; i < values.size(); i++) { Point2D point = values.get(i); diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints3D.java b/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints3D.java index abefa0fb..c2498b9c 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints3D.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points/DefaultExtremePoints3D.java @@ -1,26 +1,25 @@ package com.github.skjolber.packing.points; -import com.github.skjolber.packing.api.Placement3D; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; import com.github.skjolber.packing.ep.points3d.ExtremePoints3D; -public class DefaultExtremePoints3D extends ExtremePoints3D { +public class DefaultExtremePoints3D extends ExtremePoints3D { public DefaultExtremePoints3D(int dx, int dy, int dz) { super(dx, dy, dz); } @Override - public boolean add(int index, DefaultPlacement3D placement) { + public boolean add(int index, StackPlacement placement) { boolean add = super.add(index, placement); validate(placement); return add; } - private void validate(DefaultPlacement3D target) { + private void validate(StackPlacement target) { - for (Placement3D p : placements) { + for (StackPlacement p : placements) { for (int i = 0; i < values.size(); i++) { Point3D point = values.get(i); diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ExtremePoints2DTest.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ExtremePoints2DTest.java index d1c9ace3..e5e3df28 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ExtremePoints2DTest.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ExtremePoints2DTest.java @@ -7,18 +7,32 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import com.github.skjolber.packing.api.ep.Point2D; -import com.github.skjolber.packing.ep.points2d.DefaultPlacement2D; +import com.github.skjolber.packing.api.Box; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.ep.points2d.DefaultXYSupportPoint2D; import com.github.skjolber.packing.ep.points2d.ExtremePoints2D; +import com.github.skjolber.packing.ep.points2d.Point2D; import com.github.skjolber.packing.points.DefaultExtremePoints2D; public class ExtremePoints2DTest { + private StackPlacement createStackPlacement(int x, int y, int endX, int endY) { + return createStackPlacement(x, y, 0, endX, endY, 0); + } + + private StackPlacement createStackPlacement(int x, int y, int z, int endX, int endY, int endZ) { + BoxStackValue stackValue = new BoxStackValue(endX + 1 - x, endY + 1 - y, 1, null, null); + + Box box = Box.newBuilder().withSize(endX + 1 - x, endY + 1 - y, 1).withWeight(0).build(); + + return new StackPlacement(box, stackValue, x, y, z); + } + @Test public void testSinglePoint() { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 10, 10)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 10, 10)); assertThat(ep.getValues()).hasSize(2); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); @@ -36,8 +50,8 @@ public void testSinglePoint() { @Test public void testSinglePointCornerCase() { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 0, 0)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 0, 0)); assertThat(ep.getValues()).hasSize(2); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); @@ -55,8 +69,8 @@ public void testSinglePointCornerCase() { @Test public void testSinglePointCoveringAllX() { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 99, 10)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 99, 10)); assertThat(ep.getValues()).hasSize(1); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); @@ -65,8 +79,8 @@ public void testSinglePointCoveringAllX() { @Test public void testSinglePointCoveringAllY() { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 10, 99)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 10, 99)); assertThat(ep.getValues()).hasSize(1); assertThat(ep.getValue(0).getMinX()).isEqualTo(11); @@ -75,15 +89,15 @@ public void testSinglePointCoveringAllY() { @Test public void testSinglePointCoveringWholeContainer() { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 99, 99)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 99, 99)); assertThat(ep.getValues()).hasSize(0); } @Test public void testStackInXDirection() { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 49)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 9, 49)); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); assertThat(ep.getValue(0).getMinY()).isEqualTo(50); @@ -91,7 +105,7 @@ public void testStackInXDirection() { assertThat(ep.getValue(1).getMinX()).isEqualTo(10); assertThat(ep.getValue(1).getMinY()).isEqualTo(0); - ep.add(1, new DefaultPlacement2D(10, 0, 19, 24)); + ep.add(1, createStackPlacement(10, 0, 19, 24)); assertThat(ep.getValues()).hasSize(3); @@ -130,8 +144,8 @@ public void testStackInYDirection() { // ------------ // 4 9 - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 49)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 9, 49)); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); assertThat(ep.getValue(0).getMinY()).isEqualTo(50); @@ -139,7 +153,7 @@ public void testStackInYDirection() { assertThat(ep.getValue(1).getMinX()).isEqualTo(10); assertThat(ep.getValue(1).getMinY()).isEqualTo(0); - ep.add(0, new DefaultPlacement2D(0, 50, 4, 74)); + ep.add(0, createStackPlacement(0, 50, 4, 74)); assertThat(ep.getValues()).hasSize(3); @@ -170,7 +184,7 @@ public void testStackEqualItemsInXDirection() throws InterruptedException { // 9 19 DefaultExtremePoints2D ep = new DefaultExtremePoints2D(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); + ep.add(0, createStackPlacement(0, 0, 9, 9)); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); assertThat(ep.getValue(0).getMinY()).isEqualTo(10); @@ -179,7 +193,7 @@ public void testStackEqualItemsInXDirection() throws InterruptedException { assertThat(ep.getValue(1).getMinY()).isEqualTo(0); assertThat(ep.getValues()).hasSize(2); - ep.add(1, new DefaultPlacement2D(10, 0, 19, 9)); + ep.add(1, createStackPlacement(10, 0, 19, 9)); assertThat(ep.getValues()).hasSize(2); @@ -212,8 +226,8 @@ public void testStackEqualItemsInYDirection() throws InterruptedException { // ---------- // 9 - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 9, 9)); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); assertThat(ep.getValue(0).getMinY()).isEqualTo(10); @@ -221,7 +235,7 @@ public void testStackEqualItemsInYDirection() throws InterruptedException { assertThat(ep.getValue(1).getMinX()).isEqualTo(10); assertThat(ep.getValue(1).getMinY()).isEqualTo(0); - ep.add(0, new DefaultPlacement2D(0, 10, 9, 19)); + ep.add(0, createStackPlacement(0, 10, 9, 19)); assertThat(ep.getValues()).hasSize(2); @@ -253,7 +267,7 @@ public void testStackHigherItemsInXDirection() throws InterruptedException { // 9 19 DefaultExtremePoints2D ep = new DefaultExtremePoints2D(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); + ep.add(0, createStackPlacement(0, 0, 9, 9)); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); assertThat(ep.getValue(0).getMinY()).isEqualTo(10); @@ -261,7 +275,7 @@ public void testStackHigherItemsInXDirection() throws InterruptedException { assertThat(ep.getValue(1).getMinX()).isEqualTo(10); assertThat(ep.getValue(1).getMinY()).isEqualTo(0); - ep.add(1, new DefaultPlacement2D(10, 0, 19, 19)); + ep.add(1, createStackPlacement(10, 0, 19, 19)); assertThat(ep.getValues()).hasSize(3); @@ -299,8 +313,8 @@ public void testStackWiderItemsInYDirection() throws InterruptedException { // ------------- // 9 19 - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 9, 9)); assertThat(ep.getValue(0).getMinX()).isEqualTo(0); assertThat(ep.getValue(0).getMinY()).isEqualTo(10); @@ -310,7 +324,7 @@ public void testStackWiderItemsInYDirection() throws InterruptedException { assertThat(ep.getValues()).hasSize(2); - ep.add(0, new DefaultPlacement2D(0, 10, 19, 19)); + ep.add(0, createStackPlacement(0, 10, 19, 19)); assertThat(ep.getValues()).hasSize(3); @@ -337,8 +351,8 @@ public void testStackWiderItemsInYDirection() throws InterruptedException { @Test public void testSwallowedInXDirection1() throws InterruptedException { DefaultExtremePoints2D ep = new DefaultExtremePoints2D(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); - ep.add(1, new DefaultPlacement2D(10, 0, 19, 19)); + ep.add(0, createStackPlacement(0, 0, 9, 9)); + ep.add(1, createStackPlacement(10, 0, 19, 19)); // | // | @@ -353,7 +367,7 @@ public void testSwallowedInXDirection1() throws InterruptedException { // 10 20 assertThat(ep.getValues()).hasSize(3); - ep.add(0, new DefaultPlacement2D(0, 10, 4, 24)); + ep.add(0, createStackPlacement(0, 10, 4, 24)); // | // 25 x---| @@ -393,8 +407,8 @@ public void testSwallowedInXDirection1() throws InterruptedException { @Test public void testSwallowedInXDirection2() throws InterruptedException { DefaultExtremePoints2D ep = new DefaultExtremePoints2D(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); - ep.add(1, new DefaultPlacement2D(10, 0, 19, 19)); + ep.add(0, createStackPlacement(0, 0, 9, 9)); + ep.add(1, createStackPlacement(10, 0, 19, 19)); // | // | @@ -414,7 +428,7 @@ public void testSwallowedInXDirection2() throws InterruptedException { assertThat(ep.getValue(1)).isMin(0, 20); assertThat(ep.getValue(2)).isMin(20, 0); - ep.add(2, new DefaultPlacement2D(20, 0, 24, 24)); + ep.add(2, createStackPlacement(20, 0, 24, 24)); // | // | @@ -454,7 +468,7 @@ public void testSwallowedInXDirection2() throws InterruptedException { assertThat(ep.getValue(3).getMinY()).isEqualTo(0); assertThat(ep.getValue(3)).isMax(99, 99); - ep.add(0, new DefaultPlacement2D(0, 10, 4, 29)); + ep.add(0, createStackPlacement(0, 10, 4, 29)); // | // | @@ -502,9 +516,9 @@ public void testSwallowedInXDirection2() throws InterruptedException { @Test public void testSwallowedInYDirection1() throws InterruptedException { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); - ep.add(0, new DefaultPlacement2D(0, 10, 19, 19)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 9, 9)); + ep.add(0, createStackPlacement(0, 10, 19, 19)); // | // 20 x------------------| @@ -534,7 +548,7 @@ public void testSwallowedInYDirection1() throws InterruptedException { assertThat(ep.getValue(2)).isNoYSupport(0); assertThat(ep.getValue(2)).isYSupport(19); - ep.add(1, new DefaultPlacement2D(10, 0, 24, 4)); + ep.add(1, createStackPlacement(10, 0, 24, 4)); // | // 20 x------------------| @@ -577,9 +591,9 @@ public void testSwallowedInYDirection1() throws InterruptedException { @Test public void testSwallowedInYDirection2() throws InterruptedException { - ExtremePoints2D ep = new ExtremePoints2D<>(100, 100); - ep.add(0, new DefaultPlacement2D(0, 0, 9, 9)); - ep.add(0, new DefaultPlacement2D(0, 10, 19, 19)); + ExtremePoints2D ep = new ExtremePoints2D(100, 100); + ep.add(0, createStackPlacement(0, 0, 9, 9)); + ep.add(0, createStackPlacement(0, 10, 19, 19)); // | // 20 x------------------| @@ -603,7 +617,7 @@ public void testSwallowedInYDirection2() throws InterruptedException { assertThat(ep.getValue(2).getMinX()).isEqualTo(20); assertThat(ep.getValue(2).getMinY()).isEqualTo(0); - ep.add(0, new DefaultPlacement2D(0, 20, 24, 24)); + ep.add(0, createStackPlacement(0, 20, 24, 24)); // | // x-----------------------| @@ -642,7 +656,7 @@ public void testSwallowedInYDirection2() throws InterruptedException { assertThat(ep.getValue(3)).isNoYSupport(0); assertThat(ep.getValue(3)).isYSupport(24); - ep.add(1, new DefaultPlacement2D(10, 0, 29, 4)); + ep.add(1, createStackPlacement(10, 0, 29, 4)); // | // x-----------------------| @@ -675,22 +689,22 @@ public void testSwallowedInYDirection2() throws InterruptedException { @Test public void testStacking() { - ExtremePoints2D ep = new ExtremePoints2D<>(3, 2); - ep.add(0, new DefaultPlacement2D(0, 0, 0, 1)); + ExtremePoints2D ep = new ExtremePoints2D(3, 2); + ep.add(0, createStackPlacement(0, 0, 0, 1)); assertThat(ep.getValues()).hasSize(1); assertThat(ep.getValue(0).getMinX()).isEqualTo(1); assertThat(ep.getValue(0).getMinY()).isEqualTo(0); - ep.add(0, new DefaultPlacement2D(1, 0, 1, 1)); + ep.add(0, createStackPlacement(1, 0, 1, 1)); assertThat(ep.getValues()).hasSize(1); assertThat(ep.getValue(0).getMinX()).isEqualTo(2); assertThat(ep.getValue(0).getMinY()).isEqualTo(0); - ep.add(0, new DefaultPlacement2D(2, 0, 2, 1)); + ep.add(0, createStackPlacement(2, 0, 2, 1)); assertThat(ep.getValues()).hasSize(0); } @@ -698,11 +712,11 @@ public void testStacking() { @ParameterizedTest @ValueSource(booleans = { true, false }) public void testFloatingX(boolean b) { - ExtremePoints2D ep = new ExtremePoints2D<>(1000, 1000, b); - ep.add(0, new DefaultPlacement2D(0, 0, 49, 99)); + ExtremePoints2D ep = new ExtremePoints2D(1000, 1000, b); + ep.add(0, createStackPlacement(0, 0, 49, 99)); assertThat(ep.getValue(0)).isInstanceOf(DefaultXYSupportPoint2D.class); - ep.add(1, new DefaultPlacement2D(50, 0, 99, 49)); + ep.add(1, createStackPlacement(50, 0, 99, 49)); assertThat(ep.getValue(0)).isInstanceOf(DefaultXYSupportPoint2D.class); assertThat(ep.getValue(1)).isInstanceOf(DefaultXYSupportPoint2D.class); @@ -722,7 +736,7 @@ public void testFloatingX(boolean b) { assertThat(point.getMaxY()).isEqualTo(999); } - ep.add(1, new DefaultPlacement2D(50, 50, 149, 149)); + ep.add(1, createStackPlacement(50, 50, 149, 149)); // | // | @@ -763,7 +777,7 @@ public void testFloatingX(boolean b) { assertThat(ep.getValue(3).getMinY()).isEqualTo(0); assertThat(ep.getValue(3)).isInstanceOf(DefaultXYSupportPoint2D.class); - ep.add(3, new DefaultPlacement2D(150, 0, 169, 19)); + ep.add(3, createStackPlacement(150, 0, 169, 19)); // | // | @@ -821,7 +835,7 @@ public void testFloatingX(boolean b) { assertThat(ep.getValues()).hasSize(6); - ep.add(5, new DefaultPlacement2D(170, 0, 189, 29)); + ep.add(5, createStackPlacement(170, 0, 189, 29)); // | // | @@ -882,7 +896,7 @@ public void testFloatingX(boolean b) { assertThat(ep.getValue(7)).isInstanceOf(DefaultXYSupportPoint2D.class); assertThat(ep.getValue(7)).isMax(999, 999); - ep.add(6, new DefaultPlacement2D(150, 30, 189, 69)); + ep.add(6, createStackPlacement(150, 30, 189, 69)); // | // | @@ -927,7 +941,7 @@ public void testFloatingX(boolean b) { assertThat(ep.getValues()).hasSize(6); - ep.add(3, new DefaultPlacement2D(100, 20, 139, 24)); + ep.add(3, createStackPlacement(100, 20, 139, 24)); // | // | @@ -997,11 +1011,11 @@ public void testFloatingX(boolean b) { @ParameterizedTest @ValueSource(booleans = { true, false }) public void testFloatingY(boolean b) { - ExtremePoints2D ep = new ExtremePoints2D<>(1000, 1000, b); - ep.add(0, new DefaultPlacement2D(0, 0, 49, 99)); + ExtremePoints2D ep = new ExtremePoints2D(1000, 1000, b); + ep.add(0, createStackPlacement(0, 0, 49, 99)); assertThat(ep.getValue(0)).isInstanceOf(DefaultXYSupportPoint2D.class); - ep.add(1, new DefaultPlacement2D(50, 0, 99, 49)); + ep.add(1, createStackPlacement(50, 0, 99, 49)); assertThat(ep.getValue(0)).isInstanceOf(DefaultXYSupportPoint2D.class); assertThat(ep.getValue(1)).isInstanceOf(DefaultXYSupportPoint2D.class); @@ -1021,7 +1035,7 @@ public void testFloatingY(boolean b) { assertThat(point.getMaxY()).isEqualTo(999); } - ep.add(1, new DefaultPlacement2D(50, 50, 149, 149)); + ep.add(1, createStackPlacement(50, 50, 149, 149)); // | // | @@ -1062,7 +1076,7 @@ public void testFloatingY(boolean b) { assertThat(ep.getValue(3).getMinY()).isEqualTo(0); assertThat(ep.getValue(3)).isInstanceOf(DefaultXYSupportPoint2D.class); - ep.add(1, new DefaultPlacement2D(0, 150, 19, 169)); + ep.add(1, createStackPlacement(0, 150, 19, 169)); // | // | @@ -1114,7 +1128,7 @@ public void testFloatingY(boolean b) { assertThat(ep.getValues()).hasSize(6); - ep.add(1, new DefaultPlacement2D(0, 170, 29, 189)); + ep.add(1, createStackPlacement(0, 170, 29, 189)); // | // | @@ -1176,7 +1190,7 @@ public void testFloatingY(boolean b) { assertThat(ep.getValue(7).getMinY()).isEqualTo(0); assertThat(ep.getValue(7)).isInstanceOf(DefaultXYSupportPoint2D.class); - ep.add(5, new DefaultPlacement2D(30, 150, 69, 189)); + ep.add(5, createStackPlacement(30, 150, 69, 189)); // | // | @@ -1229,7 +1243,7 @@ public void testFloatingY(boolean b) { assertThat(ep.getValue(5).getMinY()).isEqualTo(0); assertThat(ep.getValue(5)).isInstanceOf(DefaultXYSupportPoint2D.class); - ep.add(2, new DefaultPlacement2D(20, 100, 24, 139)); + ep.add(2, createStackPlacement(20, 100, 24, 139)); // | // | diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPoint2DAssert.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractPoint2DAssert.java similarity index 97% rename from test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPoint2DAssert.java rename to extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractPoint2DAssert.java index ab44d71a..77aaf118 100644 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPoint2DAssert.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractPoint2DAssert.java @@ -1,8 +1,9 @@ -package com.github.skjolber.packing.test.assertj; +package com.github.skjolber.packing.points2d.assertj; + import org.assertj.core.api.AbstractObjectAssert; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.ep.points2d.Point2D; @SuppressWarnings("rawtypes") public abstract class AbstractPoint2DAssert, ACTUAL extends Point2D> diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractSimplePoint2DAssert.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractSimplePoint2DAssert.java index 5729d11b..650a1421 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractSimplePoint2DAssert.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/AbstractSimplePoint2DAssert.java @@ -2,12 +2,10 @@ import org.assertj.core.api.AbstractObjectAssert; -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.ep.points2d.Point2D; import com.github.skjolber.packing.ep.points2d.SimplePoint2D; import com.github.skjolber.packing.ep.points2d.XSupportPoint2D; import com.github.skjolber.packing.ep.points2d.YSupportPoint2D; -import com.github.skjolber.packing.test.assertj.AbstractPoint2DAssert; @SuppressWarnings("rawtypes") public abstract class AbstractSimplePoint2DAssert, ACTUAL extends SimplePoint2D> diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/Point2DAssert.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/Point2DAssert.java similarity index 73% rename from test/src/main/java/com/github/skjolber/packing/test/assertj/Point2DAssert.java rename to extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/Point2DAssert.java index 600c609e..95597fe8 100644 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/Point2DAssert.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/Point2DAssert.java @@ -1,6 +1,6 @@ -package com.github.skjolber.packing.test.assertj; +package com.github.skjolber.packing.points2d.assertj; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.ep.points2d.Point2D; @SuppressWarnings("rawtypes") public class Point2DAssert extends AbstractPoint2DAssert { diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/SimplePoint2DAssert.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/SimplePoint2DAssert.java index 2c6c3077..20981d3c 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/SimplePoint2DAssert.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/assertj/SimplePoint2DAssert.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.points2d.assertj; -import com.github.skjolber.packing.api.ep.Point2D; +import com.github.skjolber.packing.ep.points2d.Point2D; import com.github.skjolber.packing.ep.points2d.SimplePoint2D; @SuppressWarnings("rawtypes") diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints2D.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints2D.java deleted file mode 100644 index facc3684..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints2D.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import java.util.List; - -import com.github.skjolber.packing.points.BouwkampConverter; -import com.github.skjolber.packing.points.DefaultExtremePoints2D; -import com.github.skjolber.packing.test.bouwkamp.BouwkampCode; -import com.github.skjolber.packing.test.bouwkamp.BouwkampCodeDirectory; -import com.github.skjolber.packing.test.bouwkamp.BouwkampCodes; - -public class DrawBouwkampPoints2D { - - public static void main(String[] args) { - - BouwkampConverter converter = new BouwkampConverter(false); - - BouwkampCodeDirectory directory = BouwkampCodeDirectory.getInstance(); - - List target = directory.getSimplePerfectSquaredRectangles(); - for (BouwkampCodes codes : target) { - System.out.println(codes.getSource()); - for (BouwkampCode c : codes.getCodes()) { - if(codes.getSource().contains("o12spsr.bkp") && c.getName().equals("106x99A")) { - DefaultExtremePoints2D convert2d = converter.convert2D(c, 10); - - DrawPoints2D.show(convert2d); - - return; - } - } - } - } -} diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints3D.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints3D.java deleted file mode 100644 index 549315eb..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawBouwkampPoints3D.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import java.util.ArrayList; -import java.util.List; - -import com.github.skjolber.packing.api.Placement3D; -import com.github.skjolber.packing.api.ep.Point3D; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; -import com.github.skjolber.packing.ep.points3d.SimplePoint3D; -import com.github.skjolber.packing.points.BouwkampConverter; -import com.github.skjolber.packing.points.DefaultExtremePoints3D; -import com.github.skjolber.packing.test.bouwkamp.BouwkampCode; -import com.github.skjolber.packing.test.bouwkamp.BouwkampCodeDirectory; -import com.github.skjolber.packing.test.bouwkamp.BouwkampCodes; - -public class DrawBouwkampPoints3D { - - public static void main(String[] args) { - - BouwkampConverter converter = new BouwkampConverter(false); - - BouwkampCodeDirectory directory = BouwkampCodeDirectory.getInstance(); - - List target = directory.getAll(); - - for (BouwkampCodes codes : target) { - for (BouwkampCode c : codes.getCodes()) { - - DefaultExtremePoints3D plane = converter.convert3DXYPlane(c, 1); - - List> list = new ArrayList<>(); - - List> values = plane.getValuesAsList(); - - List placements = plane.getPlacements(); - - Placement3D last = placements.get(placements.size() - 1); - boolean rotate = last.getAbsoluteX() == 0; - - for (Point3D point3d : values) { - if(rotate) { - list.add(point3d.rotate()); - } else { - list.add(point3d); - } - } - - List results = new ArrayList<>(); - - for (Placement3D p : placements) { - if(rotate) { - results.add(rotate(p)); - } else { - results.add(p); - } - } - - if(rotate) { - DrawPoints2D.show3D(list, results, plane.getDepth(), plane.getHeight()); - } else { - DrawPoints2D.show3D(list, results, plane.getWidth(), plane.getDepth()); - } - } - } - } - - private static Placement3D rotate(Placement3D p) { - return new DefaultPlacement3D(p.getAbsoluteY(), p.getAbsoluteZ(), p.getAbsoluteX(), p.getAbsoluteEndY(), p.getAbsoluteEndZ(), p.getAbsoluteEndX()); - } - -} \ No newline at end of file diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2D.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2D.java deleted file mode 100644 index 1d45f02e..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2D.java +++ /dev/null @@ -1,313 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Rectangle; -import java.awt.Toolkit; -import java.awt.event.MouseEvent; -import java.awt.image.BufferedImage; -import java.util.List; - -import javax.swing.BorderFactory; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.SwingUtilities; -import javax.swing.event.MouseInputAdapter; - -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.Placement3D; -import com.github.skjolber.packing.api.ep.Point2D; -import com.github.skjolber.packing.api.ep.Point3D; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; -import com.github.skjolber.packing.ep.points3d.SimplePoint3D; -import com.github.skjolber.packing.points.DefaultExtremePoints2D; -import com.github.skjolber.packing.points.DefaultExtremePoints3D; - -public class DrawPoints2D { - - public static void show(DefaultExtremePoints2D p) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - - init(p.getValues(), p.getPlacements(), p.getWidth(), p.getDepth()); - } - }); - } - - public static void show3D(List points, List placements, int width, int depth) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - - init(points, placements, width, depth); - } - }); - } - - public static void show(DefaultExtremePoints3D p) { - SwingUtilities.invokeLater(new Runnable() { - public void run() { - - List> values = p.getValuesAsList(); - - init(values, p.getPlacements(), p.getWidth(), p.getDepth()); - } - }); - } - - private static void init(List points, List placements, int width, int depth) { - DrawingArea drawingArea = new DrawingArea(width, depth); - - System.out.println("Show " + width + "x" + depth); - - for (Point2D extremePoint : points) { - if(extremePoint.getMaxX() != width || extremePoint.getMaxY() != depth) { - Color c; - if(extremePoint.getMaxX() != width && extremePoint.getMaxY() != depth) { - c = Color.red; - } else if(extremePoint.getMaxX() != width) { - c = Color.blue; - } else { - c = Color.yellow; - } - drawingArea.fillRect(extremePoint.getMinX(), extremePoint.getMinY(), extremePoint.getMaxX(), - extremePoint.getMaxY(), c); - System.out.println("Paint constrained " + extremePoint.getMinX() + "x" + extremePoint.getMinY() + " " - + extremePoint.getMaxX() + "x" + extremePoint.getMaxY()); - } - } - - for (Point2D extremePoint : points) { - if(extremePoint.getMaxX() == width && extremePoint.getMaxY() == depth) { - System.out.println("Paint white " + extremePoint.getMinX() + "x" + extremePoint.getMinY() + " " - + extremePoint.getMaxX() + "x" + extremePoint.getMaxY()); - drawingArea.fillRect(extremePoint.getMinX(), extremePoint.getMinY(), extremePoint.getMaxX(), - extremePoint.getMaxY(), Color.white); - } - } - - for (Placement2D extremePoint : placements) { - drawingArea.addRectangle(extremePoint.getAbsoluteX(), extremePoint.getAbsoluteY(), - extremePoint.getAbsoluteEndX(), extremePoint.getAbsoluteEndY(), Color.green); - drawingArea.addDashedLine(extremePoint.getAbsoluteX(), extremePoint.getAbsoluteY(), - extremePoint.getAbsoluteEndX(), extremePoint.getAbsoluteEndY(), Color.red); - - System.out.println(" " + extremePoint.getAbsoluteX() + "x" + extremePoint.getAbsoluteY()); - - } - - for (int i = 0; i < points.size(); i++) { - Point2D point2d = points.get(i); - drawingArea.addCircle(point2d.getMinX(), point2d.getMinY(), Color.black, i); - } - - drawingArea.addGuide(0, -5, width, -5, Color.blue); - - JFrame.setDefaultLookAndFeelDecorated(true); - JFrame frame = new JFrame("Draw On extreme points"); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - - BufferedImage image = drawingArea.getImage(); - MainPanel mainPanel = new MainPanel(image); - mainPanel.setBounds(0, 0, image.getWidth(), image.getHeight()); - mainPanel.setBorder(BorderFactory.createLineBorder(Color.black)); - - Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); - - frame.getContentPane().add(mainPanel); - - frame.pack(); - frame.setLocationRelativeTo(null); - frame.setVisible(true); - - frame.setBounds(0, 0, image.getWidth(), image.getHeight()); - - } - - private static class DrawingArea extends JPanel { - - private static final long serialVersionUID = 1L; - - private int width; - private int depth; - - private BufferedImage image; - private Rectangle shape; - - public DrawingArea(int width, int depth) { - this.width = width; - this.depth = depth; - - image = new BufferedImage(width + 50, depth + 50, BufferedImage.TYPE_INT_ARGB); - - setBackground(Color.WHITE); - - MyMouseListener ml = new MyMouseListener(); - addMouseListener(ml); - addMouseMotionListener(ml); - - addRectangle(new Rectangle(0, 0, width, depth), Color.black); - - } - - public BufferedImage getImage() { - return image; - } - - public void fillRect(int x, int y, int xx, int yy, Color color) { - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(color); - g2d.fillRect(x, depth - yy, xx - x + 1, (yy - y + 1)); - repaint(); - - } - - @Override - public Dimension getPreferredSize() { - return isPreferredSizeSet() ? super.getPreferredSize() : new Dimension(image.getWidth(), image.getHeight()); - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - - // Custom code to support painting from the BufferedImage - if(image != null) { - g.drawImage(image, 0, 0, null); - } - - // Paint the Rectangle as the mouse is being dragged - if(shape != null) { - Graphics2D g2d = (Graphics2D)g; - g2d.draw(shape); - } - } - - public void addRectangle(int x1, int y1, int x2, int y2, Color color) { - addRectangle(new Rectangle(x1, depth - y2, x2 - x1, y2 - y1), color); - } - - public void addRectangle(Rectangle rectangle, Color color) { - // Draw the Rectangle onto the BufferedImage - - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(color); - g2d.draw(rectangle); - repaint(); - } - - public void addCircle(int x1, int y1, Color color, int index) { - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(color); - - int size = 10; - - g2d.drawOval(x1 - size / 2, depth - y1 - size / 2, size, size); - g2d.drawLine(x1, depth - y1, x1, depth - y1); - repaint(); - } - - public void addLine(int x1, int y1, int x2, int y2, Color color) { - // Draw the Rectangle onto the BufferedImage - - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(color); - g2d.drawLine(x1, depth - y1, x2, depth - y2); - repaint(); - } - - public void addGuide(int x1, int y1, int x2, int y2, Color color) { - // Draw the Rectangle onto the BufferedImage - - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(color); - drawDashed(g2d, x1, depth - y1, x2, depth - y2, 1, 9); - repaint(); - } - - public void addDashedLine(int x1, int y1, int x2, int y2, Color color) { - // Draw the Rectangle onto the BufferedImage - - Graphics2D g2d = (Graphics2D)image.getGraphics(); - g2d.setColor(color); - drawDashed(g2d, x1, depth - y1, x2, depth - y2, 5, 5); - repaint(); - } - - class MyMouseListener extends MouseInputAdapter { - private java.awt.Point startPoint; - - public void mousePressed(MouseEvent e) { - startPoint = e.getPoint(); - shape = new Rectangle(); - } - - public void mouseDragged(MouseEvent e) { - int x = Math.min(startPoint.x, e.getX()); - int y = Math.min(startPoint.y, e.getY()); - int width = Math.abs(startPoint.x - e.getX()); - int height = Math.abs(startPoint.y - e.getY()); - - shape.setBounds(x, y, width, height); - repaint(); - } - - public void mouseReleased(MouseEvent e) { - if(shape.width != 0 || shape.height != 0) { - addRectangle(shape, e.getComponent().getForeground()); - } - - shape = null; - } - } - - public static void drawDashed(Graphics g, int x1, int y1, int x2, int y2, int dashSize, int gapSize) { - if(x2 < x1) { - int temp = x1; - x1 = x2; - x2 = temp; - } - if(y2 < y1) { - int temp = y1; - y1 = y2; - y2 = temp; - } - int totalDash = dashSize + gapSize; - if(y1 == y2) { - int virtualStartX = (x1 / totalDash) * totalDash; - for (int x = virtualStartX; x < x2; x += totalDash) { - int topX = x + dashSize; - if(topX > x2) { - topX = x2; - } - int firstX = x; - if(firstX < x1) { - firstX = x1; - } - if(firstX < topX) { - g.drawLine(firstX, y1, topX, y1); - } - } - } else if(x1 == x2) { - int virtualStartY = (y1 / totalDash) * totalDash; - for (int y = virtualStartY; y < y2; y += totalDash) { - int topY = y + dashSize; - if(topY > y2) { - topY = y2; - } - int firstY = y; - if(firstY < y1) { - firstY = y1; - } - if(firstY < topY) { - g.drawLine(x1, firstY, x1, topY); - } - } - } else { - // Not supported - g.drawLine(x1, y1, x2, y2); - } - } - } -} \ No newline at end of file diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2DTest.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2DTest.java deleted file mode 100644 index e9742f4f..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints2DTest.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import com.github.skjolber.packing.api.ep.Point2D; -import com.github.skjolber.packing.ep.points2d.DefaultPlacement2D; -import com.github.skjolber.packing.points.DefaultExtremePoints2D; - -public class DrawPoints2DTest { - - private static DefaultPlacement2D createPlacement(Point2D extremePoint, int dx, int dy) { - return new DefaultPlacement2D(extremePoint.getMinX(), extremePoint.getMinY(), extremePoint.getMinX() + dx - 1, extremePoint.getMinY() + dy - 1); - } - - public static void main(String[] args) { - DefaultExtremePoints2D extremePoints = new DefaultExtremePoints2D(1000, 1000); - - Point2D extremePoint = extremePoints.getValues().get(0); - extremePoints.add(0, createPlacement(extremePoint, 50, 100)); - - extremePoint = extremePoints.getValues().get(extremePoints.getValues().size() - 1); - extremePoints.add(extremePoints.getValues().size() - 1, createPlacement(extremePoint, 50, 50)); - - extremePoint = extremePoints.getValues().get(extremePoints.getValues().size() - 2); - extremePoints.add(extremePoints.getValues().size() - 2, createPlacement(extremePoint, 100, 100)); - - extremePoint = extremePoints.getValues().get(extremePoints.getValues().size() - 1); - extremePoints.add(extremePoints.getValues().size() - 1, createPlacement(extremePoint, 20, 20)); - - extremePoint = extremePoints.getValues().get(extremePoints.getValues().size() - 1); - extremePoints.add(extremePoints.getValues().size() - 1, createPlacement(extremePoint, 20, 35)); - - extremePoint = extremePoints.getValues().get(1); - extremePoints.add(1, createPlacement(extremePoint, 20, 20)); - - extremePoint = extremePoints.getValues().get(1); - extremePoints.add(1, createPlacement(extremePoint, 30, 20)); - - extremePoint = extremePoints.getValues().get(0); - extremePoints.add(0, createPlacement(extremePoint, 25, 20)); - /* - int offset = 6; - extremePoint = extremePoints.getValues().get(extremePoints.getValues().size() - offset); - extremePoints.add(extremePoints.getValues().size() - offset, createPlacement(extremePoint, 20, 30)); - /* - extremePoint = extremePoints.getValues().get(6); - extremePoints.add(6, createPlacement(extremePoint, 50, 50)); - - offset = 2; - extremePoint = extremePoints.getValues().get(extremePoints.getValues().size() - offset); - extremePoints.add(extremePoints.getValues().size() - offset, createPlacement(extremePoint, 50, 50)); - */ - for (Point2D p : extremePoints.getValues()) { - System.out.println(" " + p.getMinX() + "x" + p.getMinY() + " " + p.getMaxX() + "x" + p.getMaxY()); - } - DrawPoints2D.show(extremePoints); - } -} \ No newline at end of file diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints3DTest.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints3DTest.java deleted file mode 100644 index 2236fc5a..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/DrawPoints3DTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import java.util.List; - -import com.github.skjolber.packing.api.Placement3D; -import com.github.skjolber.packing.api.ep.Point3D; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; -import com.github.skjolber.packing.ep.points3d.SimplePoint3D; -import com.github.skjolber.packing.points.DefaultExtremePoints3D; - -public class DrawPoints3DTest { - - private static DefaultPlacement3D createPlacement(Point3D extremePoint, int dx, int dy, int dz) { - if(extremePoint.getMinZ() != 0) { - throw new IllegalArgumentException(extremePoint.getMinX() + "x" + extremePoint.getMinY() + "x" + extremePoint.getMinZ()); - } - return new DefaultPlacement3D(extremePoint.getMinX(), extremePoint.getMinY(), extremePoint.getMinZ(), extremePoint.getMinX() + dx - 1, extremePoint.getMinY() + dy - 1, - extremePoint.getMinZ() + dz - 1); - } - - public static void main(String[] args) { - DefaultExtremePoints3D extremePoints = new DefaultExtremePoints3D(1000, 1000, 1000); - - Point3D extremePoint = extremePoints.getValuesAsList().get(0); - extremePoints.add(0, createPlacement(extremePoint, 50, 100, 1)); - - extremePoint = extremePoints.getValuesAsList().get(extremePoints.getValuesAsList().size() - 1); - extremePoints.add(extremePoints.getValuesAsList().size() - 1, createPlacement(extremePoint, 50, 50, 1)); - - extremePoint = extremePoints.getValuesAsList().get(extremePoints.getValuesAsList().size() - 2); - extremePoints.add(extremePoints.getValuesAsList().size() - 2, createPlacement(extremePoint, 100, 100, 1)); - - extremePoint = extremePoints.getValuesAsList().get(extremePoints.getValuesAsList().size() - 1); - extremePoints.add(extremePoints.getValuesAsList().size() - 1, createPlacement(extremePoint, 20, 20, 1)); - - extremePoint = extremePoints.getValuesAsList().get(extremePoints.getValuesAsList().size() - 1); - extremePoints.add(extremePoints.getValuesAsList().size() - 1, createPlacement(extremePoint, 20, 35, 1)); - - extremePoint = extremePoints.getValuesAsList().get(2); - extremePoints.add(2, createPlacement(extremePoint, 20, 20, 1)); - - extremePoint = extremePoints.getValuesAsList().get(1); - extremePoints.add(1, createPlacement(extremePoint, 30, 20, 1)); - - extremePoint = extremePoints.getValuesAsList().get(2); - extremePoints.add(2, createPlacement(extremePoint, 30, 20, 1)); - - int offset = 2; - extremePoint = extremePoints.getValuesAsList().get(extremePoints.getValuesAsList().size() - offset); - //extremePoints.add(extremePoints.getValuesAsList().size() - offset, createPlacement(extremePoint, 50, 50, 1)); - - //extremePoint = extremePoints.getValuesAsList().get(6); - // extremePoints.add(6, createPlacement(extremePoint, 50, 50, 1)); - - System.out.println("xyz:"); - - for (Point3D p : extremePoints.getValuesAsList()) { - System.out.println(" " + p.getMinX() + "x" + p.getMinY() + "x" + p.getMinZ() + " " + p.getMaxX() + "x" + p.getMaxY() + "x" + p.getMaxZ()); - } - - List> values = extremePoints.getValuesAsList(); - for (int i = 0; i < values.size(); i++) { - Point3D point3d = values.get(i); - - if(point3d.getMinZ() != 0) { - values.remove(i); - i--; - } - } - - System.out.println("xy:"); - for (Point3D p : extremePoints.getValuesAsList()) { - System.out.println(" " + p.getMinX() + "x" + p.getMinY() + "x" + p.getMinZ() + " " + p.getMaxX() + "x" + p.getMaxY() + "x" + p.getMaxZ()); - } - DrawPoints2D.show(extremePoints); - } -} \ No newline at end of file diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/MainPanel.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/MainPanel.java deleted file mode 100644 index 16ce39ce..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/MainPanel.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.MouseInfo; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.awt.geom.AffineTransform; -import java.awt.image.BufferedImage; - -import javax.swing.JPanel; - -/** - * From https://github.com/Thanasis1101/Zoomable-Java-Panel/blob/master/src/zoomable/panel/MainFrame.java - * - * @author Thanasis1101 - * @version 1.0 - */ -public class MainPanel extends JPanel implements MouseWheelListener, MouseListener, MouseMotionListener { - - private final BufferedImage image; - - private double zoomFactor = 1; - private double prevZoomFactor = 1; - private boolean zoomer; - private boolean dragger; - private boolean released; - private double xOffset = 0; - private double yOffset = 0; - private int xDiff; - private int yDiff; - private Point startPoint; - - public MainPanel(BufferedImage image) { - - this.image = image; - initComponent(); - - } - - private void initComponent() { - addMouseWheelListener(this); - addMouseMotionListener(this); - addMouseListener(this); - } - - @Override - public void paint(Graphics g) { - super.paint(g); - - Graphics2D g2 = (Graphics2D)g; - - if(zoomer) { - AffineTransform at = new AffineTransform(); - - double xRel = MouseInfo.getPointerInfo().getLocation().getX() - getLocationOnScreen().getX(); - double yRel = MouseInfo.getPointerInfo().getLocation().getY() - getLocationOnScreen().getY(); - - double zoomDiv = zoomFactor / prevZoomFactor; - - xOffset = (zoomDiv) * (xOffset) + (1 - zoomDiv) * xRel; - yOffset = (zoomDiv) * (yOffset) + (1 - zoomDiv) * yRel; - - at.translate(xOffset, yOffset); - at.scale(zoomFactor, zoomFactor); - prevZoomFactor = zoomFactor; - g2.transform(at); - zoomer = false; - } - - if(dragger) { - AffineTransform at = new AffineTransform(); - at.translate(xOffset + xDiff, yOffset + yDiff); - at.scale(zoomFactor, zoomFactor); - g2.transform(at); - - if(released) { - xOffset += xDiff; - yOffset += yDiff; - dragger = false; - } - - } - - // All drawings go here - - g2.drawImage(image, 0, 0, this); - - } - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - - zoomer = true; - - //Zoom in - if(e.getWheelRotation() < 0) { - zoomFactor *= 1.1; - repaint(); - } - //Zoom out - if(e.getWheelRotation() > 0) { - zoomFactor /= 1.1; - repaint(); - } - } - - @Override - public void mouseDragged(MouseEvent e) { - Point curPoint = e.getLocationOnScreen(); - xDiff = curPoint.x - startPoint.x; - yDiff = curPoint.y - startPoint.y; - - dragger = true; - repaint(); - - } - - @Override - public void mouseMoved(MouseEvent e) { - } - - @Override - public void mouseClicked(MouseEvent e) { - - } - - @Override - public void mousePressed(MouseEvent e) { - released = false; - startPoint = MouseInfo.getPointerInfo().getLocation(); - } - - @Override - public void mouseReleased(MouseEvent e) { - released = true; - repaint(); - } - - @Override - public void mouseEntered(MouseEvent e) { - - } - - @Override - public void mouseExited(MouseEvent e) { - - } - -} \ No newline at end of file diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/ZoomPane.java b/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/ZoomPane.java deleted file mode 100644 index 17c626fd..00000000 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points2d/ui/ZoomPane.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.github.skjolber.packing.points2d.ui; - -import java.awt.Container; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Image; -import java.awt.Point; -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; - -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JViewport; -import javax.swing.KeyStroke; - -public class ZoomPane extends JPanel implements MouseWheelListener { - - /** - * @author samkortchmar - * Mostly taken from various StackOverflow posts such as: - * http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position - * But I've modded it (clumsily) to support the pan-by-dragging and zoom-by-scrolling - * behavior we want for the map. There are problems with the panning right now, I think it's - * redrawing too quickly which makes it jerky. - * - * Supports: - * Zoom in/out to mouse pointer from mousewheel - * Click and drag to pan (not quite right) - * Zoom in/out via SHIFT-EQUALS or MINUS - */ - private Image background; - private Image scaled; - private float zoom = 1f; - - private Dimension scaledSize; - - public ZoomPane(Image image) { - - background = image; - scaled = background; - scaledSize = new Dimension(background.getWidth(this), background.getHeight(this)); - - InputMap im = getInputMap(WHEN_IN_FOCUSED_WINDOW); - ActionMap am = getActionMap(); - - im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0), "plus"); - im.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.SHIFT_DOWN_MASK), "plus"); - im.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0), "minus"); - - //key binding for zoom in - am.put("plus", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - setZoom(getZoom() + 0.5f); - } - }); - - //key binding for zoom out - am.put("minus", new AbstractAction() { - @Override - public void actionPerformed(ActionEvent e) { - setZoom(getZoom() - 0.5f); - } - }); - - //key binding for zooming with scroll wheel - addMouseWheelListener(this); - - //key binding for panning with click-n-drag. - //TODO fix the jerkiness. - MouseAdapter ma = new HandScrollListener(); - addMouseMotionListener(ma); - addMouseListener(ma); - - setFocusable(true); - requestFocusInWindow(); - } - - static class HandScrollListener extends MouseAdapter { - private final Point pp = new Point(); - - @Override - public void mouseDragged(MouseEvent e) { - ZoomPane z = (ZoomPane)e.getSource(); - JViewport vport = (JViewport)z.getParent(); - JComponent img = (JComponent)vport.getView(); - Point cp = e.getPoint(); - Point vp = vport.getViewPosition(); - vp.translate(pp.x - cp.x, pp.y - cp.y); - img.scrollRectToVisible(new Rectangle(vp, vport.getSize())); - pp.setLocation(cp); - } - - @Override - public void mousePressed(MouseEvent e) { - pp.setLocation(e.getPoint()); - } - } - - @Override - public void addNotify() { - super.addNotify(); - } - - public float getZoom() { - return zoom; - } - - public void setZoom(float value) { - //We need the mouse to be in the JViewport to do anything, since - //all zoom actions are dependent on mouse location. - Point mouse = getMousePosition(); - if(zoom != value && value > 0 && mouse != null) { - - JViewport parent = (JViewport)getParent(); - Point viewPort = parent.getViewPosition(); - Rectangle viewRect = parent.getViewRect(); - - int width = (int)Math.floor(background.getWidth(this) * value); - int height = (int)Math.floor(background.getHeight(this) * value); - - //Things stop working if the image is smaller than the jviewport. - if(width < viewRect.width || height < viewRect.height) { - return; - } - - //The appropriately scaled version of the background image to be repainted. - scaled = background.getScaledInstance(width, height, Image.SCALE_SMOOTH); - scaledSize = new Dimension(width, height); - - //I think this is a little bit ungraceful - we need it because - //the MousePosition() and JViewport are relative to the component - //which is basically the image, which means they both already have - //the existing zoom factored into them. So every time we scale, we - //remove the existing scale factor and then multiply by the new one. - //not sure if there is a better way to do it. - float scaleFactor = value / zoom; - - if(getParent() instanceof JViewport) { - //Establishes the top left corner of the viewPort relative to the image. See: - //http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position - //for a helpful description. - // (Ix' component) (Vx component) - viewRect.x = (int)((mouse.x - viewPort.x) * (scaleFactor - 1) + (scaleFactor) * viewPort.x); - viewRect.y = (int)((mouse.y - viewPort.y) * (scaleFactor - 1) + (scaleFactor) * viewPort.y); - zoom = value; - - //scrollRectToVisible(viewRect); - } - invalidate(); - repaint(); - } - } - - @Override - public Dimension getPreferredSize() { - return scaledSize; - } - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - if(scaled != null) { - g.drawImage(scaled, 0, 0, this); - } - } - - protected void centerInViewport() { - Container container = getParent(); - if(container instanceof JViewport) { - - JViewport port = (JViewport)container; - Rectangle viewRect = port.getViewRect(); - - int width = getWidth(); - int height = getHeight(); - - viewRect.x = (width - viewRect.width) / 2; - viewRect.y = (height - viewRect.height) / 2; - - scrollRectToVisible(viewRect); - } - } - - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - int notches = e.getWheelRotation(); - float zoomAmount = 0.05f; - setZoom(getZoom() - notches * zoomAmount); - } -} \ No newline at end of file diff --git a/extreme-points/src/test/java/com/github/skjolber/packing/points3d/ExtremePoints3DTest.java b/extreme-points/src/test/java/com/github/skjolber/packing/points3d/ExtremePoints3DTest.java index f858c616..cd9526d7 100644 --- a/extreme-points/src/test/java/com/github/skjolber/packing/points3d/ExtremePoints3DTest.java +++ b/extreme-points/src/test/java/com/github/skjolber/packing/points3d/ExtremePoints3DTest.java @@ -3,20 +3,30 @@ import static com.github.skjolber.packing.points3d.assertj.SimplePoint3DAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; +import com.github.skjolber.packing.api.Box; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; +import com.github.skjolber.packing.api.Stackable; import com.github.skjolber.packing.ep.points3d.ExtremePoints3D; public class ExtremePoints3DTest { - + + private StackPlacement createStackPlacement(int x, int y, int z, int endX, int endY, int endZ) { + BoxStackValue stackValue = new BoxStackValue(endX + 1 - x, endY + 1 - y, endZ + 1 - z, null, null); + + Box box = Box.newBuilder().withSize(endX + 1 - x, endY + 1 - y, endZ + 1 - z).withWeight(0).build(); + + return new StackPlacement(box, stackValue, x, y, z); + } + @ParameterizedTest @ValueSource(booleans = {true, false}) public void testSinglePoint(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); // y @@ -59,8 +69,8 @@ public void testSinglePoint(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testSinglePointCornercase(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 0, 0, 0)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 0, 0, 0)); assertThat(ep.getValues()).hasSize(3); assertThat(ep.getValue(0)).isMin(0, 0, 1); @@ -71,8 +81,8 @@ public void testSinglePointCornercase(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testSinglePointCoveringAllX(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 99, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 99, 9, 9)); assertThat(ep.getValues()).hasSize(2); @@ -90,8 +100,8 @@ public void testSinglePointCoveringAllX(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testSinglePointCoveringAllY(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 99, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 99, 9)); assertThat(ep.getValues()).hasSize(2); @@ -109,8 +119,8 @@ public void testSinglePointCoveringAllY(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testSinglePointCoveringAllZ(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 99)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 99)); assertThat(ep.getValues()).hasSize(2); assertThat(ep.getValue(0)).isMin(0, 10, 0); @@ -127,16 +137,16 @@ public void testSinglePointCoveringAllZ(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testSinglePointCoveringWholeContainer(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 99, 99, 99)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 99, 99, 99)); assertThat(ep.getValues()).hasSize(0); } @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackInXDirection(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); @@ -144,7 +154,7 @@ public void testStackInXDirection(boolean clone) { assertThat(ep.getValue(1)).isMin(0, 10, 0); assertThat(ep.getValue(2)).isMin(10, 0, 0); - ep.add(2, new DefaultPlacement3D(10, 0, 0, 19, 4, 4)); + ep.add(2, createStackPlacement(10, 0, 0, 19, 4, 4)); // y // | @@ -209,23 +219,23 @@ public void testStackInXDirection(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackInXDirectionWithIntermediate(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 0)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 0)); assertThat(ep.getValues()).hasSize(3); - ep.add(2, new DefaultPlacement3D(10, 0, 0, 19, 3, 0)); + ep.add(2, createStackPlacement(10, 0, 0, 19, 3, 0)); assertThat(ep.getValues()).hasSize(4); - ep.add(3, new DefaultPlacement3D(20, 0, 0, 29, 6, 0)); + ep.add(3, createStackPlacement(20, 0, 0, 29, 6, 0)); } @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackInZDirection(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); @@ -233,7 +243,7 @@ public void testStackInZDirection(boolean clone) { assertThat(ep.getValue(1)).isMin(0, 10, 0); assertThat(ep.getValue(2)).isMin(10, 0, 0); - ep.add(0, new DefaultPlacement3D(0, 0, 10, 4, 4, 19)); + ep.add(0, createStackPlacement(0, 0, 10, 4, 4, 19)); // y // | @@ -307,12 +317,12 @@ public void testStackInZDirection(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackInYDirection(boolean clone) { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); - ep.add(1, new DefaultPlacement3D(0, 10, 0, 4, 19, 4)); + ep.add(1, createStackPlacement(0, 10, 0, 4, 19, 4)); assertThat(ep.getValues()).hasSize(5); @@ -326,8 +336,8 @@ public void testStackInYDirection(boolean clone) { @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackEqualItemsInXDirection(boolean clone) throws InterruptedException { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValue(0)).isMin(0, 0, 10); assertThat(ep.getValue(0)).isXYSupportAt(9, 9); @@ -355,7 +365,7 @@ public void testStackEqualItemsInXDirection(boolean clone) throws InterruptedExc // |-----|---- x // - ep.add(2, new DefaultPlacement3D(10, 0, 0, 19, 9, 9)); + ep.add(2, createStackPlacement(10, 0, 0, 19, 9, 9)); // y // | @@ -397,8 +407,8 @@ public void testStackEqualItemsInXDirection(boolean clone) throws InterruptedExc @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackEqualItemsInYDirection(boolean clone) throws InterruptedException { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); // y // | @@ -418,7 +428,7 @@ public void testStackEqualItemsInYDirection(boolean clone) throws InterruptedExc // |-----|---- x // - ep.add(1, new DefaultPlacement3D(0, 10, 0, 9, 19, 9)); + ep.add(1, createStackPlacement(0, 10, 0, 9, 19, 9)); // y // | @@ -462,10 +472,10 @@ public void testStackEqualItemsInYDirection(boolean clone) throws InterruptedExc @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackEqualItemsInZDirection(boolean clone) throws InterruptedException { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); - ep.add(0, new DefaultPlacement3D(0, 0, 10, 9, 9, 19)); + ep.add(0, createStackPlacement(0, 0, 10, 9, 9, 19)); // y // | @@ -511,12 +521,12 @@ public void testStackEqualItemsInZDirection(boolean clone) throws InterruptedExc @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackHigherItemsInXDirection(boolean clone) throws InterruptedException { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); - ep.add(2, new DefaultPlacement3D(10, 0, 0, 19, 19, 19)); + ep.add(2, createStackPlacement(10, 0, 0, 19, 19, 19)); assertThat(ep.getValues()).hasSize(5); @@ -570,12 +580,12 @@ public void testStackHigherItemsInXDirection(boolean clone) throws InterruptedEx @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackHigherItemsInYDirection(boolean clone) throws InterruptedException { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); - ep.add(1, new DefaultPlacement3D(0, 10, 0, 19, 19, 19)); + ep.add(1, createStackPlacement(0, 10, 0, 19, 19, 19)); // y // | @@ -623,12 +633,12 @@ public void testStackHigherItemsInYDirection(boolean clone) throws InterruptedEx @ParameterizedTest @ValueSource(booleans = {true, false}) public void testStackHigherItemsInZDirection(boolean clone) throws InterruptedException { - ExtremePoints3D ep = new ExtremePoints3D<>(100, 100, 100, clone); - ep.add(0, new DefaultPlacement3D(0, 0, 0, 9, 9, 9)); + ExtremePoints3D ep = new ExtremePoints3D(100, 100, 100, clone); + ep.add(0, createStackPlacement(0, 0, 0, 9, 9, 9)); assertThat(ep.getValues()).hasSize(3); - ep.add(0, new DefaultPlacement3D(0, 0, 10, 19, 19, 19)); + ep.add(0, createStackPlacement(0, 0, 10, 19, 19, 19)); } } diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint2DEntry.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint2DEntry.java index 57249c0e..baa4d0f3 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint2DEntry.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint2DEntry.java @@ -1,13 +1,13 @@ package com.github.skjolber.packing.jmh.ep; -import com.github.skjolber.packing.ep.points2d.DefaultPlacement2D; +import com.github.skjolber.packing.api.StackPlacement; public class ExtremePoint2DEntry { private final int index; - private final DefaultPlacement2D placement; + private final StackPlacement placement; - public ExtremePoint2DEntry(int index, DefaultPlacement2D placement) { + public ExtremePoint2DEntry(int index, StackPlacement placement) { super(); this.index = index; this.placement = placement; @@ -17,7 +17,7 @@ public int getIndex() { return index; } - public DefaultPlacement2D getPlacement() { + public StackPlacement getPlacement() { return placement; } } diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint3DEntry.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint3DEntry.java index c6c3c623..ffc82226 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint3DEntry.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoint3DEntry.java @@ -1,13 +1,13 @@ package com.github.skjolber.packing.jmh.ep; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; +import com.github.skjolber.packing.api.StackPlacement; public class ExtremePoint3DEntry { private final int index; - private final DefaultPlacement3D placement; + private final StackPlacement placement; - public ExtremePoint3DEntry(int index, DefaultPlacement3D placement) { + public ExtremePoint3DEntry(int index, StackPlacement placement) { super(); this.index = index; this.placement = placement; @@ -17,7 +17,7 @@ public int getIndex() { return index; } - public DefaultPlacement3D getPlacement() { + public StackPlacement getPlacement() { return placement; } } diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints2DState.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints2DState.java index 890e67db..bfe34af0 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints2DState.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints2DState.java @@ -9,9 +9,10 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; -import com.github.skjolber.packing.api.ep.Point2D; -import com.github.skjolber.packing.ep.points2d.DefaultPlacement2D; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.ep.points2d.ExtremePoints2D; +import com.github.skjolber.packing.ep.points2d.Point2D; import com.github.skjolber.packing.test.bouwkamp.BouwkampCode; import com.github.skjolber.packing.test.bouwkamp.BouwkampCodeDirectory; import com.github.skjolber.packing.test.bouwkamp.BouwkampCodeLine; @@ -22,6 +23,12 @@ public class ExtremePoints2DState { private List entries = new ArrayList<>(); + private StackPlacement createStackPlacement(int x, int y, int dx, int dy) { + BoxStackValue stackValue = new BoxStackValue(dx, dy, 0, null, null); + + return new StackPlacement(null, stackValue, x, y, 0); + } + @Setup(Level.Trial) public void init() { // these does not really result in successful stacking, but still should run as expected @@ -36,7 +43,7 @@ public void init() { } private void add(BouwkampCode bkpLine) { - ExtremePoints2D points = new ExtremePoints2D<>(bkpLine.getWidth(), bkpLine.getDepth()); + ExtremePoints2D points = new ExtremePoints2D(bkpLine.getWidth(), bkpLine.getDepth()); ExtremePoints2DEntries extremePointsEntries = new ExtremePoints2DEntries(points); @@ -61,7 +68,7 @@ private void add(BouwkampCode bkpLine) { int factoredSquare = square; - DefaultPlacement2D placement = new DefaultPlacement2D(offset, value.getMinY(), offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1); + StackPlacement placement = createStackPlacement(offset, value.getMinY(), offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1); extremePointsEntries.add(new ExtremePoint2DEntry(nextY, placement)); points.add(nextY, placement); diff --git a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints3DState.java b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints3DState.java index 1e7f46bf..5ac58c12 100644 --- a/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints3DState.java +++ b/jmh/src/main/java/com/github/skjolber/packing/jmh/ep/ExtremePoints3DState.java @@ -9,8 +9,9 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.TearDown; +import com.github.skjolber.packing.api.BoxStackValue; +import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.ep.Point3D; -import com.github.skjolber.packing.ep.points3d.DefaultPlacement3D; import com.github.skjolber.packing.ep.points3d.ExtremePoints3D; import com.github.skjolber.packing.test.bouwkamp.BouwkampCode; import com.github.skjolber.packing.test.bouwkamp.BouwkampCodeDirectory; @@ -22,6 +23,12 @@ public class ExtremePoints3DState { private List entries = new ArrayList<>(); + private StackPlacement createStackPlacement(int x, int y, int z, int dx, int dy, int dz) { + BoxStackValue stackValue = new BoxStackValue(dx, dy, dz, null, null); + + return new StackPlacement(null, stackValue, x, y, z); + } + @Setup(Level.Trial) public void init() { // these does not really result in successful stacking, but still should run as expected @@ -36,7 +43,7 @@ public void init() { } private void add(BouwkampCode bkpLine) { - ExtremePoints3D points = new ExtremePoints3D<>(bkpLine.getWidth(), bkpLine.getDepth(), 1); + ExtremePoints3D points = new ExtremePoints3D(bkpLine.getWidth(), bkpLine.getDepth(), 1); ExtremePoints3DEntries extremePointsEntries = new ExtremePoints3DEntries(points); @@ -58,7 +65,7 @@ private void add(BouwkampCode bkpLine) { Integer square = squares.get(i); int factoredSquare = square; - DefaultPlacement3D defaultPlacement3D = new DefaultPlacement3D(offset, value.getMinY(), 0, offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1, 0); + StackPlacement defaultPlacement3D = createStackPlacement(offset, value.getMinY(), 0, offset + factoredSquare - 1, value.getMinY() + factoredSquare - 1, 0); extremePointsEntries.add(new ExtremePoint3DEntry(nextY, defaultPlacement3D)); points.add(nextY, defaultPlacement3D); diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement2DAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement2DAssert.java deleted file mode 100644 index e6b31de8..00000000 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement2DAssert.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.github.skjolber.packing.test.assertj; - -import org.assertj.core.api.AbstractObjectAssert; - -import com.github.skjolber.packing.api.Placement2D; -import com.github.skjolber.packing.api.Placement3D; - -public abstract class AbstractPlacement2DAssert, ACTUAL extends Placement2D> - extends AbstractObjectAssert { - - protected AbstractPlacement2DAssert(ACTUAL actual, Class selfType) { - super(actual, selfType); - } - - public SELF isAtX(int x) { - isNotNull(); - if(actual.getAbsoluteX() != x) { - failWithExpectedXAt(x); - } - return myself; - } - - private void failWithExpectedXAt(int x) { - failWithMessage("Expected x at " + x); - } - - public SELF isAtY(int y) { - isNotNull(); - if(actual.getAbsoluteY() != y) { - failWithExpectedYAt(y); - } - return myself; - } - - private void failWithExpectedYAt(int y) { - failWithMessage("Expected y at " + y); - } - - public SELF isAt(int x, int y) { - isNotNull(); - if(actual.getAbsoluteX() != x) { - failWithMessage("Expected x " + x + ", not " + actual.getAbsoluteX() + " (was " + getCoordinates() + ")"); - } - if(actual.getAbsoluteY() != y) { - failWithMessage("Expected y " + y + ", not " + actual.getAbsoluteY() + " (was " + getCoordinates() + ")"); - } - return myself; - } - - public SELF isEndAt(int x, int y, int z) { - isNotNull(); - if(actual.getAbsoluteEndX() != x && actual.getAbsoluteEndY() != y) { - failWithMessage("Expected at " + x + "x" + y + "x" + z + ", not " + getEndCoordinates()); - } - if(actual.getAbsoluteEndX() != x) { - failWithMessage("Expected x " + x + ", not " + actual.getAbsoluteEndX() + " (was " + getCoordinates() + ")"); - } - if(actual.getAbsoluteEndY() != y) { - failWithMessage("Expected y " + y + ", not " + actual.getAbsoluteEndY() + " (was " + getCoordinates() + ")"); - } - return myself; - } - - private String getEndCoordinates() { - return actual.getAbsoluteEndX() + "x" + actual.getAbsoluteEndY(); - } - - private String getStartCoordinates() { - return actual.getAbsoluteX() + "x" + actual.getAbsoluteY(); - } - - private String getCoordinates() { - return getStartCoordinates() + " " + getEndCoordinates(); - } - - protected boolean isOverlapX(Placement2D placement) { - - if(placement.getAbsoluteX() <= actual.getAbsoluteX() && actual.getAbsoluteX() <= placement.getAbsoluteEndX()) { - return true; - } - - if(placement.getAbsoluteX() <= actual.getAbsoluteEndX() && actual.getAbsoluteEndX() <= placement.getAbsoluteEndX()) { - return true; - } - - return false; - } - - protected boolean isOverlapY(Placement2D placement) { - if(placement.getAbsoluteY() <= actual.getAbsoluteY() && actual.getAbsoluteY() <= placement.getAbsoluteEndY()) { - return true; - } - - if(placement.getAbsoluteY() <= actual.getAbsoluteEndY() && actual.getAbsoluteEndY() <= placement.getAbsoluteEndY()) { - return true; - } - - return false; - } - - public SELF isAlongsideY(Placement2D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(actual.getAbsoluteEndY() + 1 != other.getAbsoluteY() && other.getAbsoluteEndY() + 1 != actual.getAbsoluteY()) { - failWithMessage("Expected start y at " + (other.getAbsoluteEndY() + 1) + " or end y at " + (other.getAbsoluteY() - 1)); - } - return myself; - } - - public SELF isAlongsideX(Placement2D other) { - isNotNull(); - - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - if(actual.getAbsoluteEndX() + 1 != other.getAbsoluteX() && other.getAbsoluteEndX() + 1 != actual.getAbsoluteX()) { - failWithMessage("Expected start x at " + (other.getAbsoluteEndX() + 1) + " or end x at " + (other.getAbsoluteX() - 1)); - } - return myself; - } - - public SELF followsAlongsideX(Placement2D other) { - isNotNull(); - - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - if(other.getAbsoluteEndX() + 1 != actual.getAbsoluteX()) { - failWithMessage("Expected start x at " + (other.getAbsoluteEndX() + 1)); - } - return myself; - } - - public SELF followsAlongsideY(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - - if(other.getAbsoluteEndY() + 1 != actual.getAbsoluteY()) { - failWithMessage("Expected start y at " + (other.getAbsoluteEndY() + 1)); - } - return myself; - } - - public SELF followsAlongsideZ(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - return myself; - } - - private void failWithNotOverlappingInXDimension() { - failWithMessage("Not overlapping in x dimension"); - } - - private void failWithNotOverlappingInYDimension() { - failWithMessage("Not overlapping in y dimension"); - } - - public SELF preceedsAlongsideY(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - - if(actual.getAbsoluteEndY() + 1 != other.getAbsoluteY()) { - failWithMessage("Expected end y at " + (other.getAbsoluteY() - 1)); - } - return myself; - } - - public SELF preceedsAlongsideX(Placement3D other) { - isNotNull(); - - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - if(actual.getAbsoluteEndX() + 1 != other.getAbsoluteX()) { - failWithMessage("Expected end x at " + (other.getAbsoluteX() - 1)); - } - return myself; - } - - public SELF preceedsAlongsideZ(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - return myself; - } - - /* - public SELF isSupportedBy(Placement3D ... others) { - isNotNull(); - - List supports3d = actual.getSupports2D(); - for (Placement3D other : others) { - if(!supports3d.contains(other)) { - failWithMessage("Not supported by " + other); - } - } - return myself; - } - - public SELF supports(Placement3D ... others) { - isNotNull(); - for (Placement3D other : others) { - List list = other.getSupports3D(); - if(list == null || !list.contains(actual)) { - failWithMessage(actual + " is not supporting " + other + ". Supporters are " + list); - } - } - return myself; - } - */ -} diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement3DAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement3DAssert.java deleted file mode 100644 index fde9010f..00000000 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractPlacement3DAssert.java +++ /dev/null @@ -1,313 +0,0 @@ -package com.github.skjolber.packing.test.assertj; - -import org.assertj.core.api.AbstractObjectAssert; - -import com.github.skjolber.packing.api.Placement3D; - -public abstract class AbstractPlacement3DAssert, ACTUAL extends Placement3D> - extends AbstractObjectAssert { - - protected AbstractPlacement3DAssert(ACTUAL actual, Class selfType) { - super(actual, selfType); - } - - public SELF isAtX(int x) { - isNotNull(); - if(actual.getAbsoluteX() != x) { - failWithExpectedXAt(x); - } - return myself; - } - - private void failWithExpectedXAt(int x) { - failWithMessage("Expected x at " + x); - } - - public SELF isAtY(int y) { - isNotNull(); - if(actual.getAbsoluteY() != y) { - failWithExpectedYAt(y); - } - return myself; - } - - private void failWithExpectedYAt(int y) { - failWithMessage("Expected y at " + y); - } - - public SELF isAtZ(int z) { - isNotNull(); - if(actual.getAbsoluteZ() != z) { - failWithExpectedZAt(z); - } - return myself; - } - - private void failWithExpectedZAt(int z) { - failWithMessage("Expected z at " + z); - } - - public SELF isAt(int x, int y, int z) { - isNotNull(); - if(actual.getAbsoluteX() != x && actual.getAbsoluteY() != y && actual.getAbsoluteZ() != z) { - failWithMessage("Expected at " + x + "x" + y + "x" + z + ", not " + getStartCoordinates()); - } - if(actual.getAbsoluteX() != x) { - failWithMessage("Expected x " + x + ", not " + actual.getAbsoluteX() + " (was " + getCoordinates() + ")"); - } - if(actual.getAbsoluteY() != y) { - failWithMessage("Expected y " + y + ", not " + actual.getAbsoluteY() + " (was " + getCoordinates() + ")"); - } - if(actual.getAbsoluteZ() != z) { - failWithMessage("Expected z " + y + ", not " + actual.getAbsoluteZ() + " (was " + getCoordinates() + ")"); - } - return myself; - } - - public SELF isEndAt(int x, int y, int z) { - isNotNull(); - if(actual.getAbsoluteEndX() != x && actual.getAbsoluteEndY() != y && actual.getAbsoluteEndZ() != z) { - failWithMessage("Expected at " + x + "x" + y + "x" + z + ", not " + getEndCoordinates()); - } - if(actual.getAbsoluteEndX() != x) { - failWithMessage("Expected x " + x + ", not " + actual.getAbsoluteEndX() + " (was " + getCoordinates() + ")"); - } - if(actual.getAbsoluteEndY() != y) { - failWithMessage("Expected y " + y + ", not " + actual.getAbsoluteEndY() + " (was " + getCoordinates() + ")"); - } - if(actual.getAbsoluteEndZ() != z) { - failWithMessage("Expected z " + y + ", not " + actual.getAbsoluteEndZ() + " (was " + getCoordinates() + ")"); - } - return myself; - } - - private String getEndCoordinates() { - return actual.getAbsoluteEndX() + "x" + actual.getAbsoluteEndY() + "x" + actual.getAbsoluteEndZ(); - } - - private String getStartCoordinates() { - return actual.getAbsoluteX() + "x" + actual.getAbsoluteY() + "x" + actual.getAbsoluteZ(); - } - - private String getCoordinates() { - return getStartCoordinates() + " " + getEndCoordinates(); - } - - protected boolean isOverlapX(Placement3D placement) { - - if(placement.getAbsoluteX() <= actual.getAbsoluteX() && actual.getAbsoluteX() <= placement.getAbsoluteEndX()) { - return true; - } - - if(placement.getAbsoluteX() <= actual.getAbsoluteEndX() && actual.getAbsoluteEndX() <= placement.getAbsoluteEndX()) { - return true; - } - - return false; - } - - protected boolean isOverlapY(Placement3D placement) { - if(placement.getAbsoluteY() <= actual.getAbsoluteY() && actual.getAbsoluteY() <= placement.getAbsoluteEndY()) { - return true; - } - - if(placement.getAbsoluteY() <= actual.getAbsoluteEndY() && actual.getAbsoluteEndY() <= placement.getAbsoluteEndY()) { - return true; - } - - return false; - } - - protected boolean isOverlapZ(Placement3D placement) { - if(placement.getAbsoluteZ() <= actual.getAbsoluteZ() && actual.getAbsoluteZ() <= placement.getAbsoluteEndZ()) { - return true; - } - - if(placement.getAbsoluteZ() <= actual.getAbsoluteEndZ() && actual.getAbsoluteEndZ() <= placement.getAbsoluteEndZ()) { - return true; - } - - return false; - } - - public SELF isAlongsideY(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapZ(other)) { - failWithNotOverlappingInZDimension(); - } - - if(actual.getAbsoluteEndY() + 1 != other.getAbsoluteY() && other.getAbsoluteEndY() + 1 != actual.getAbsoluteY()) { - failWithMessage("Expected start y at " + (other.getAbsoluteEndY() + 1) + " or end y at " + (other.getAbsoluteY() - 1)); - } - return myself; - } - - public SELF isAlongsideX(Placement3D other) { - isNotNull(); - - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - if(!isOverlapZ(other)) { - failWithNotOverlappingInZDimension(); - } - - if(actual.getAbsoluteEndX() + 1 != other.getAbsoluteX() && other.getAbsoluteEndX() + 1 != actual.getAbsoluteX()) { - failWithMessage("Expected start x at " + (other.getAbsoluteEndX() + 1) + " or end x at " + (other.getAbsoluteX() - 1)); - } - return myself; - } - - public SELF isAlongsideZ(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - if(actual.getAbsoluteEndZ() + 1 != other.getAbsoluteZ() && other.getAbsoluteEndZ() + 1 != actual.getAbsoluteZ()) { - failWithMessage("Expected start z at " + (other.getAbsoluteEndZ() + 1) + " or end z at " + (other.getAbsoluteZ() - 1)); - } - return myself; - } - - public SELF followsAlongsideX(Placement3D other) { - isNotNull(); - - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - if(!isOverlapZ(other)) { - failWithNotOverlappingInZDimension(); - } - - if(other.getAbsoluteEndX() + 1 != actual.getAbsoluteX()) { - failWithMessage("Expected start x at " + (other.getAbsoluteEndX() + 1)); - } - return myself; - } - - public SELF followsAlongsideY(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapZ(other)) { - failWithNotOverlappingInZDimension(); - } - - if(other.getAbsoluteEndY() + 1 != actual.getAbsoluteY()) { - failWithMessage("Expected start y at " + (other.getAbsoluteEndY() + 1)); - } - return myself; - } - - public SELF followsAlongsideZ(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - if(other.getAbsoluteEndZ() + 1 != actual.getAbsoluteZ()) { - failWithMessage("Expected start z at " + (other.getAbsoluteEndZ() + 1)); - } - return myself; - } - - public SELF preceedsAlongsideY(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapZ(other)) { - failWithNotOverlappingInZDimension(); - } - - if(actual.getAbsoluteEndY() + 1 != other.getAbsoluteY()) { - failWithMessage("Expected end y at " + (other.getAbsoluteY() - 1)); - } - return myself; - } - - public SELF preceedsAlongsideX(Placement3D other) { - isNotNull(); - - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - if(!isOverlapZ(other)) { - failWithNotOverlappingInZDimension(); - } - - if(actual.getAbsoluteEndX() + 1 != other.getAbsoluteX()) { - failWithMessage("Expected end x at " + (other.getAbsoluteX() - 1)); - } - return myself; - } - - public SELF preceedsAlongsideZ(Placement3D other) { - isNotNull(); - - if(!isOverlapX(other)) { - failWithNotOverlappingInXDimension(); - } - if(!isOverlapY(other)) { - failWithNotOverlappingInYDimension(); - } - - if(actual.getAbsoluteEndZ() + 1 != other.getAbsoluteZ()) { - failWithMessage("Expected end z at " + (other.getAbsoluteZ() - 1)); - } - return myself; - } - - private void failWithNotOverlappingInZDimension() { - failWithMessage("Not overlapping in z dimension"); - } - - private void failWithNotOverlappingInXDimension() { - failWithMessage("Not overlapping in x dimension"); - } - - private void failWithNotOverlappingInYDimension() { - failWithMessage("Not overlapping in y dimension"); - } - - /* - public SELF isSupportedBy(Placement3D ... others) { - isNotNull(); - - List supports3d = actual.getSupports3D(); - for (Placement3D other : others) { - if(!supports3d.contains(other)) { - failWithMessage("Not supported by " + other); - } - } - return myself; - } - - public SELF supports(Placement3D ... others) { - isNotNull(); - for (Placement3D other : others) { - List list = other.getSupports3D(); - if(list == null || !list.contains(actual)) { - failWithMessage(actual + " is not supporting " + other + ". Supporters are " + list); - } - } - return myself; - } - */ -} diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractStackPlacementAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractStackPlacementAssert.java index cc8336d6..6592b028 100644 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractStackPlacementAssert.java +++ b/test/src/main/java/com/github/skjolber/packing/test/assertj/AbstractStackPlacementAssert.java @@ -2,16 +2,319 @@ import java.util.Objects; +import org.assertj.core.api.AbstractObjectAssert; + import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.StackValue; +import com.github.skjolber.packing.api.StackPlacement; public abstract class AbstractStackPlacementAssert, ACTUAL extends StackPlacement> - extends AbstractPlacement3DAssert { + extends AbstractObjectAssert { protected AbstractStackPlacementAssert(ACTUAL actual, Class selfType) { super(actual, selfType); } + public SELF isAtX(int x) { + isNotNull(); + if(actual.getAbsoluteX() != x) { + failWithExpectedXAt(x); + } + return myself; + } + + private void failWithExpectedXAt(int x) { + failWithMessage("Expected x at " + x); + } + + public SELF isAtY(int y) { + isNotNull(); + if(actual.getAbsoluteY() != y) { + failWithExpectedYAt(y); + } + return myself; + } + + private void failWithExpectedYAt(int y) { + failWithMessage("Expected y at " + y); + } + + public SELF isAtZ(int z) { + isNotNull(); + if(actual.getAbsoluteZ() != z) { + failWithExpectedZAt(z); + } + return myself; + } + + private void failWithExpectedZAt(int z) { + failWithMessage("Expected z at " + z); + } + + public SELF isAt(int x, int y, int z) { + isNotNull(); + if(actual.getAbsoluteX() != x && actual.getAbsoluteY() != y && actual.getAbsoluteZ() != z) { + failWithMessage("Expected at " + x + "x" + y + "x" + z + ", not " + getStartCoordinates()); + } + if(actual.getAbsoluteX() != x) { + failWithMessage("Expected x " + x + ", not " + actual.getAbsoluteX() + " (was " + getCoordinates() + ")"); + } + if(actual.getAbsoluteY() != y) { + failWithMessage("Expected y " + y + ", not " + actual.getAbsoluteY() + " (was " + getCoordinates() + ")"); + } + if(actual.getAbsoluteZ() != z) { + failWithMessage("Expected z " + y + ", not " + actual.getAbsoluteZ() + " (was " + getCoordinates() + ")"); + } + return myself; + } + + public SELF isEndAt(int x, int y, int z) { + isNotNull(); + if(actual.getAbsoluteEndX() != x && actual.getAbsoluteEndY() != y && actual.getAbsoluteEndZ() != z) { + failWithMessage("Expected at " + x + "x" + y + "x" + z + ", not " + getEndCoordinates()); + } + if(actual.getAbsoluteEndX() != x) { + failWithMessage("Expected x " + x + ", not " + actual.getAbsoluteEndX() + " (was " + getCoordinates() + ")"); + } + if(actual.getAbsoluteEndY() != y) { + failWithMessage("Expected y " + y + ", not " + actual.getAbsoluteEndY() + " (was " + getCoordinates() + ")"); + } + if(actual.getAbsoluteEndZ() != z) { + failWithMessage("Expected z " + y + ", not " + actual.getAbsoluteEndZ() + " (was " + getCoordinates() + ")"); + } + return myself; + } + + private String getEndCoordinates() { + return actual.getAbsoluteEndX() + "x" + actual.getAbsoluteEndY() + "x" + actual.getAbsoluteEndZ(); + } + + private String getStartCoordinates() { + return actual.getAbsoluteX() + "x" + actual.getAbsoluteY() + "x" + actual.getAbsoluteZ(); + } + + private String getCoordinates() { + return getStartCoordinates() + " " + getEndCoordinates(); + } + + protected boolean isOverlapX(StackPlacement placement) { + + if(placement.getAbsoluteX() <= actual.getAbsoluteX() && actual.getAbsoluteX() <= placement.getAbsoluteEndX()) { + return true; + } + + if(placement.getAbsoluteX() <= actual.getAbsoluteEndX() && actual.getAbsoluteEndX() <= placement.getAbsoluteEndX()) { + return true; + } + + return false; + } + + protected boolean isOverlapY(StackPlacement placement) { + if(placement.getAbsoluteY() <= actual.getAbsoluteY() && actual.getAbsoluteY() <= placement.getAbsoluteEndY()) { + return true; + } + + if(placement.getAbsoluteY() <= actual.getAbsoluteEndY() && actual.getAbsoluteEndY() <= placement.getAbsoluteEndY()) { + return true; + } + + return false; + } + + protected boolean isOverlapZ(StackPlacement placement) { + if(placement.getAbsoluteZ() <= actual.getAbsoluteZ() && actual.getAbsoluteZ() <= placement.getAbsoluteEndZ()) { + return true; + } + + if(placement.getAbsoluteZ() <= actual.getAbsoluteEndZ() && actual.getAbsoluteEndZ() <= placement.getAbsoluteEndZ()) { + return true; + } + + return false; + } + + public SELF isAlongsideY(StackPlacement other) { + isNotNull(); + + if(!isOverlapX(other)) { + failWithNotOverlappingInXDimension(); + } + if(!isOverlapZ(other)) { + failWithNotOverlappingInZDimension(); + } + + if(actual.getAbsoluteEndY() + 1 != other.getAbsoluteY() && other.getAbsoluteEndY() + 1 != actual.getAbsoluteY()) { + failWithMessage("Expected start y at " + (other.getAbsoluteEndY() + 1) + " or end y at " + (other.getAbsoluteY() - 1)); + } + return myself; + } + + public SELF isAlongsideX(StackPlacement other) { + isNotNull(); + + if(!isOverlapY(other)) { + failWithNotOverlappingInYDimension(); + } + if(!isOverlapZ(other)) { + failWithNotOverlappingInZDimension(); + } + + if(actual.getAbsoluteEndX() + 1 != other.getAbsoluteX() && other.getAbsoluteEndX() + 1 != actual.getAbsoluteX()) { + failWithMessage("Expected start x at " + (other.getAbsoluteEndX() + 1) + " or end x at " + (other.getAbsoluteX() - 1)); + } + return myself; + } + + public SELF isAlongsideZ(StackPlacement other) { + isNotNull(); + + if(!isOverlapX(other)) { + failWithNotOverlappingInXDimension(); + } + if(!isOverlapY(other)) { + failWithNotOverlappingInYDimension(); + } + + if(actual.getAbsoluteEndZ() + 1 != other.getAbsoluteZ() && other.getAbsoluteEndZ() + 1 != actual.getAbsoluteZ()) { + failWithMessage("Expected start z at " + (other.getAbsoluteEndZ() + 1) + " or end z at " + (other.getAbsoluteZ() - 1)); + } + return myself; + } + + public SELF followsAlongsideX(StackPlacement other) { + isNotNull(); + + if(!isOverlapY(other)) { + failWithNotOverlappingInYDimension(); + } + if(!isOverlapZ(other)) { + failWithNotOverlappingInZDimension(); + } + + if(other.getAbsoluteEndX() + 1 != actual.getAbsoluteX()) { + failWithMessage("Expected start x at " + (other.getAbsoluteEndX() + 1)); + } + return myself; + } + + public SELF followsAlongsideY(StackPlacement other) { + isNotNull(); + + if(!isOverlapX(other)) { + failWithNotOverlappingInXDimension(); + } + if(!isOverlapZ(other)) { + failWithNotOverlappingInZDimension(); + } + + if(other.getAbsoluteEndY() + 1 != actual.getAbsoluteY()) { + failWithMessage("Expected start y at " + (other.getAbsoluteEndY() + 1)); + } + return myself; + } + + public SELF followsAlongsideZ(StackPlacement other) { + isNotNull(); + + if(!isOverlapX(other)) { + failWithNotOverlappingInXDimension(); + } + if(!isOverlapY(other)) { + failWithNotOverlappingInYDimension(); + } + + if(other.getAbsoluteEndZ() + 1 != actual.getAbsoluteZ()) { + failWithMessage("Expected start z at " + (other.getAbsoluteEndZ() + 1)); + } + return myself; + } + + public SELF preceedsAlongsideY(StackPlacement other) { + isNotNull(); + + if(!isOverlapX(other)) { + failWithNotOverlappingInXDimension(); + } + if(!isOverlapZ(other)) { + failWithNotOverlappingInZDimension(); + } + + if(actual.getAbsoluteEndY() + 1 != other.getAbsoluteY()) { + failWithMessage("Expected end y at " + (other.getAbsoluteY() - 1)); + } + return myself; + } + + public SELF preceedsAlongsideX(StackPlacement other) { + isNotNull(); + + if(!isOverlapY(other)) { + failWithNotOverlappingInYDimension(); + } + if(!isOverlapZ(other)) { + failWithNotOverlappingInZDimension(); + } + + if(actual.getAbsoluteEndX() + 1 != other.getAbsoluteX()) { + failWithMessage("Expected end x at " + (other.getAbsoluteX() - 1)); + } + return myself; + } + + public SELF preceedsAlongsideZ(StackPlacement other) { + isNotNull(); + + if(!isOverlapX(other)) { + failWithNotOverlappingInXDimension(); + } + if(!isOverlapY(other)) { + failWithNotOverlappingInYDimension(); + } + + if(actual.getAbsoluteEndZ() + 1 != other.getAbsoluteZ()) { + failWithMessage("Expected end z at " + (other.getAbsoluteZ() - 1)); + } + return myself; + } + + private void failWithNotOverlappingInZDimension() { + failWithMessage("Not overlapping in z dimension"); + } + + private void failWithNotOverlappingInXDimension() { + failWithMessage("Not overlapping in x dimension"); + } + + private void failWithNotOverlappingInYDimension() { + failWithMessage("Not overlapping in y dimension"); + } + + /* + public SELF isSupportedBy(StackPlacement ... others) { + isNotNull(); + + List supports3d = actual.getSupports3D(); + for (StackPlacement other : others) { + if(!supports3d.contains(other)) { + failWithMessage("Not supported by " + other); + } + } + return myself; + } + + public SELF supports(StackPlacement ... others) { + isNotNull(); + for (StackPlacement other : others) { + List list = other.getSupports3D(); + if(list == null || !list.contains(actual)) { + failWithMessage(actual + " is not supporting " + other + ". Supporters are " + list); + } + } + return myself; + } + */ + public SELF hasStackableName(String name) { isNotNull(); if(!Objects.equals(name, actual.getStackable().getDescription())) { diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/Placement2DAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/Placement2DAssert.java deleted file mode 100644 index 87c7e3e9..00000000 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/Placement2DAssert.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.skjolber.packing.test.assertj; - -import com.github.skjolber.packing.api.Placement2D; - -public class Placement2DAssert extends AbstractPlacement2DAssert { - - public static Placement2DAssert assertThat(Placement2D actual) { - return new Placement2DAssert(actual); - } - - public Placement2DAssert(Placement2D actual) { - super(actual, Placement2DAssert.class); - } - -} diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/Placement3DAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/Placement3DAssert.java deleted file mode 100644 index d64482b9..00000000 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/Placement3DAssert.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.skjolber.packing.test.assertj; - -import com.github.skjolber.packing.api.Placement3D; - -public class Placement3DAssert extends AbstractPlacement3DAssert { - - public static Placement3DAssert assertThat(Placement3D actual) { - return new Placement3DAssert(actual); - } - - public Placement3DAssert(Placement3D actual) { - super(actual, Placement3DAssert.class); - } - -} diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/StackPlacementAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/StackPlacementAssert.java new file mode 100644 index 00000000..aea82bca --- /dev/null +++ b/test/src/main/java/com/github/skjolber/packing/test/assertj/StackPlacementAssert.java @@ -0,0 +1,15 @@ +package com.github.skjolber.packing.test.assertj; + +import com.github.skjolber.packing.api.StackPlacement; + +public class StackPlacementAssert extends AbstractStackPlacementAssert { + + public static StackPlacementAssert assertThat(StackPlacement actual) { + return new StackPlacementAssert(actual); + } + + public StackPlacementAssert(StackPlacement actual) { + super(actual, StackPlacementAssert.class); + } + +} diff --git a/test/src/main/java/com/github/skjolber/packing/test/assertj/StackablePlacementAssert.java b/test/src/main/java/com/github/skjolber/packing/test/assertj/StackablePlacementAssert.java deleted file mode 100644 index 327bcbce..00000000 --- a/test/src/main/java/com/github/skjolber/packing/test/assertj/StackablePlacementAssert.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.github.skjolber.packing.test.assertj; - -import com.github.skjolber.packing.api.StackPlacement; - -public class StackablePlacementAssert extends AbstractStackPlacementAssert { - - public static StackablePlacementAssert assertThat(StackPlacement actual) { - return new StackablePlacementAssert(actual); - } - - public StackablePlacementAssert(StackPlacement actual) { - super(actual, StackablePlacementAssert.class); - } - -} diff --git a/visualizer/packaging/src/main/java/com/github/skjolber/packing/visualizer/packaging/DefaultPackagingResultVisualizerFactory.java b/visualizer/packaging/src/main/java/com/github/skjolber/packing/visualizer/packaging/DefaultPackagingResultVisualizerFactory.java index fbdd3adc..682cd752 100644 --- a/visualizer/packaging/src/main/java/com/github/skjolber/packing/visualizer/packaging/DefaultPackagingResultVisualizerFactory.java +++ b/visualizer/packaging/src/main/java/com/github/skjolber/packing/visualizer/packaging/DefaultPackagingResultVisualizerFactory.java @@ -9,6 +9,7 @@ import com.github.skjolber.packing.api.StackPlacement; import com.github.skjolber.packing.api.StackValue; import com.github.skjolber.packing.api.Stackable; +import com.github.skjolber.packing.api.ep.Point3D; import com.github.skjolber.packing.ep.points3d.ExtremePoints3D; import com.github.skjolber.packing.ep.points3d.SimplePoint3D; import com.github.skjolber.packing.visualizer.api.packaging.BoxVisualizer; @@ -59,7 +60,7 @@ public PackagingResultVisualizer visualize(List inputContainers) { Stack stack = inputContainer.getStack(); - ExtremePoints3D extremePoints = new ExtremePoints3D<>(containerStackValue.getDx(), containerStackValue.getDy(), containerStackValue.getDz(), true); + ExtremePoints3D extremePoints = new ExtremePoints3D(containerStackValue.getDx(), containerStackValue.getDy(), containerStackValue.getDz(), true); for (StackPlacement placement : stack.getPlacements()) { Stackable box = placement.getStackable(); @@ -91,7 +92,7 @@ public PackagingResultVisualizer visualize(List inputContainers) { } else { extremePoints.add(pointIndex, placement); - for (SimplePoint3D point : extremePoints.getValues()) { + for (Point3D point : extremePoints.getValues()) { PointVisualizer p = new PointVisualizer(); p.setX(point.getMinX()); diff --git a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java index 5218f5b2..7731a559 100644 --- a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java +++ b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/BruteForcePackagerTest.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.visualizer.packaging; -import static com.github.skjolber.packing.test.assertj.StackablePlacementAssert.assertThat; +import static com.github.skjolber.packing.test.assertj.StackPlacementAssert.assertThat; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertFalse; diff --git a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/FastBruteForcePackagerTest.java b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/FastBruteForcePackagerTest.java index 4bbb5346..6a6f09d6 100644 --- a/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/FastBruteForcePackagerTest.java +++ b/visualizer/packaging/src/test/java/com/github/skjolber/packing/visualizer/packaging/FastBruteForcePackagerTest.java @@ -1,6 +1,6 @@ package com.github.skjolber.packing.visualizer.packaging; -import static com.github.skjolber.packing.test.assertj.StackablePlacementAssert.assertThat; +import static com.github.skjolber.packing.test.assertj.StackPlacementAssert.assertThat; import static org.junit.Assert.assertFalse; import java.util.ArrayList;