[DEV] add uri more elements and P2

This commit is contained in:
Edouard DUPIN 2021-04-13 01:37:07 +02:00
parent bd9c867207
commit d2c142485a
5 changed files with 215 additions and 28 deletions

105
build.gradle Normal file
View File

@ -0,0 +1,105 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java library project to get you started.
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.8.3/userguide/building_java_projects.html
*/
import com.github.jk1.license.render.*
plugins {
id 'java-library'
id 'com.adarshr.test-logger' version '3.0.0'
id "com.github.spotbugs" version "4.7.0"
}
sourceCompatibility = 15
tasks.withType(JavaCompile) {
options.compilerArgs += '--enable-preview'
}
tasks.withType(Test) {
jvmArgs += "--enable-preview"
}
sourceSets {
main {
buildDir 'out/gradle'
java {
srcDir 'src'
}
resources {
srcDir 'resources'
}
version = rootProject.file('etk/version.txt').text.trim()
}
test {
java {
srcDir 'test/src'
}
resources {
srcDir 'test/resources'
}
}
}
repositories {
// Use JCenter for resolving dependencies.
jcenter()
google()
}
dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1'
compile project(':scenarium-logger')
}
tasks.named('test') {
// Use junit platform for unit tests.
useJUnitPlatform()
}
tasks.named('jar') {
manifest {
attributes('Implementation-Title': project.name,
'Implementation-Version': project.version)
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
testlogger {
showFullStackTraces true
showSimpleNames true
// pick a theme - mocha, standard, plain, mocha-parallel, standard-parallel or plain-parallel
theme 'mocha'
}
artifacts {
archives sourcesJar
archives javadocJar
}
jar {
manifest {
attributes 'Implementation-Title': 'Ewol tool Kit (ETK)', 'Implementation-Version': version
}
}

2
settings.gradle Normal file
View File

@ -0,0 +1,2 @@
rootProject.name = 'etk'

View File

@ -25,6 +25,7 @@ public class Uri {
static {
genericMap.put("DATA", "data/");
genericMap.put("THEME", "theme/");
genericMap.put("FONTS", "fonts/");
genericMap.put("TRANSLATE", "translate/");
}
@ -101,11 +102,11 @@ public class Uri {
}
if (out == null) {
// search in the libraries ...
if (uri.lib == null) {
if (uri.properties.get("lib") == null) {
Log.warning(" !! No library specified");
return null;
} else {
LibraryElement libraryElement = libraries.get(uri.lib);
LibraryElement libraryElement = libraries.get(uri.properties.get("lib"));
if (libraryElement == null) {
Log.warning(" Can not get element in library");
return null;
@ -133,6 +134,7 @@ public class Uri {
public static List<Uri> listRecursive(final Uri uri) {
final List<Uri> out = new ArrayList<>();
Log.todo("not implemented function ...");
return out;
}
@ -231,28 +233,56 @@ public class Uri {
private final String path;
private final String lib;
private final Map<String, String> properties;
public Uri(final String path) {
this(null, path, null);
this(null, path);
}
public Uri(final String group, final String path) {
this(group, path, null);
}
public Uri(final String group, final String path, final String lib) {
if (group == null) {
this.group = null;
} else {
this.group = group.toUpperCase();
}
this.path = path;
if (lib == null) {
this.lib = null;
} else {
this.lib = lib.toLowerCase();
this.properties = new HashMap<>();
}
public Uri(final String group, final String path, final Map<String, String> properties) {
if (group == null) {
this.group = null;
} else {
this.group = group.toUpperCase();
}
this.path = path;
this.properties = new HashMap<>(properties);
}
public Uri(final String group, final String path, final String lib) {
this(group, path);
if (lib != null) {
this.properties.put("lib", lib.toLowerCase());
}
}
@Override
public Uri clone() {
return new Uri(this.group, this.path, new HashMap<>(this.properties));
}
public boolean exist() {
InputStream stream = getStream(this);
if (stream == null) {
return false;
}
try {
stream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
public String get() {
@ -264,10 +294,22 @@ public class Uri {
return ret[ret.length - 1];
}
public String getGroup() {
return this.group;
}
public String getPath() {
return this.path;
}
public Map<String, String> getproperties() {
return this.properties;
}
public String getproperty(final String key) {
return this.properties.get(key);
}
public String getValue() {
return toString();
}
@ -276,29 +318,47 @@ public class Uri {
return this.path == null || this.path.isEmpty();
}
public void setproperty(final String key, final String value) {
this.properties.put(key, value);
}
@Override
public String toString() {
String out = "";
StringBuilder out = new StringBuilder();
if (this.group != null) {
out += this.group + ":";
out.append(this.group);
out.append(":");
}
out += this.path;
if (this.lib != null) {
out += "?lib=" + this.lib;
out.append(this.path);
boolean first = true;
for (Map.Entry<String, String> entry : this.properties.entrySet()) {
if (first) {
out.append("?");
} else {
out.append("&");
}
return out;
out.append(entry.getKey());
String value = entry.getValue();
if (value != null) {
out.append("=");
out.append(value);
}
}
return out.toString();
}
// Format : DATA:jlfqkjsdflkjqs/sqldkhjflqksdjf/lll.png?lib=ewol
public Uri withGroup(final String group) {
return new Uri(group, this.path, this.lib);
return new Uri(group, this.path, new HashMap<>(this.properties));
}
public Uri withLib(final String lib) {
return new Uri(this.group, this.path, lib);
Map<String, String> tmp = new HashMap<>(this.properties);
tmp.put("lib", lib);
return new Uri(this.group, this.path, tmp);
}
public Uri withPath(final String path) {
return new Uri(this.group, path, this.lib);
return new Uri(this.group, path, new HashMap<>(this.properties));
}
}

View File

@ -2,6 +2,8 @@ package org.atriasoft.etk.math;
import java.text.DecimalFormat;
import org.atriasoft.etk.internal.Log;
public class FMath {
public static final float PI = (float) Math.PI;
@ -187,6 +189,23 @@ public class FMath {
return value % modulo;
}
/**
* get the next power 2 if the input
* @param value Value that we want the next power of 2
* @return result value
*/
public static int nextP2(final int value) {
int val = 1;
for (int iii = 1; iii < 31; iii++) {
if (value <= val) {
return val;
}
val *= 2;
}
Log.critical("impossible CASE....");
return val;
}
public static float pow(final float value, final float exponent) {
// TODO Auto-generated method stub
return (float) Math.pow(value, exponent);

View File

@ -98,24 +98,25 @@ public record Matrix4f(
* @return New matrix of the transformation requested
*/
public static Matrix4f createMatrixOrtho(final float left, final float right, final float bottom, final float top, final float nearVal, final float farVal) {
float a1 = 2.0f / (right - left);
float b1 = 0;
float c1 = 0;
float d1 = -1.0f * (right + left) / (right - left);
float a2 = 0;
float b2 = 2.0f / (top - bottom);
float c2 = 0;
float d2 = -1.0f * (top + bottom) / (top - bottom);
float a3 = 0;
float b3 = 0;
float c3 = -2.0f / (farVal - nearVal);
float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
float a4 = 0;
float b4 = 0;
float c4 = 0;
float a1 = 2.0f / (right - left);
float b2 = 2.0f / (top - bottom);
float c3 = -2.0f / (farVal - nearVal);
float d1 = -1.0f * (right + left) / (right - left);
float d2 = -1.0f * (top + bottom) / (top - bottom);
float d3 = -1.0f * (farVal + nearVal) / (farVal - nearVal);
float d4 = 1.0f;
//return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
return new Matrix4f(a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3, a4, b4, c4, d4);
//return new Matrix4f(a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4);
}