Skip to content

Commit

Permalink
Rewrites the Ellipse/RectanglePrinter classes to use Point/Dimension …
Browse files Browse the repository at this point in the history
…objs.
  • Loading branch information
Valkryst committed Sep 28, 2017
1 parent 93dfb47 commit 5dc9667
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 148 deletions.
55 changes: 21 additions & 34 deletions src/com/valkryst/VTerminal/printer/EllipsePrinter.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
import com.valkryst.VTerminal.misc.ShapeAlgorithms;
import lombok.*;

import java.awt.Dimension;
import java.awt.Point;

@EqualsAndHashCode
@ToString
public class EllipsePrinter {
/** The width of the ellipse to print. */
@Getter private int width = 2;
/** The height of the ellipse to print. */
@Getter private int height = 2;
/** The width/height of the ellipse to print. */
@Getter private final Dimension dimensions = new Dimension(2, 2);

/** The character to print the ellipse with. */
@Getter @Setter private char printChar = '█';
Expand All @@ -24,17 +23,14 @@ public class EllipsePrinter {
* @param panel
* The panel.
*
* @param row
* The y-axis (row) coordinate of the top-left character.
*
* @param column
* The x-axis (column) coordinate of the top-left character.
* @param position
* The x/y-axis (column/row) coordinates of the top-left character.
*
* @throws NullPointerException
* If the panel is null.
*/
public void print(final @NonNull Panel panel, final int row, final int column) {
print(panel.getScreen(), row, column);
public void print(final @NonNull Panel panel, final Point position) {
print(panel.getScreen(), position);
}

/**
Expand All @@ -43,17 +39,14 @@ public void print(final @NonNull Panel panel, final int row, final int column) {
* @param screen
* The screen.
*
* @param row
* The y-axis (row) coordinate of the top-left character.
*
* @param column
* The x-axis (column) coordinate of the top-left character.
* @param position
* The x/y-axis (column/row) coordinates of the top-left character.
*
* @throws NullPointerException
* If the screen is null.
*/
public void print(final @NonNull Screen screen, final int row, final int column) {
for (final Point point : ShapeAlgorithms.getEllipse(column, row, width, height)) {
public void print(final @NonNull Screen screen, final Point position) {
for (final Point point : ShapeAlgorithms.getEllipse(position, dimensions)) {
screen.write(printChar, point);
}
}
Expand All @@ -64,17 +57,14 @@ public void print(final @NonNull Screen screen, final int row, final int column)
* @param panel
* The panel.
*
* @param row
* The y-axis (row) coordinate of the top-left character.
*
* @param column
* The x-axis (column) coordinate of the top-left character.
* @param position
* The x/y-axis (column/row) coordinates of the top-left character.
*
* @throws NullPointerException
* If the panel is null.
*/
public void printFilled(final @NonNull Panel panel, final int row, final int column) {
printFilled(panel.getScreen(), row, column);
public void printFilled(final @NonNull Panel panel, final Point position) {
printFilled(panel.getScreen(), position);
}

/**
Expand All @@ -83,17 +73,14 @@ public void printFilled(final @NonNull Panel panel, final int row, final int col
* @param screen
* The screen.
*
* @param row
* The y-axis (row) coordinate of the top-left character.
*
* @param column
* The x-axis (column) coordinate of the top-left character.
* @param position
* The x/y-axis (column/row) coordinates of the top-left character.
*
* @throws NullPointerException
* If the screen is null.
*/
public void printFilled(final @NonNull Screen screen, final int row, final int column) {
for (final Point point : ShapeAlgorithms.getFilledEllipse(column, row, width, height)) {
public void printFilled(final @NonNull Screen screen, final Point position) {
for (final Point point : ShapeAlgorithms.getFilledEllipse(position, dimensions)) {
screen.write(printChar, point);
}
}
Expand All @@ -109,7 +96,7 @@ public void printFilled(final @NonNull Screen screen, final int row, final int c
*/
public EllipsePrinter setWidth(final int width) {
if (width > 0) {
this.width = width;
dimensions.setSize(width, dimensions.height);
}

return this;
Expand All @@ -126,7 +113,7 @@ public EllipsePrinter setWidth(final int width) {
*/
public EllipsePrinter setHeight(final int height) {
if (height > 0) {
this.height = height;
dimensions.setSize(dimensions.width, height);
}

return this;
Expand Down
Loading

0 comments on commit 5dc9667

Please sign in to comment.