Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswoehlke committed Dec 20, 2022
1 parent 7812f2b commit 7155abc
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@Deprecated
public class Bounds implements Serializable {

private static final long serialVersionUID = 242L;
static final long serialVersionUID = 242L;

private final int myStartX;
private final int myStartY;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.woehlke.computer.kurzweil.simulated.evolution.model.food.molecules;

import lombok.*;
import lombok.extern.log4j.Log4j2;

import java.io.Serializable;

@Log4j2
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
public class LatticeDimension implements Serializable {

static final long serialVersionUID = 242L;

/**
* Horizontal X-Coordinate. Also used as Width;
*/
private int width;

/**
* Vertical Y-Coordinate. Also used as Height;
*/
private int height;

public void absoluteValue() {
width *= Integer.signum(width);
height *= Integer.signum(height);
}

public void plus(LatticeDimension p) {
this.width += p.getWidth();
this.height += p.getHeight();
absoluteValue();
}

public LatticeDimension copy() {
return new LatticeDimension(
this.getWidth(),
this.getHeight()
);
}

public LatticePoint toLatticePoint() {
return new LatticePoint(
this.getWidth(),
this.getHeight()
);
}

public static LatticeDimension of(LatticePoint p) {
return new LatticeDimension(p.getX(), p.getY());
}

public static LatticeDimension of(LatticeDimension p) {
return LatticeDimension.of(p.toLatticePoint());
}

public static LatticeDimension of(int width, int height) {
return new LatticeDimension(width, height);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,18 @@ public class LatticePoint implements Serializable {
/**
* Horizontal X-Coordinate. Also used as Width;
*/
private int x = 0;
private int x;

/**
* Vertical Y-Coordinate. Also used as Height;
*/
private int y = 0;
private int y;

public LatticePoint(LatticePoint other) {
this.x = other.getX();
this.y = other.getY();
}

// TODO: remove
@Deprecated
public int getWidth() {
return x;
}

// TODO: remove
@Deprecated
public int getHeight() {
return y;
}

public void absoluteValue() {
x *= Integer.signum(x);
y *= Integer.signum(y);
Expand All @@ -74,49 +62,32 @@ public void plus(LatticePoint p) {
this.y += p.getY();
absoluteValue();
}

public void add(LatticePoint p) {
this.x += p.getX();
this.y += p.getY();
}

public void moveBy(LatticePoint p) {
this.add(p);
}

public void normalize(LatticePoint p) {
this.x %= p.getX();
this.y %= p.getY();
}

public void moveUp() {
y--;
}

public void moveRight() {
x++;
}

public void moveDown() {
y++;
}

public void moveLeft() {
x--;
}

public LatticePoint copy() {
return new LatticePoint(this);
}

// TODO: remove
@Deprecated
public static LatticePoint start(LatticePoint worldDimensions) {
return new LatticePoint(
(worldDimensions.getX() - 2),
((worldDimensions.getY() / 2) + 11)
public LatticeDimension toLatticePoint() {
return new LatticeDimension(
this.getX(),
this.getY()
);
}

public static LatticePoint of(LatticeDimension p) {
return new LatticePoint(p.getWidth(), p.getHeight());
}

/**
* Get Neighbourhood.
* @param max - limit the dimensions of the world around
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.woehlke.computer.kurzweil.simulated.evolution.model.food.molecules;

import lombok.*;
import lombok.extern.log4j.Log4j2;

import java.io.Serializable;

@Log4j2
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode
public class LatticeRectangle implements Serializable {

static final long serialVersionUID = 242L;

private LatticePoint start;

private LatticeDimension dimension;

public static LatticeRectangle of(LatticePoint start, LatticeDimension dimension){
LatticeRectangle lb = new LatticeRectangle(start, dimension);
return lb;
}

public static LatticeRectangle of(int startX, int startY, int width, int height){
LatticePoint start = new LatticePoint(startX, startY);
LatticeDimension dimension = new LatticeDimension(width, height);
LatticeRectangle lb = new LatticeRectangle(start, dimension);
return lb;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import org.woehlke.computer.kurzweil.simulated.evolution.control.SimulatedEvolutionController;
import org.woehlke.computer.kurzweil.simulated.evolution.model.SimulatedEvolutionModel;
import org.woehlke.computer.kurzweil.simulated.evolution.application.SimulatedEvolutionParameter;
import org.woehlke.computer.kurzweil.simulated.evolution.model.food.molecules.LatticeDimension;
import org.woehlke.computer.kurzweil.simulated.evolution.model.food.molecules.LatticePoint;
import org.woehlke.computer.kurzweil.simulated.evolution.model.food.molecules.LatticeRectangle;
import org.woehlke.computer.kurzweil.simulated.evolution.view.canvas.SimulatedEvolutionCanvas;
import org.woehlke.computer.kurzweil.simulated.evolution.view.census.PopulationStatisticsElementsPanelCounted;
import org.woehlke.computer.kurzweil.simulated.evolution.view.census.PopulationStatisticsElementsPanelLifeCycle;
Expand Down Expand Up @@ -101,20 +103,10 @@ public class SimulatedEvolutionTab extends JFrame implements MenuContainer,
private final ComputerKurzweilProperties properties;

/**
* TODO: refactor, replace Rectangle with a class based on LatticePoint
* @see java.awt.Rectangle
* @see LatticePoint
*/
@Deprecated
private volatile Rectangle rectangleBounds;

/**
* TODO: refactor, replace Dimension with a class based on LatticePoint
* @see java.awt.Dimension
* @see LatticePoint
*/
@Deprecated
private volatile Dimension dimensionSize;
private volatile LatticeRectangle rectangleBounds;

public SimulatedEvolutionTab(ComputerKurzweilProperties properties) {
super(properties.getSimulatedevolution().getView().getTitle());
Expand Down Expand Up @@ -147,27 +139,31 @@ public void showMeInit() {
int heightOfTitle = properties.getSimulatedevolution().getView().getHeightOfTitle();
int heightOfStatistics = properties.getSimulatedevolution().getView().getHeightOfStatistics();
int titleHeight = heightOfTitle + heightOfStatistics;
int width = this.getModel().getWorldDimensions().getWidth();
int height = this.getModel().getWorldDimensions().getHeight() + titleHeight;
int width = this.getModel().getWorldDimensions().getX();
int height = this.getModel().getWorldDimensions().getY() + titleHeight;
double dStartX = (screenSize.getWidth() - width) / 2d;
double dStartY = (screenSize.getHeight() - height) / 2d;
int iStartX = Double.valueOf(dStartX).intValue();
int iStartY = Double.valueOf(dStartY).intValue();
int iWidth = Double.valueOf(width).intValue();
int iHeight = Double.valueOf(height).intValue();
this.rectangleBounds = new Rectangle(iStartX, iStartY, iWidth, iHeight);
this.dimensionSize = new Dimension(iWidth, iHeight);
this.rectangleBounds = LatticeRectangle.of(iStartX, iStartY, iWidth, iHeight);
showMe();
}

/**
* Things to do, to show the Application Window again.
*/

public void showMe(){
this.setBounds(this.rectangleBounds);
this.setSize(this.dimensionSize);
this.setPreferredSize(this.dimensionSize);
int x = this.rectangleBounds.getStart().getX();
int y = this.rectangleBounds.getStart().getY();
int width = this.rectangleBounds.getDimension().getWidth();
int height = this.rectangleBounds.getDimension().getHeight();
Rectangle r = new Rectangle(x,y,width,height);
Dimension d = new Dimension(width,height);
this.setBounds(r);
this.setSize(d);
this.setPreferredSize(d);
setVisible(true);
toFront();
}
Expand Down

0 comments on commit 7155abc

Please sign in to comment.