commit b384446fc6e529327b955ec6e9701434b701fdf6 Author: tabidachinokaze Date: Fri Jun 13 11:41:47 2025 +0800 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb5ffd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties +/.kotlin diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..f252f75 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,45 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.icegps.maps" + compileSdk = 35 + + defaultConfig { + applicationId = "com.icegps.maps" + minSdk = 24 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + implementation(project(":maps-view")) + + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/icegps/maps/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/icegps/maps/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..1a6fa3d --- /dev/null +++ b/app/src/androidTest/java/com/icegps/maps/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.icegps.maps + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.icegps.maps", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..d50ab0f --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..7bcb8e6 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..5ce71f4 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + maps + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..a6f9395 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/backup_rules.xml b/app/src/main/res/xml/backup_rules.xml new file mode 100644 index 0000000..4df9255 --- /dev/null +++ b/app/src/main/res/xml/backup_rules.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/data_extraction_rules.xml b/app/src/main/res/xml/data_extraction_rules.xml new file mode 100644 index 0000000..9ee9997 --- /dev/null +++ b/app/src/main/res/xml/data_extraction_rules.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/test/java/com/icegps/maps/ExampleUnitTest.kt b/app/src/test/java/com/icegps/maps/ExampleUnitTest.kt new file mode 100644 index 0000000..8ecd48b --- /dev/null +++ b/app/src/test/java/com/icegps/maps/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.icegps.maps + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..fc94b22 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,7 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.kotlin.android) apply false + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.android.library) apply false +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..20e2a01 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,23 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..958a7c4 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,24 @@ +[versions] +agp = "8.10.1" +kotlin = "2.1.21" +coreKtx = "1.16.0" +junit = "4.13.2" +junitVersion = "1.2.1" +espressoCore = "3.6.1" +appcompat = "1.7.1" +material = "1.12.0" +jetbrainsKotlinJvm = "2.0.21" + +[libraries] +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +junit = { group = "junit", name = "junit", version.ref = "junit" } +androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +material = { group = "com.google.android.material", name = "material", version.ref = "material" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "agp" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..336aa4d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Jun 13 11:06:47 CST 2025 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/maps-view/.gitignore b/maps-view/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/maps-view/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/maps-view/build.gradle.kts b/maps-view/build.gradle.kts new file mode 100644 index 0000000..812994e --- /dev/null +++ b/maps-view/build.gradle.kts @@ -0,0 +1,40 @@ +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.kotlin.android) +} + +android { + namespace = "com.icegps.maps" + compileSdk = 35 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } +} + +dependencies { + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.appcompat) + implementation(libs.material) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) +} \ No newline at end of file diff --git a/maps-view/consumer-rules.pro b/maps-view/consumer-rules.pro new file mode 100644 index 0000000..e69de29 diff --git a/maps-view/proguard-rules.pro b/maps-view/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/maps-view/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/maps-view/src/androidTest/java/com/icegps/maps/ExampleInstrumentedTest.kt b/maps-view/src/androidTest/java/com/icegps/maps/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..ce4bc50 --- /dev/null +++ b/maps-view/src/androidTest/java/com/icegps/maps/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.icegps.maps + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.icegps.maps.test", appContext.packageName) + } +} \ No newline at end of file diff --git a/maps-view/src/main/AndroidManifest.xml b/maps-view/src/main/AndroidManifest.xml new file mode 100644 index 0000000..a5918e6 --- /dev/null +++ b/maps-view/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/maps-view/src/main/res/drawable/bucket_profile.xml b/maps-view/src/main/res/drawable/bucket_profile.xml new file mode 100644 index 0000000..16c992c --- /dev/null +++ b/maps-view/src/main/res/drawable/bucket_profile.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + diff --git a/maps-view/src/main/res/drawable/bucket_top.xml b/maps-view/src/main/res/drawable/bucket_top.xml new file mode 100644 index 0000000..3250217 --- /dev/null +++ b/maps-view/src/main/res/drawable/bucket_top.xml @@ -0,0 +1,145 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/maps-view/src/test/java/com/icegps/maps/ExampleUnitTest.kt b/maps-view/src/test/java/com/icegps/maps/ExampleUnitTest.kt new file mode 100644 index 0000000..8ecd48b --- /dev/null +++ b/maps-view/src/test/java/com/icegps/maps/ExampleUnitTest.kt @@ -0,0 +1,17 @@ +package com.icegps.maps + +import org.junit.Test + +import org.junit.Assert.* + +/** + * Example local unit test, which will execute on the development machine (host). + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +class ExampleUnitTest { + @Test + fun addition_isCorrect() { + assertEquals(4, 2 + 2) + } +} \ No newline at end of file diff --git a/math/.gitignore b/math/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/math/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/math/build.gradle.kts b/math/build.gradle.kts new file mode 100644 index 0000000..7870696 --- /dev/null +++ b/math/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + alias(libs.plugins.kotlin.jvm) +} +java { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 +} +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 + } +} diff --git a/math/src/main/java/com/icegps/math/IsAlmostEquals.kt b/math/src/main/java/com/icegps/math/IsAlmostEquals.kt new file mode 100644 index 0000000..f56b754 --- /dev/null +++ b/math/src/main/java/com/icegps/math/IsAlmostEquals.kt @@ -0,0 +1,14 @@ +package com.icegps.math + +import kotlin.math.absoluteValue + +interface IsAlmostEquals { + fun isAlmostEquals(other: T, epsilon: Double = 0.000001): Boolean +} + +interface IsAlmostEqualsF { + fun isAlmostEquals(other: T, epsilon: Float = 0.0001f): Boolean +} + +fun Float.isAlmostEquals(other: Float, epsilon: Float = 0.000001f): Boolean = (this - other).absoluteValue < epsilon +fun Double.isAlmostEquals(other: Double, epsilon: Double = 0.000001): Boolean = (this - other).absoluteValue < epsilon diff --git a/math/src/main/java/com/icegps/math/geometry/Line2F.kt b/math/src/main/java/com/icegps/math/geometry/Line2F.kt new file mode 100644 index 0000000..519d17b --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Line2F.kt @@ -0,0 +1,5 @@ +package com.icegps.math.geometry + +typealias Line = Line2F + +data class Line2F(val a: Vector2F, val b: Vector2F) diff --git a/math/src/main/java/com/icegps/math/geometry/Scale.kt b/math/src/main/java/com/icegps/math/geometry/Scale.kt new file mode 100644 index 0000000..d10ac14 --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Scale.kt @@ -0,0 +1,3 @@ +package com.icegps.math.geometry + +data class Scale(val scaleX: Float, val scaleY: Float) diff --git a/math/src/main/java/com/icegps/math/geometry/Size.kt b/math/src/main/java/com/icegps/math/geometry/Size.kt new file mode 100644 index 0000000..7fbfe45 --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Size.kt @@ -0,0 +1,32 @@ +package com.icegps.math.geometry + +data class Size2F(val width: Float, val height: Float) + +data class SizeInt(val width: Int, val height: Int) { + constructor() : this(0, 0) + + fun avgComponent(): Int = (width + height) / 2 + fun minComponent(): Int = kotlin.math.min(width, height) + fun maxComponent(): Int = kotlin.math.max(width, height) + + val area: Int get() = width * height + val perimeter: Int get() = width * 2 + height * 2 + + operator fun unaryMinus(): SizeInt = SizeInt(-width, -height) + operator fun unaryPlus(): SizeInt = this + + operator fun minus(other: SizeInt): SizeInt = SizeInt(width - other.width, height - other.height) + operator fun plus(other: SizeInt): SizeInt = SizeInt(width + other.width, height + other.height) + operator fun times(s: Float): SizeInt = SizeInt((width * s).toInt(), (height * s).toInt()) + operator fun times(s: Double): SizeInt = times(s.toFloat()) + operator fun times(s: Int): SizeInt = times(s.toFloat()) + operator fun times(scale: Vector2F): SizeInt = SizeInt((width * scale.x).toInt(), (height * scale.y).toInt()) + operator fun times(scale: Scale): SizeInt = SizeInt((width * scale.scaleX).toInt(), (height * scale.scaleY).toInt()) + + operator fun div(other: SizeInt): SizeInt = SizeInt(width / other.width, height / other.height) + operator fun div(s: Float): SizeInt = SizeInt((width / s).toInt(), (height / s).toInt()) + operator fun div(s: Double): SizeInt = div(s.toFloat()) + operator fun div(s: Int): SizeInt = div(s.toFloat()) + + override fun toString(): String = "${width}x${height}" +} \ No newline at end of file diff --git a/math/src/main/java/com/icegps/math/geometry/Vector2D.kt b/math/src/main/java/com/icegps/math/geometry/Vector2D.kt new file mode 100644 index 0000000..0f87665 --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Vector2D.kt @@ -0,0 +1,191 @@ +package com.icegps.math.geometry + +import com.icegps.math.IsAlmostEquals +import com.icegps.math.isAlmostEquals +import kotlin.math.abs +import kotlin.math.ceil +import kotlin.math.floor +import kotlin.math.hypot +import kotlin.math.max +import kotlin.math.min +import kotlin.math.round + +data class Vector2D(val x: Double, val y: Double) : IsAlmostEquals { + //constructor(x: Float, y: Float) : this(float2PackOf(x, y)) + constructor(x: Float, y: Float) : this(x.toDouble(), y.toDouble()) + constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble()) + + constructor(x: Double, y: Int) : this(x.toDouble(), y.toDouble()) + constructor(x: Int, y: Double) : this(x.toDouble(), y.toDouble()) + + constructor(x: Float, y: Int) : this(x.toDouble(), y.toDouble()) + constructor(x: Int, y: Float) : this(x.toDouble(), y.toDouble()) + + //constructor(p: Vector2) : this(p.raw) + constructor() : this(0.0, 0.0) + //constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble()) + //constructor(x: Float, y: Float) : this(x.toDouble(), y.toDouble()) + + fun copy(x: Float = this.x.toFloat(), y: Float = this.y.toFloat()): Vector2D = Vector2D(x, y) + + inline operator fun unaryMinus(): Vector2D = Vector2D(-x, -y) + inline operator fun unaryPlus(): Vector2D = this + + inline operator fun plus(that: Vector2D): Vector2D = Vector2D(x + that.x, y + that.y) + inline operator fun minus(that: Vector2D): Vector2D = Vector2D(x - that.x, y - that.y) + inline operator fun times(that: Vector2D): Vector2D = Vector2D(x * that.x, y * that.y) + inline operator fun div(that: Vector2D): Vector2D = Vector2D(x / that.x, y / that.y) + inline operator fun rem(that: Vector2D): Vector2D = Vector2D(x % that.x, y % that.y) + + inline operator fun times(scale: Double): Vector2D = Vector2D(x * scale, y * scale) + inline operator fun times(scale: Float): Vector2D = this * scale.toDouble() + inline operator fun times(scale: Int): Vector2D = this * scale.toDouble() + + inline operator fun div(scale: Double): Vector2D = Vector2D(x / scale, y / scale) + inline operator fun div(scale: Float): Vector2D = this / scale.toDouble() + inline operator fun div(scale: Int): Vector2D = this / scale.toDouble() + + inline operator fun rem(scale: Double): Vector2D = Vector2D(x % scale, y % scale) + inline operator fun rem(scale: Float): Vector2D = this % scale.toDouble() + inline operator fun rem(scale: Int): Vector2D = this % scale.toDouble() + + fun avgComponent(): Double = x * 0.5 + y * 0.5 + fun minComponent(): Double = min(x, y) + fun maxComponent(): Double = max(x, y) + + fun distanceTo(x: Double, y: Double): Double = hypot(x - this.x, y - this.y) + fun distanceTo(x: Float, y: Float): Double = distanceTo(x.toDouble(), y.toDouble()) + fun distanceTo(x: Int, y: Int): Double = this.distanceTo(x.toDouble(), y.toDouble()) + fun distanceTo(that: Vector2D): Double = distanceTo(that.x, that.y) + + infix fun cross(that: Vector2D): Double = crossProduct(this, that) + infix fun dot(that: Vector2D): Double = ((this.x * that.x) + (this.y * that.y)) + + operator fun get(component: Int): Double = when (component) { + 0 -> x; 1 -> y + else -> throw IndexOutOfBoundsException("Point doesn't have $component component") + } + + val length: Double get() = hypot(x, y) + val lengthSquared: Double + get() { + val x = x + val y = y + return x * x + y * y + } + val magnitude: Double get() = hypot(x, y) + val normalized: Vector2D get() = this * (1f / magnitude) + val unit: Vector2D get() = this / length + + /** Normal vector. Rotates the vector/point -90 degrees (not normalizing it) */ + fun toNormal(): Vector2D = Vector2D(-this.y, this.x) + + fun round(): Vector2D = Vector2D(round(x), round(y)) + fun ceil(): Vector2D = Vector2D(ceil(x), ceil(y)) + fun floor(): Vector2D = Vector2D(floor(x), floor(y)) + + //fun copy(x: Double = this.x, y: Double = this.y): Vector2 = Vector2D(x, y) + + override fun isAlmostEquals(other: Vector2D, epsilon: Double): Boolean = + this.x.isAlmostEquals(other.x, epsilon) && this.y.isAlmostEquals(other.y, epsilon) + + /** Vector2 with inverted (1f / v) components to this */ + fun inv(): Vector2D = Vector2D(1.0 / x, 1.0 / y) + + fun isNaN(): Boolean = this.x.isNaN() && this.y.isNaN() + + val absoluteValue: Vector2D get() = Vector2D(abs(x), abs(y)) + + companion object { + val ZERO = Vector2D(0.0, 0.0) + val NaN = Vector2D(Double.NaN, Double.NaN) + + /** Mathematically typical LEFT, matching screen coordinates (-1, 0) */ + val LEFT = Vector2D(-1.0, 0.0) + + /** Mathematically typical RIGHT, matching screen coordinates (+1, 0) */ + val RIGHT = Vector2D(+1.0, 0.0) + + /** Mathematically typical UP (0, +1) */ + val UP = Vector2D(0.0, +1.0) + + /** UP using screen coordinates as reference (0, -1) */ + val UP_SCREEN = Vector2D(0.0, -1.0) + + /** Mathematically typical DOWN (0, -1) */ + val DOWN = Vector2D(0.0, -1.0) + + /** DOWN using screen coordinates as reference (0, +1) */ + val DOWN_SCREEN = Vector2D(0.0, +1.0) + + + inline operator fun invoke(x: Number, y: Number): Vector2D = Vector2D(x.toDouble(), y.toDouble()) + //inline operator fun invoke(x: Float, y: Float): Vector2D = Vector2D(x.toDouble(), y.toDouble()) + + //fun fromRaw(raw: Float2Pack) = Vector2D(raw) + + inline fun middle(a: Vector2D, b: Vector2D): Vector2D = (a + b) * 0.5 + + fun distance(a: Double, b: Double): Double = abs(a - b) + fun distance(x1: Double, y1: Double, x2: Double, y2: Double): Double = hypot(x1 - x2, y1 - y2) + fun distance(x1: Float, y1: Float, x2: Float, y2: Float): Double = hypot(x1 - x2, y1 - y2).toDouble() + fun distance(x1: Int, y1: Int, x2: Int, y2: Int): Double = hypot(x1.toDouble() - x2.toDouble(), y1.toDouble() - y2.toDouble()) + fun distance(a: Vector2D, b: Vector2D): Double = distance(a.x, a.y, b.x, b.y) + + fun distanceSquared(a: Vector2D, b: Vector2D): Double = distanceSquared(a.x, a.y, b.x, b.y) + fun distanceSquared(x1: Double, y1: Double, x2: Double, y2: Double): Double = square(x1 - x2) + square(y1 - y2) + fun distanceSquared(x1: Float, y1: Float, x2: Float, y2: Float): Float = square(x1 - x2) + square(y1 - y2) + fun distanceSquared(x1: Int, y1: Int, x2: Int, y2: Int): Int = square(x1 - x2) + square(y1 - y2) + + @Deprecated("Likely searching for orientation") + inline fun direction(a: Vector2D, b: Vector2D): Vector2D = b - a + + fun compare(l: Vector2D, r: Vector2D): Int = compare(l.x, l.y, r.x, r.y) + fun compare(lx: Float, ly: Float, rx: Float, ry: Float): Int = ly.compareTo(ry).let { ret -> if (ret == 0) lx.compareTo(rx) else ret } + fun compare(lx: Double, ly: Double, rx: Double, ry: Double): Int = ly.compareTo(ry).let { ret -> if (ret == 0) lx.compareTo(rx) else ret } + + private fun square(x: Double): Double = x * x + private fun square(x: Float): Float = x * x + private fun square(x: Int): Int = x * x + + fun dot(aX: Double, aY: Double, bX: Double, bY: Double): Double = (aX * bX) + (aY * bY) + fun dot(aX: Float, aY: Float, bX: Float, bY: Float): Float = (aX * bX) + (aY * bY) + fun dot(a: Vector2D, b: Vector2D): Double = dot(a.x, a.y, b.x, b.y) + + fun crossProduct(ax: Float, ay: Float, bx: Float, by: Float): Float = (ax * by) - (bx * ay) + fun crossProduct(ax: Double, ay: Double, bx: Double, by: Double): Double = (ax * by) - (bx * ay) + fun crossProduct(p1: Vector2D, p2: Vector2D): Double = crossProduct(p1.x, p1.y, p2.x, p2.y) + + fun minComponents(p1: Vector2D, p2: Vector2D): Vector2D = Vector2D(min(p1.x, p2.x), min(p1.y, p2.y)) + fun minComponents(p1: Vector2D, p2: Vector2D, p3: Vector2D): Vector2D = Vector2D( + minOf(p1.x, p2.x, p3.x), + minOf(p1.y, p2.y, p3.y) + ) + + fun minComponents(p1: Vector2D, p2: Vector2D, p3: Vector2D, p4: Vector2D): Vector2D = Vector2D( + minOf( + p1.x, + p2.x, + p3.x, + p4.x + ), minOf(p1.y, p2.y, p3.y, p4.y) + ) + + fun maxComponents(p1: Vector2D, p2: Vector2D): Vector2D = Vector2D(max(p1.x, p2.x), max(p1.y, p2.y)) + fun maxComponents(p1: Vector2D, p2: Vector2D, p3: Vector2D): Vector2D = Vector2D( + maxOf(p1.x, p2.x, p3.x), + maxOf(p1.y, p2.y, p3.y) + ) + + fun maxComponents(p1: Vector2D, p2: Vector2D, p3: Vector2D, p4: Vector2D): Vector2D = Vector2D( + maxOf( + p1.x, + p2.x, + p3.x, + p4.x + ), maxOf(p1.y, p2.y, p3.y, p4.y) + ) + } +} + +fun Vector2D.toVector2F(): Vector2F = Vector2F(x, y) diff --git a/math/src/main/java/com/icegps/math/geometry/Vector2F.kt b/math/src/main/java/com/icegps/math/geometry/Vector2F.kt new file mode 100644 index 0000000..bb750fd --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Vector2F.kt @@ -0,0 +1,176 @@ +package com.icegps.math.geometry + +import com.icegps.math.isAlmostEquals +import kotlin.math.abs +import kotlin.math.hypot +import kotlin.math.max +import kotlin.math.min + +data class Vector2F(val x: Float, val y: Float) { + constructor(x: Double, y: Double) : this(x.toFloat(), y.toFloat()) + constructor(x: Int, y: Int) : this(x.toFloat(), y.toFloat()) + + constructor(x: Double, y: Int) : this(x.toFloat(), y.toFloat()) + constructor(x: Int, y: Double) : this(x.toFloat(), y.toFloat()) + + constructor(x: Float, y: Int) : this(x.toFloat(), y.toFloat()) + constructor(x: Int, y: Float) : this(x.toFloat(), y.toFloat()) + + //constructor(p: Vector2) : this(p.raw) + constructor() : this(0f, 0f) + //constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble()) + //constructor(x: Float, y: Float) : this(x.toDouble(), y.toDouble()) + + fun copy(x: Double = this.x.toDouble(), y: Double = this.y.toDouble()): Vector2F = Vector2F(x, y) + + inline operator fun unaryMinus(): Vector2F = Vector2F(-x, -y) + inline operator fun unaryPlus(): Vector2F = this + + inline operator fun plus(that: Vector2F): Vector2F = Vector2F(x + that.x, y + that.y) + inline operator fun minus(that: Vector2F): Vector2F = Vector2F(x - that.x, y - that.y) + inline operator fun times(that: Vector2F): Vector2F = Vector2F(x * that.x, y * that.y) + inline operator fun div(that: Vector2F): Vector2F = Vector2F(x / that.x, y / that.y) + inline operator fun rem(that: Vector2F): Vector2F = Vector2F(x % that.x, y % that.y) + + inline operator fun times(scale: Float): Vector2F = Vector2F(x * scale, y * scale) + inline operator fun times(scale: Double): Vector2F = this * scale.toFloat() + inline operator fun times(scale: Int): Vector2F = this * scale.toDouble() + + inline operator fun div(scale: Float): Vector2F = Vector2F(x / scale, y / scale) + inline operator fun div(scale: Double): Vector2F = this / scale.toFloat() + inline operator fun div(scale: Int): Vector2F = this / scale.toDouble() + + inline operator fun rem(scale: Float): Vector2F = Vector2F(x % scale, y % scale) + inline operator fun rem(scale: Double): Vector2F = this % scale.toFloat() + inline operator fun rem(scale: Int): Vector2F = this % scale.toDouble() + + fun avgComponent(): Float = x * 0.5f + y * 0.5f + fun minComponent(): Float = min(x, y) + fun maxComponent(): Float = max(x, y) + + fun distanceTo(x: Float, y: Float): Float = hypot(x - this.x, y - this.y) + fun distanceTo(x: Double, y: Double): Float = this.distanceTo(x.toFloat(), y.toFloat()) + fun distanceTo(x: Int, y: Int): Float = this.distanceTo(x.toDouble(), y.toDouble()) + fun distanceTo(that: Vector2F): Float = distanceTo(that.x, that.y) + + infix fun cross(that: Vector2F): Float = crossProduct(this, that) + infix fun dot(that: Vector2F): Float = ((this.x * that.x) + (this.y * that.y)) + + operator fun get(component: Int) = when (component) { + 0 -> x; 1 -> y + else -> throw IndexOutOfBoundsException("Point doesn't have $component component") + } + + val length: Float get() = hypot(x, y) + val lengthSquared: Float + get() { + val x = x + val y = y + return x * x + y * y + } + val magnitude: Float get() = hypot(x, y) + val normalized: Vector2F get() = this * (1f / magnitude) + val unit: Vector2F get() = this / length + + /** Normal vector. Rotates the vector/point -90 degrees (not normalizing it) */ + fun toNormal(): Vector2F = Vector2F(-this.y, this.x) + + fun round(): Vector2F = Vector2F(kotlin.math.round(x), kotlin.math.round(y)) + fun ceil(): Vector2F = Vector2F(kotlin.math.ceil(x), kotlin.math.ceil(y)) + fun floor(): Vector2F = Vector2F(kotlin.math.floor(x), kotlin.math.floor(y)) + + //fun copy(x: Double = this.x, y: Double = this.y): Vector2 = Point(x, y) + + fun isAlmostEquals(other: Vector2F, epsilon: Float = 0.00001f): Boolean = + this.x.isAlmostEquals(other.x, epsilon) && this.y.isAlmostEquals(other.y, epsilon) + + /** Vector2 with inverted (1f / v) components to this */ + fun inv(): Vector2F = Vector2F(1f / x, 1f / y) + + fun isNaN(): Boolean = this.x.isNaN() && this.y.isNaN() + + val absoluteValue: Vector2F get() = Vector2F(abs(x), abs(y)) + + companion object { + val ZERO = Vector2F(0f, 0f) + val NaN = Vector2F(Float.NaN, Float.NaN) + + /** Mathematically typical LEFT, matching screen coordinates (-1, 0) */ + val LEFT = Vector2F(-1f, 0f) + + /** Mathematically typical RIGHT, matching screen coordinates (+1, 0) */ + val RIGHT = Vector2F(+1f, 0f) + + /** Mathematically typical UP (0, +1) */ + val UP = Vector2F(0f, +1f) + + /** UP using 2D screen coordinates as reference (0, -1) */ + val UP_SCREEN = Vector2F(0f, -1f) + + /** Mathematically typical DOWN (0, -1) */ + val DOWN = Vector2F(0f, -1f) + + /** DOWN using 2D screen coordinates as reference (0, +1) */ + val DOWN_SCREEN = Vector2F(0f, +1f) + + fun distance(a: Double, b: Double): Double = abs(a - b) + fun distance(x1: Double, y1: Double, x2: Double, y2: Double): Double = hypot(x1 - x2, y1 - y2) + fun distance(x1: Float, y1: Float, x2: Float, y2: Float): Float = hypot(x1 - x2, y1 - y2) + fun distance(x1: Int, y1: Int, x2: Int, y2: Int): Float = distance(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat()) + fun distance(a: Vector2F, b: Vector2F): Float = distance(a.x, a.y, b.x, b.y) + + fun distanceSquared(a: Vector2F, b: Vector2F): Float = distanceSquared(a.x, a.y, b.x, b.y) + fun distanceSquared(x1: Double, y1: Double, x2: Double, y2: Double): Double = square(x1 - x2) + square(y1 - y2) + fun distanceSquared(x1: Float, y1: Float, x2: Float, y2: Float): Float = square(x1 - x2) + square(y1 - y2) + fun distanceSquared(x1: Int, y1: Int, x2: Int, y2: Int): Int = square(x1 - x2) + square(y1 - y2) + + @Deprecated("Likely searching for orientation") + inline fun direction(a: Vector2F, b: Vector2F): Vector2F = b - a + + fun compare(l: Vector2F, r: Vector2F): Int = compare(l.x, l.y, r.x, r.y) + fun compare(lx: Float, ly: Float, rx: Float, ry: Float): Int = ly.compareTo(ry).let { ret -> if (ret == 0) lx.compareTo(rx) else ret } + fun compare(lx: Double, ly: Double, rx: Double, ry: Double): Int = ly.compareTo(ry).let { ret -> if (ret == 0) lx.compareTo(rx) else ret } + + private fun square(x: Double): Double = x * x + private fun square(x: Float): Float = x * x + private fun square(x: Int): Int = x * x + + fun dot(aX: Double, aY: Double, bX: Double, bY: Double): Double = (aX * bX) + (aY * bY) + fun dot(aX: Float, aY: Float, bX: Float, bY: Float): Float = (aX * bX) + (aY * bY) + fun dot(a: Vector2F, b: Vector2F): Float = dot(a.x, a.y, b.x, b.y) + + fun crossProduct(ax: Float, ay: Float, bx: Float, by: Float): Float = (ax * by) - (bx * ay) + fun crossProduct(ax: Double, ay: Double, bx: Double, by: Double): Double = (ax * by) - (bx * ay) + fun crossProduct(p1: Vector2F, p2: Vector2F): Float = crossProduct(p1.x, p1.y, p2.x, p2.y) + + fun minComponents(p1: Vector2F, p2: Vector2F): Vector2F = Vector2F(min(p1.x, p2.x), min(p1.y, p2.y)) + fun minComponents(p1: Vector2F, p2: Vector2F, p3: Vector2F): Vector2F = Vector2F( + minOf(p1.x, p2.x, p3.x), + minOf(p1.y, p2.y, p3.y) + ) + + fun minComponents(p1: Vector2F, p2: Vector2F, p3: Vector2F, p4: Vector2F): Vector2F = Vector2F( + minOf( + p1.x, + p2.x, + p3.x, + p4.x + ), minOf(p1.y, p2.y, p3.y, p4.y) + ) + + fun maxComponents(p1: Vector2F, p2: Vector2F): Vector2F = Vector2F(max(p1.x, p2.x), max(p1.y, p2.y)) + fun maxComponents(p1: Vector2F, p2: Vector2F, p3: Vector2F): Vector2F = Vector2F( + maxOf(p1.x, p2.x, p3.x), + maxOf(p1.y, p2.y, p3.y) + ) + + fun maxComponents(p1: Vector2F, p2: Vector2F, p3: Vector2F, p4: Vector2F): Vector2F = Vector2F( + maxOf( + p1.x, + p2.x, + p3.x, + p4.x + ), maxOf(p1.y, p2.y, p3.y, p4.y) + ) + } +} \ No newline at end of file diff --git a/math/src/main/java/com/icegps/math/geometry/Vector3D.kt b/math/src/main/java/com/icegps/math/geometry/Vector3D.kt new file mode 100644 index 0000000..e295401 --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Vector3D.kt @@ -0,0 +1,9 @@ +package com.icegps.math.geometry + +typealias Point3 = Vector3D + +data class Vector3D(val x: Double, val y: Double, val z: Double) { + constructor() : this(0.0, 0.0, 0.0) +} + +fun Vector3D.toVector2D(): Vector2D = Vector2D(x, y) \ No newline at end of file diff --git a/math/src/main/java/com/icegps/math/geometry/Vector3F.kt b/math/src/main/java/com/icegps/math/geometry/Vector3F.kt new file mode 100644 index 0000000..9218476 --- /dev/null +++ b/math/src/main/java/com/icegps/math/geometry/Vector3F.kt @@ -0,0 +1,101 @@ +package com.icegps.math.geometry + +import com.icegps.math.IsAlmostEqualsF +import com.icegps.math.isAlmostEquals +import kotlin.math.abs +import kotlin.math.sqrt + +data class Vector3F(val x: Float, val y: Float, val z: Float) : IsAlmostEqualsF { + companion object { + val NaN = Vector3F(Float.NaN, Float.NaN, Float.NaN) + + val ZERO = Vector3F(0f, 0f, 0f) + val ONE = Vector3F(1f, 1f, 1f) + + val FORWARD = Vector3F(0f, 0f, 1f) + val BACK = Vector3F(0f, 0f, -1f) + val LEFT = Vector3F(-1f, 0f, 0f) + val RIGHT = Vector3F(1f, 0f, 0f) + val UP = Vector3F(0f, 1f, 0f) + val DOWN = Vector3F(0f, -1f, 0f) + + operator fun invoke(): Vector3F = ZERO + + fun cross(a: Vector3F, b: Vector3F): Vector3F = Vector3F( + ((a.y * b.z) - (a.z * b.y)), + ((a.z * b.x) - (a.x * b.z)), + ((a.x * b.y) - (a.y * b.x)), + ) + + fun length(x: Float, y: Float, z: Float): Float = sqrt(lengthSq(x, y, z)) + fun lengthSq(x: Float, y: Float, z: Float): Float = x * x + y * y + z * z + + fun fromArray(array: FloatArray, offset: Int): Vector3F = + Vector3F(array[offset + 0], array[offset + 1], array[offset + 2]) + + inline fun func(func: (index: Int) -> Float): Vector3F = Vector3F(func(0), func(1), func(2)) + } + + //constructor(x: Float, y: Float, z: Float) : this(float4PackOf(x, y, z, 0f)) + constructor(x: Int, y: Int, z: Int) : this(x.toFloat(), y.toFloat(), z.toFloat()) + constructor(x: Double, y: Double, z: Double) : this(x.toFloat(), y.toFloat(), z.toFloat()) + + fun distanceTo(other: Vector3F): Float { + val dx = this.x - other.x + val dy = this.y - other.y + val dz = this.z - other.z + return sqrt(dx * dx + dy * dy + dz * dz) + } + + val lengthSquared: Float get() = (x * x) + (y * y) + (z * z) + val length: Float get() = sqrt(lengthSquared) + fun normalized(): Vector3F { + val length = this.length + //if (length.isAlmostZero()) return Vector3.ZERO + if (length == 0f) return Vector3F.ZERO + return this / length + } + + operator fun get(index: Int): Float = when (index) { + 0 -> x + 1 -> y + 2 -> z + else -> throw IndexOutOfBoundsException() + } + + operator fun unaryPlus(): Vector3F = this + operator fun unaryMinus(): Vector3F = Vector3F(-this.x, -this.y, -this.z) + + operator fun plus(v: Vector3F): Vector3F = Vector3F(this.x + v.x, this.y + v.y, this.z + v.z) + operator fun minus(v: Vector3F): Vector3F = Vector3F(this.x - v.x, this.y - v.y, this.z - v.z) + + operator fun times(v: Vector3F): Vector3F = Vector3F(this.x * v.x, this.y * v.y, this.z * v.z) + operator fun div(v: Vector3F): Vector3F = Vector3F(this.x / v.x, this.y / v.y, this.z / v.z) + operator fun rem(v: Vector3F): Vector3F = Vector3F(this.x % v.x, this.y % v.y, this.z % v.z) + + operator fun times(v: Float): Vector3F = Vector3F(this.x * v, this.y * v, this.z * v) + operator fun div(v: Float): Vector3F = Vector3F(this.x / v, this.y / v, this.z / v) + operator fun rem(v: Float): Vector3F = Vector3F(this.x % v, this.y % v, this.z % v) + + operator fun times(v: Int): Vector3F = this * v.toFloat() + operator fun div(v: Int): Vector3F = this / v.toFloat() + operator fun rem(v: Int): Vector3F = this % v.toFloat() + + operator fun times(v: Double): Vector3F = this * v.toFloat() + operator fun div(v: Double): Vector3F = this / v.toFloat() + operator fun rem(v: Double): Vector3F = this % v.toFloat() + + infix fun dot(v: Vector3F): Float = (x * v.x) + (y * v.y) + (z * v.z) + infix fun cross(v: Vector3F): Vector3F = cross(this, v) + + /** Vector3 with inverted (1f / v) components to this */ + fun inv(): Vector3F = Vector3F(1f / x, 1f / y, 1f / z) + + fun isNaN(): Boolean = this.x.isNaN() && this.y.isNaN() && this.z.isNaN() + val absoluteValue: Vector3F get() = Vector3F(abs(x), abs(y), abs(z)) + + override fun isAlmostEquals(other: Vector3F, epsilon: Float): Boolean = + this.x.isAlmostEquals(other.x, epsilon) && + this.y.isAlmostEquals(other.y, epsilon) && + this.z.isAlmostEquals(other.z, epsilon) +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..da0cecc --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,25 @@ +pluginManagement { + repositories { + google { + content { + includeGroupByRegex("com\\.android.*") + includeGroupByRegex("com\\.google.*") + includeGroupByRegex("androidx.*") + } + } + mavenCentral() + gradlePluginPortal() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} + +rootProject.name = "maps" +include(":app") +include(":math") +include(":maps-view")