Compare commits
6 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f9c3d6d50 | |||
| fedac0bb72 | |||
| b89b87d7e9 | |||
| cae4221157 | |||
| 5ef5837349 | |||
| f616f0ad10 |
3 changed files with 51 additions and 35 deletions
38
.drone.yml
38
.drone.yml
|
|
@ -3,36 +3,36 @@ type: docker
|
||||||
name: default
|
name: default
|
||||||
steps:
|
steps:
|
||||||
- name: build
|
- name: build
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-25
|
||||||
commands:
|
commands:
|
||||||
- mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
- mvn clean install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
|
||||||
when:
|
when:
|
||||||
ref:
|
ref:
|
||||||
include:
|
include:
|
||||||
- refs/head/master
|
- refs/head/main
|
||||||
- refs/head/feature/**
|
- refs/head/feature/**
|
||||||
- refs/tags/**
|
- refs/tags/**
|
||||||
- name: test
|
- name: test
|
||||||
image: maven:3.9-eclipse-temurin-21
|
image: maven:3.9-eclipse-temurin-25
|
||||||
commands:
|
commands:
|
||||||
- mvn test -B
|
- mvn test -B
|
||||||
when:
|
when:
|
||||||
branch:
|
branch:
|
||||||
include:
|
include:
|
||||||
- master
|
- main
|
||||||
- feature/*
|
- feature/*
|
||||||
- name: deploy
|
# - name: deploy
|
||||||
image: maven:3.9-eclipse-temurin-21
|
# image: maven:3.9-eclipse-temurin-25
|
||||||
environment:
|
# environment:
|
||||||
REPO_TOKEN:
|
# REPO_TOKEN:
|
||||||
from_secret: repo-token
|
# from_secret: repo-token
|
||||||
REPO_TOKEN_OSSRH:
|
# REPO_TOKEN_OSSRH:
|
||||||
from_secret: repo-token-ossrh
|
# from_secret: repo-token-ossrh
|
||||||
commands:
|
# commands:
|
||||||
- mvn -s maven-settings.xml deploy -DskipTests=true
|
# - mvn -s maven-settings.xml deploy -DskipTests=true
|
||||||
when:
|
# when:
|
||||||
branch:
|
# branch:
|
||||||
- master
|
# - main
|
||||||
event:
|
# event:
|
||||||
exclude:
|
# exclude:
|
||||||
- pull_request
|
# - pull_request
|
||||||
|
|
|
||||||
4
pom.xml
4
pom.xml
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
<groupId>ch.fritteli.a-maze-r</groupId>
|
<groupId>ch.fritteli.a-maze-r</groupId>
|
||||||
<artifactId>maze-generator</artifactId>
|
<artifactId>maze-generator</artifactId>
|
||||||
<version>0.4.0</version>
|
<version>0.5.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>A-Maze-R Generator</name>
|
<name>A-Maze-R Generator</name>
|
||||||
<description>A-Maze-R, The Maze Generator. It is a library for generating mazes in various output formats.
|
<description>A-Maze-R, The Maze Generator. It is a library for generating mazes in various output formats.
|
||||||
|
|
@ -44,7 +44,7 @@
|
||||||
<connection>scm:git:https://gittr.ch/java/maze-generator.git</connection>
|
<connection>scm:git:https://gittr.ch/java/maze-generator.git</connection>
|
||||||
<developerConnection>scm:git:ssh://git@gittr.ch/java/maze-generator.git</developerConnection>
|
<developerConnection>scm:git:ssh://git@gittr.ch/java/maze-generator.git</developerConnection>
|
||||||
<url>https://gittr.ch/java/maze-generator</url>
|
<url>https://gittr.ch/java/maze-generator</url>
|
||||||
<tag>v0.4.0</tag>
|
<tag>HEAD</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<distributionManagement>
|
<distributionManagement>
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import ch.fritteli.maze.generator.model.Maze;
|
||||||
import ch.fritteli.maze.generator.model.Position;
|
import ch.fritteli.maze.generator.model.Position;
|
||||||
import ch.fritteli.maze.generator.model.Tile;
|
import ch.fritteli.maze.generator.model.Tile;
|
||||||
import io.vavr.control.Option;
|
import io.vavr.control.Option;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
|
|
@ -20,18 +19,31 @@ import java.awt.*;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
class Generator {
|
class Generator {
|
||||||
|
private static final PDRectangle REFERENCE_PAGE = PDRectangle.A4;
|
||||||
|
private static final int DPI = 72;
|
||||||
|
private static final double CM_PER_INCH = 2.54;
|
||||||
|
private static final double DOT_PER_CM = DPI / CM_PER_INCH;
|
||||||
|
// 1.5cm margin on each side of the page
|
||||||
|
private static final float MARGIN = (float) (1.5 * DOT_PER_CM);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Maze maze;
|
private final Maze maze;
|
||||||
|
private final float stepSize;
|
||||||
|
|
||||||
|
Generator(@NonNull final Maze maze) {
|
||||||
|
this.maze = maze;
|
||||||
|
|
||||||
|
final float usableWidth = REFERENCE_PAGE.getWidth() - 2 * MARGIN;
|
||||||
|
final float usableHeight = REFERENCE_PAGE.getHeight() - 2 * MARGIN;
|
||||||
|
final float stepWidth = usableWidth / maze.getWidth();
|
||||||
|
final float stepHeight = usableHeight / maze.getHeight();
|
||||||
|
this.stepSize = Math.min(stepWidth, stepHeight);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ByteArrayOutputStream generate() {
|
public ByteArrayOutputStream generate() {
|
||||||
final float pageWidth = this.maze.getWidth() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
|
|
||||||
final float pageHeight = this.maze.getHeight() * PDFRenderer.SCALE + 2 * PDFRenderer.MARGIN;
|
|
||||||
|
|
||||||
final PDDocument pdDocument = new PDDocument();
|
final PDDocument pdDocument = new PDDocument();
|
||||||
final PDDocumentInformation info = new PDDocumentInformation();
|
final PDDocumentInformation info = new PDDocumentInformation();
|
||||||
info.setTitle("Maze %sx%s, ID %s (%s)".formatted(
|
info.setTitle("Maze %sx%s, ID %s (%s)".formatted(
|
||||||
|
|
@ -41,8 +53,8 @@ class Generator {
|
||||||
this.maze.getAlgorithm()
|
this.maze.getAlgorithm()
|
||||||
));
|
));
|
||||||
pdDocument.setDocumentInformation(info);
|
pdDocument.setDocumentInformation(info);
|
||||||
final PDPage puzzlePage = new PDPage(new PDRectangle(pageWidth, pageHeight));
|
final PDPage puzzlePage = new PDPage(REFERENCE_PAGE);
|
||||||
final PDPage solutionPage = new PDPage(new PDRectangle(pageWidth, pageHeight));
|
final PDPage solutionPage = new PDPage(REFERENCE_PAGE);
|
||||||
pdDocument.addPage(puzzlePage);
|
pdDocument.addPage(puzzlePage);
|
||||||
pdDocument.addPage(solutionPage);
|
pdDocument.addPage(solutionPage);
|
||||||
try (final PDPageContentStream puzzlePageContentStream = new PDPageContentStream(pdDocument, puzzlePage);
|
try (final PDPageContentStream puzzlePageContentStream = new PDPageContentStream(pdDocument, puzzlePage);
|
||||||
|
|
@ -75,7 +87,7 @@ class Generator {
|
||||||
|
|
||||||
private void drawHorizontalLines(@NonNull final PDPageContentStream... contentStreams) throws IOException {
|
private void drawHorizontalLines(@NonNull final PDPageContentStream... contentStreams) throws IOException {
|
||||||
// PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required.
|
// PDF has the origin in the lower left corner. We want it in the upper left corner, hence some magic is required.
|
||||||
Coordinate coordinate = new Coordinate(0f, 0f);
|
Coordinate coordinate = new Coordinate(0, 0);
|
||||||
// Draw the TOP borders of all tiles.
|
// Draw the TOP borders of all tiles.
|
||||||
for (int y = 0; y < this.maze.getHeight(); y++) {
|
for (int y = 0; y < this.maze.getHeight(); y++) {
|
||||||
boolean isPainting = false;
|
boolean isPainting = false;
|
||||||
|
|
@ -248,11 +260,15 @@ class Generator {
|
||||||
|
|
||||||
@Value
|
@Value
|
||||||
private class Coordinate {
|
private class Coordinate {
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
|
|
||||||
public Coordinate(final float x, final float y) {
|
public Coordinate(final int x, final int y) {
|
||||||
|
this.x = this.calcX(x);
|
||||||
|
this.y = this.calcY(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Coordinate(final float x, final float y) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
}
|
}
|
||||||
|
|
@ -262,7 +278,7 @@ class Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calcX(final int x) {
|
private float calcX(final int x) {
|
||||||
return x * PDFRenderer.SCALE + PDFRenderer.MARGIN;
|
return x * Generator.this.stepSize + Generator.MARGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinate withY(final int y) {
|
public Coordinate withY(final int y) {
|
||||||
|
|
@ -270,7 +286,7 @@ class Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calcY(final int y) {
|
private float calcY(final int y) {
|
||||||
return (Generator.this.maze.getHeight() - y) * PDFRenderer.SCALE + PDFRenderer.MARGIN;
|
return (Generator.this.maze.getHeight() - y) * Generator.this.stepSize + Generator.MARGIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -286,11 +302,11 @@ class Generator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calcX(final int x) {
|
private float calcX(final int x) {
|
||||||
return x * PDFRenderer.SCALE + PDFRenderer.SCALE / 2 + PDFRenderer.MARGIN;
|
return x * Generator.this.stepSize + Generator.this.stepSize / 2 + Generator.MARGIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float calcY(final int y) {
|
private float calcY(final int y) {
|
||||||
return (Generator.this.maze.getHeight() - y) * PDFRenderer.SCALE - PDFRenderer.SCALE / 2 + PDFRenderer.MARGIN;
|
return (Generator.this.maze.getHeight() - y) * Generator.this.stepSize - Generator.this.stepSize / 2 + Generator.MARGIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue