Skip to content

Commit 513f069

Browse files
committed
[RELEASE] PIE Core - 1.0
2 parents 67f06eb + c42ee9e commit 513f069

File tree

94 files changed

+429208
-1821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+429208
-1821
lines changed

.gitignore

Lines changed: 6 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,17 @@
1-
2-
# Created by https://www.gitignore.io/api/java,windows,intellij
3-
# Edit at https://www.gitignore.io/?templates=java,windows,intellij
4-
5-
### Intellij ###
6-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
7-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8-
9-
# User-specific stuff
10-
.idea/**/workspace.xml
11-
.idea/**/tasks.xml
12-
.idea/**/usage.statistics.xml
13-
.idea/**/dictionaries
14-
.idea/**/shelf
15-
16-
# Generated files
17-
.idea/**/contentModel.xml
18-
19-
# Sensitive or high-churn files
20-
.idea/**/dataSources/
21-
.idea/**/dataSources.ids
22-
.idea/**/dataSources.local.xml
23-
.idea/**/sqlDataSources.xml
24-
.idea/**/dynamic.xml
25-
.idea/**/uiDesigner.xml
26-
.idea/**/dbnavigator.xml
27-
28-
# Gradle
29-
.idea/**/gradle.xml
30-
.idea/**/libraries
31-
32-
# Gradle and Maven with auto-import
33-
# When using Gradle or Maven with auto-import, you should exclude module files,
34-
# since they will be recreated, and may cause churn. Uncomment if using
35-
# auto-import.
36-
.idea/modules.xml
37-
.idea/*.iml
38-
.idea/modules
39-
*.iml
40-
*.ipr
41-
42-
# CMake
43-
cmake-build-*/
44-
45-
# Mongo Explorer plugin
46-
.idea/**/mongoSettings.xml
47-
48-
# File-based project format
49-
*.iws
50-
511
# IntelliJ
52-
out/
53-
54-
# mpeltonen/sbt-idea plugin
55-
.idea_modules/
56-
57-
# JIRA plugin
58-
atlassian-ide-plugin.xml
59-
60-
# Cursive Clojure plugin
61-
.idea/replstate.xml
62-
63-
# Crashlytics plugin (for Android Studio and IntelliJ)
64-
com_crashlytics_export_strings.xml
65-
crashlytics.properties
66-
crashlytics-build.properties
67-
fabric.properties
68-
69-
# Editor-based Rest Client
70-
.idea/httpRequests
71-
72-
# Android studio 3.1+ serialized cache file
73-
.idea/caches/build_file_checksums.ser
74-
75-
### Intellij Patch ###
76-
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
77-
2+
**/out/
3+
**/.idea/
4+
**/target/
785
*.iml
79-
modules.xml
80-
.idea/misc.xml
81-
*.ipr
826

83-
# Sonarlint plugin
84-
.idea/**/sonarlint/
85-
86-
# SonarQube Plugin
87-
.idea/**/sonarIssues.xml
88-
89-
# Markdown Navigator plugin
90-
.idea/**/markdown-navigator.xml
91-
.idea/**/markdown-navigator/
92-
93-
### Java ###
947
# Compiled class file
958
*.class
969

9710
# Log file
9811
*.log
9912

100-
# BlueJ files
101-
*.ctxt
102-
103-
# Mobile Tools for Java (J2ME)
104-
.mtj.tmp/
105-
106-
# Package Files #
13+
#Package Files #
10714
*.jar
108-
*.war
109-
*.nar
110-
*.ear
111-
*.zip
112-
*.tar.gz
113-
*.rar
114-
115-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
116-
hs_err_pid*
117-
118-
### Windows ###
119-
# Windows thumbnail cache files
120-
Thumbs.db
121-
Thumbs.db:encryptable
122-
ehthumbs.db
123-
ehthumbs_vista.db
124-
125-
# Dump file
126-
*.stackdump
127-
128-
# Folder config file
129-
[Dd]esktop.ini
130-
131-
# Recycle Bin used on file shares
132-
$RECYCLE.BIN/
133-
134-
# Windows Installer files
135-
*.cab
136-
*.msi
137-
*.msix
138-
*.msm
139-
*.msp
140-
141-
# Windows shortcuts
142-
*.lnk
14315

144-
# End of https://www.gitignore.io/api/java,windows,intellij
16+
#Util classes for creating .PIE files
17+
/Benchmark/src/main/java/com/github/introfog/pie/benchmark/

Benchmark/pom.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.github.introfog.pie</groupId>
9+
<artifactId>root</artifactId>
10+
<version>1.0</version>
11+
</parent>
12+
13+
<artifactId>benchmark</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<properties>
17+
<junit.version>4.13</junit.version>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>com.github.introfog.pie</groupId>
23+
<artifactId>core</artifactId>
24+
<version>1.0</version>
25+
<scope>compile</scope>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.github.introfog.pie</groupId>
29+
<artifactId>test</artifactId>
30+
<version>1.0</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>junit</groupId>
35+
<artifactId>junit</artifactId>
36+
<version>${junit.version}</version>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
41+
</project>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
/*
2+
Copyright 2020 Dmitry Chubrick
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.github.introfog.pie.benchmark.collisions.broadphase;
17+
18+
import com.github.introfog.pie.core.collisions.broadphase.AbstractBroadPhase;
19+
import com.github.introfog.pie.core.collisions.broadphase.BruteForceMethod;
20+
import com.github.introfog.pie.core.collisions.broadphase.SpatialHashingMethod;
21+
import com.github.introfog.pie.core.collisions.broadphase.SweepAndPruneMethod;
22+
import com.github.introfog.pie.core.collisions.broadphase.SweepAndPruneMyMethod;
23+
import com.github.introfog.pie.core.shape.IShape;
24+
import com.github.introfog.pie.core.util.ShapeIOUtil;
25+
import com.github.introfog.pie.test.PIETest;
26+
27+
import java.io.IOException;
28+
29+
import java.text.NumberFormat;
30+
31+
import java.util.ArrayList;
32+
import java.util.Arrays;
33+
import java.util.Collections;
34+
import java.util.LinkedHashMap;
35+
import java.util.List;
36+
import java.util.Locale;
37+
import java.util.Map;
38+
import java.util.concurrent.TimeUnit;
39+
40+
import org.junit.Assert;
41+
42+
public abstract class AbstractBroadPhaseBenchmarkTest extends PIETest {
43+
private final static int DEFAULT_WARM_VALUE = 5;
44+
private final static int DEFAULT_MEASURE_VALUE = 10;
45+
private final static TimeUnit DEFAULT_TIME_UNIT = TimeUnit.MICROSECONDS;
46+
47+
private List<AbstractBroadPhase> broadPhaseMethods;
48+
private String fileName;
49+
private String sourceFolder;
50+
private TimeUnit timeUnit;
51+
private int warm;
52+
private int measure;
53+
54+
public void runBenchmarkTest(String fileName, String sourceFolder) throws IOException {
55+
runBenchmarkTest(fileName, sourceFolder, DEFAULT_TIME_UNIT);
56+
}
57+
58+
public void runBenchmarkTest(String fileName, String sourceFolder, TimeUnit timeUnit) throws IOException {
59+
runBenchmarkTest(fileName, sourceFolder, timeUnit, DEFAULT_WARM_VALUE, DEFAULT_MEASURE_VALUE);
60+
}
61+
62+
public void runBenchmarkTest(String fileName, String sourceFolder, int warm, int measure) throws IOException {
63+
runBenchmarkTest(fileName, sourceFolder, DEFAULT_TIME_UNIT, warm, measure);
64+
}
65+
66+
public void runBenchmarkTest(String fileName, String sourceFolder, TimeUnit timeUnit, int warm, int measure) throws IOException {
67+
this.fileName = fileName;
68+
this.sourceFolder = sourceFolder;
69+
this.timeUnit = timeUnit;
70+
this.warm = warm;
71+
this.measure = measure;
72+
73+
initializeTestMethods();
74+
75+
outputConfig();
76+
77+
Map<String, Double> results = new LinkedHashMap<>(broadPhaseMethods.size());
78+
broadPhaseMethods.forEach(method -> results.put(method.getClass().getSimpleName(), runBroadPhaseMethod(method)));
79+
80+
outputResults(results);
81+
}
82+
83+
private void initializeTestMethods() throws IOException {
84+
Assert.assertTrue("Use .json file", fileName.matches(".*\\.pie"));
85+
List<IShape> shapes = ShapeIOUtil.readShapesFromFile(sourceFolder + fileName);
86+
87+
broadPhaseMethods = new ArrayList<>();
88+
broadPhaseMethods.add(new BruteForceMethod());
89+
broadPhaseMethods.add(new SpatialHashingMethod());
90+
broadPhaseMethods.add(new SweepAndPruneMethod());
91+
broadPhaseMethods.add(new SweepAndPruneMyMethod());
92+
93+
broadPhaseMethods.forEach(method -> method.setShapes(shapes));
94+
}
95+
96+
// TODO Make the method universal using reflection
97+
private double runBroadPhaseMethod(AbstractBroadPhase method) {
98+
for (int i = 0; i < warm; i++) {
99+
method.calculateAabbCollision();
100+
}
101+
long averageNanoTime = 0;
102+
for (int i = 0; i < measure; i++) {
103+
long previously = System.nanoTime();
104+
method.calculateAabbCollision();
105+
averageNanoTime += System.nanoTime() - previously;
106+
}
107+
108+
return (double) timeUnit.convert(averageNanoTime, TimeUnit.NANOSECONDS) / measure;
109+
}
110+
111+
private void outputResults(Map<String, Double> results) {
112+
System.out.println("\nRESULTS");
113+
System.out.format("+---------------------------+----------------+\n");
114+
System.out.format("| Method name | Time |\n");
115+
System.out.format("+---------------------------+----------------+\n");
116+
NumberFormat numberFormat = NumberFormat.getInstance(Locale.CANADA_FRENCH);
117+
numberFormat.setMaximumFractionDigits(3);
118+
results.forEach((method, time) -> System.out.format("| %-25s | %-14s |\n", method, numberFormat.format(time)));
119+
System.out.format("+---------------------------+----------------+\n");
120+
}
121+
122+
private void outputConfig() {
123+
System.out.println("PIE BENCHMARK TEST\n");
124+
int cellWidth = Collections.max(Arrays.asList(8, timeUnit.toString().length(), fileName.length(), sourceFolder.length()));
125+
126+
System.out.println("CONFIG");
127+
System.out.format("+--------------+");
128+
for (int i = 0; i < cellWidth + 2; i++) {
129+
System.out.print("-");
130+
}
131+
System.out.print("+\n");
132+
String format = "| %-12s | %-" + cellWidth + "s |\n";
133+
System.out.format(format, "File", fileName);
134+
System.out.format(format, "Folder", sourceFolder);
135+
System.out.format(format, "Time unit", timeUnit);
136+
System.out.format(format, "Warming up", warm);
137+
System.out.format(format, "Measure", measure);
138+
System.out.format("+--------------+");
139+
for (int i = 0; i < cellWidth + 2; i++) {
140+
System.out.print("-");
141+
}
142+
System.out.print("+\n");
143+
}
144+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Copyright 2020 Dmitry Chubrick
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package com.github.introfog.pie.benchmark.collisions.broadphase;
17+
18+
import com.github.introfog.pie.test.annotations.BenchmarkTest;
19+
20+
import java.io.IOException;
21+
22+
import org.junit.Test;
23+
import org.junit.experimental.categories.Category;
24+
25+
@Category(BenchmarkTest.class)
26+
public class LineShapesBenchmarkTest extends AbstractBroadPhaseBenchmarkTest {
27+
private final static String PATH_TO_SOURCE_FOLDER = "./src/test/resources/com/github/introfog/pie/benchmark/collisions/broadphase/Line/";
28+
29+
@Test
30+
public void simpleColumns() throws IOException {
31+
super.runBenchmarkTest("5x500line_8487collision.pie", PATH_TO_SOURCE_FOLDER);
32+
}
33+
34+
@Test
35+
public void mediumColumns() throws IOException {
36+
super.runBenchmarkTest("5x500line_22443collision.pie", PATH_TO_SOURCE_FOLDER);
37+
}
38+
39+
@Test
40+
public void simpleRows() throws IOException {
41+
super.runBenchmarkTest("500x5line_8487collision.pie", PATH_TO_SOURCE_FOLDER);
42+
}
43+
44+
@Test
45+
public void mediumRows() throws IOException {
46+
super.runBenchmarkTest("500x5line_22443collision.pie", PATH_TO_SOURCE_FOLDER);
47+
}
48+
49+
@Test
50+
public void hardRows() throws IOException {
51+
super.runBenchmarkTest("3000x2line+diffSize_20491collision.pie", PATH_TO_SOURCE_FOLDER);
52+
}
53+
}

0 commit comments

Comments
 (0)