Skip to content

Commit

Permalink
Added Google Code Style.
Browse files Browse the repository at this point in the history
  • Loading branch information
romankh3 committed Apr 6, 2019
1 parent d4bfc36 commit 4cc7a8b
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ script: ./gradlew clean build jacocoTestReport
jdk: oraclejdk8

after_success:
- ./gradlew jacocoTestReport coveralls
- ./gradlew jacocoTestReport coveralls
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ defaultTasks << 'build'

/* Publishing config */

task javadocJar( type: Jar ) {
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar( type: Jar ) {
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
Expand All @@ -58,7 +58,7 @@ artifacts {
}

// add all the info required by Maven Central to the pom
configure( install.repositories.mavenInstaller ) {
configure(install.repositories.mavenInstaller) {
pom.project {
inceptionYear '2019'
name project.name
Expand Down Expand Up @@ -91,19 +91,19 @@ configure( install.repositories.mavenInstaller ) {
}

def getProjectProperty = { String propertyName ->
project.properties[ propertyName ]
project.properties[propertyName]
}

bintray {
user = getProjectProperty "bintrayUserName"
key = getProjectProperty "bintrayApiKey"
configurations = [ 'archives' ]
configurations = ['archives']
publish = true
pkg {
repo = 'maven'
name = 'image-comparison'
licenses = [ 'unlicense' ]
labels = [ 'java', 'image', 'image-comparison' ]
licenses = ['unlicense']
labels = ['java', 'image', 'image-comparison']
publicDownloadNumbers = true

//noinspection GroovyAssignabilityCheck
Expand Down
49 changes: 20 additions & 29 deletions src/main/java/ua/comparison/image/ImageComparison.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,18 @@
public class ImageComparison {

/**
* The threshold which means the max distance between non-equal pixels.
* Could be changed according size and requirements to the image.
* Prefix of the name of the result image.
*/
public static int threshold = 3;

private static final String NAME_PREFIX = "image-comparison";
/**
* The number which marks how many rectangles. Beginning from 2.
* Suffix of the name of of the result image.
*/
private int counter = 2;

private static final String NAME_SUFFIX = ".png";
/**
* The number of the marking specific rectangle.
* The threshold which means the max distance between non-equal pixels.
* Could be changed according size and requirements to the image.
*/
private int regionCount = counter;

public static int threshold = 5;
/**
* First image for comparing
*/
Expand All @@ -51,18 +48,15 @@ public class ImageComparison {
private final BufferedImage image2;

private final /* @Nullable */ File destination;

private int[][] matrix;

/**
* Prefix of the name of the result image.
* The number which marks how many rectangles. Beginning from 2.
*/
private static final String NAME_PREFIX = "image-comparison";

private int counter = 2;
/**
* Suffix of the name of of the result image.
* The number of the marking specific rectangle.
*/
private static final String NAME_SUFFIX = ".png";
private int regionCount = counter;
private int[][] matrix;

ImageComparison(String image1, String image2) throws IOException, URISyntaxException {
this(readImageFromResources(image1), readImageFromResources(image2), null);
Expand Down Expand Up @@ -141,7 +135,7 @@ private void groupRegions() {
for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {
if (matrix[row][col] == 1) {
joinToRegion(row, col, threshold);
joinToRegion(row, col);
regionCount++;
}
}
Expand All @@ -156,23 +150,20 @@ private void groupRegions() {
* @param row the value of the row.
* @param col the value of the column.
*/
private void joinToRegion(int row, int col, int localThreshold) {
private void joinToRegion(int row, int col) {
if (row < 0 || row >= matrix.length || col < 0 || col >= matrix[row].length || matrix[row][col] != 1) {
return;
}

matrix[row][col] = regionCount;

for (int i = 0; i < localThreshold; i++) {
// joinToRegion(row - 1 - i, col, 1);
joinToRegion(row + 1 + i, col, threshold);
// joinToRegion(row, col - 1 - i, 1);
joinToRegion(row, col + 1 + i, threshold);
for (int i = 0; i < threshold; i++) {
joinToRegion(row + 1 + i, col);
joinToRegion(row, col + 1 + i);

// joinToRegion(row - 1 - i, col - 1 - i, 1);
joinToRegion(row + 1 + i, col - 1 - i, threshold);
joinToRegion(row - 1 - i, col + 1 + i, threshold);
joinToRegion(row + 1 + i, col + 1 + i, threshold);
joinToRegion(row + 1 + i, col - 1 - i);
joinToRegion(row - 1 - i, col + 1 + i);
joinToRegion(row + 1 + i, col + 1 + i);
}
}

Expand Down
29 changes: 17 additions & 12 deletions src/main/java/ua/comparison/image/model/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public static Rectangle createDefault() {
}

public void merge(Rectangle that) {
if(this.minX <= that.minX && this.minY <= that.minY && this.maxY >= that.maxY && this.maxX >= that.maxX) {
if (this.minX <= that.minX && this.minY <= that.minY && this.maxY >= that.maxY && this.maxX >= that.maxX) {
that.setDefaultValues();
}
if(that.minX <= this.minX && that.minY <= this.minY && that.maxY >= this.maxY && that.maxX >= this.maxX) {
if (that.minX <= this.minX && that.minY <= this.minY && that.maxY >= this.maxY && that.maxX >= this.maxX) {
this.setDefaultValues();
}
}
Expand All @@ -55,33 +55,38 @@ public void setDefaultValues() {
this.minX = Integer.MAX_VALUE;
}

public int getMinX() {
return minX;
}

public void setMinX(int minX) {
this.minX = minX;
}

public int getMinY() {
return minY;
}

public void setMinY(int minY) {
this.minY = minY;
}

public int getMaxX() {
return maxX;
}

public void setMaxX(int maxX) {
this.maxX = maxX;
}

public void setMaxY(int maxY) {
this.maxY = maxY;
public int getMaxY() {
return maxY;
}

public int getMinX() {
return minX;
public void setMaxY(int maxY) {
this.maxY = maxY;
}

public int getMinY() { return minY; }

public int getMaxX() { return maxX; }

public int getMaxY() { return maxY; }

public int getWidth() {
return maxY - minY;
}
Expand Down
35 changes: 17 additions & 18 deletions src/test/java/ua/comparison/image/ImageComparisonUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Ignore;
import org.junit.Test;


Expand All @@ -22,6 +21,23 @@
*/
public class ImageComparisonUnitTest {

private static void assertImagesEqual(BufferedImage imgA, BufferedImage imgB) {
if (imgA.getWidth() != imgB.getWidth() || imgA.getHeight() != imgB.getHeight()) {
fail("Images have different dimensions");
}

int width = imgA.getWidth();
int height = imgA.getHeight();

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (imgA.getRGB(x, y) != imgB.getRGB(x, y)) {
fail("Images are different, found different pixel at: x = " + x + ", y = " + y);
}
}
}
}

/**
* The most important test. Shown, that the changes in algorithm,
* don't break the main behaviour and result as expected.
Expand Down Expand Up @@ -136,21 +152,4 @@ public void resultIsHandledCorrectlyWhenItShouldSaveToFile() throws IOException,
assertFalse(showUI.get());
}

private static void assertImagesEqual(BufferedImage imgA, BufferedImage imgB) {
if (imgA.getWidth() != imgB.getWidth() || imgA.getHeight() != imgB.getHeight()) {
fail("Images have different dimensions");
}

int width = imgA.getWidth();
int height = imgA.getHeight();

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
if (imgA.getRGB(x, y) != imgB.getRGB(x, y)) {
fail("Images are different, found different pixel at: x = " + x + ", y = " + y);
}
}
}
}

}
24 changes: 12 additions & 12 deletions src/test/java/ua/comparison/image/model/RectangleUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ public class RectangleUnitTest {
public void testDefaultRectangle() {
Rectangle rectangle = Rectangle.createDefault();

assertEquals( rectangle.getMinX(), Integer.MAX_VALUE );
assertEquals( rectangle.getMinY(), Integer.MAX_VALUE );
assertEquals( rectangle.getMaxX(), Integer.MIN_VALUE );
assertEquals( rectangle.getMaxY(), Integer.MIN_VALUE );
assertEquals(rectangle.getMinX(), Integer.MAX_VALUE);
assertEquals(rectangle.getMinY(), Integer.MAX_VALUE);
assertEquals(rectangle.getMaxX(), Integer.MIN_VALUE);
assertEquals(rectangle.getMaxY(), Integer.MIN_VALUE);
}

@Test
public void testGetterSetter() {
Rectangle rectangle = Rectangle.createDefault();

rectangle.setMinX( 10 );
rectangle.setMinY( 20 );
rectangle.setMaxX( 30 );
rectangle.setMaxY( 40 );
rectangle.setMinX(10);
rectangle.setMinY(20);
rectangle.setMaxX(30);
rectangle.setMaxY(40);

assertEquals( rectangle.getMinX(), 10 );
assertEquals( rectangle.getMinY(), 20 );
assertEquals( rectangle.getMaxX(), 30 );
assertEquals( rectangle.getMaxY(), 40 );
assertEquals(rectangle.getMinX(), 10);
assertEquals(rectangle.getMinY(), 20);
assertEquals(rectangle.getMaxX(), 30);
assertEquals(rectangle.getMaxY(), 40);
}
}

0 comments on commit 4cc7a8b

Please sign in to comment.