Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
e1603619fd
18 changed files with 768 additions and 249 deletions
|
@ -206,9 +206,16 @@ public class RouteDataObject {
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double directionRoute(int startPoint, boolean plus) {
|
||||
// Victor : the problem to put more than 5 meters that BinaryRoutePlanner will treat
|
||||
// 2 consequent Turn Right as UT and here 2 points will have same turn angle
|
||||
// So it should be fix in both places
|
||||
return directionRoute(startPoint, plus, 5);
|
||||
}
|
||||
|
||||
// Gives route direction of EAST degrees from NORTH ]-PI, PI]
|
||||
public double directionRoute(int startPoint, boolean plus) {
|
||||
public double directionRoute(int startPoint, boolean plus, float dist) {
|
||||
int x = getPoint31XTile(startPoint);
|
||||
int y = getPoint31YTile(startPoint);
|
||||
int nx = startPoint;
|
||||
|
@ -231,10 +238,7 @@ public class RouteDataObject {
|
|||
py = getPoint31YTile(nx);
|
||||
// translate into meters
|
||||
total += Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d;
|
||||
// Victor : the problem to put more than 5 meters that BinaryRoutePlanner will treat
|
||||
// 2 consequent Turn Right as UT and here 2 points will have same turn angle
|
||||
// So it should be fix in both places
|
||||
} while (total < 5);
|
||||
} while (total < dist);
|
||||
return -Math.atan2( x - px, y - py );
|
||||
}
|
||||
|
||||
|
|
|
@ -167,23 +167,62 @@ public class BinaryRoutePlanner {
|
|||
|
||||
public List<RouteSegmentResult> searchRoute(final RoutingContext ctx, RouteSegment start, RouteSegment end, List<RouteSegment> intermediate, boolean leftSideNavigation) throws IOException {
|
||||
if(intermediate != null && intermediate.size() > 0) {
|
||||
// TODO previously calculated route
|
||||
ArrayList<RouteSegment> ps = new ArrayList<RouteSegment>(intermediate);
|
||||
ArrayList<RouteSegmentResult> firstPartRecalculatedRoute = null;
|
||||
ArrayList<RouteSegmentResult> restPartRecalculatedRoute = null;
|
||||
if (ctx.previouslyCalculatedRoute != null) {
|
||||
List<RouteSegmentResult> prev = ctx.previouslyCalculatedRoute;
|
||||
long id = intermediate.get(0).getRoad().id;
|
||||
int ss = intermediate.get(0).getSegmentStart();
|
||||
for (int i = 0; i < prev.size(); i++) {
|
||||
RouteSegmentResult rsr = prev.get(i);
|
||||
if (id == rsr.getObject().getId() && ss == rsr.getEndPointIndex()) {
|
||||
firstPartRecalculatedRoute = new ArrayList<RouteSegmentResult>(prev.subList(0, i + 1));
|
||||
restPartRecalculatedRoute = new ArrayList<RouteSegmentResult>(prev.subList(i + 1, prev.size()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ps.add(end);
|
||||
ps.add(0, start);
|
||||
List<RouteSegmentResult> results = new ArrayList<RouteSegmentResult>();
|
||||
for (int i = 0; i < ps.size() - 1; i++) {
|
||||
RoutingContext local = new RoutingContext(ctx.config);
|
||||
local.copyLoadedDataAndClearCaches(ctx);
|
||||
if(i == 0) {
|
||||
local.previouslyCalculatedRoute = firstPartRecalculatedRoute;
|
||||
}
|
||||
local.visitor = ctx.visitor;
|
||||
List<RouteSegmentResult> res = searchRouteInternal(local, ps.get(i), ps.get(i + 1), leftSideNavigation);
|
||||
results.addAll(res);
|
||||
ctx.distinctLoadedTiles += local.distinctLoadedTiles;
|
||||
ctx.distinctUnloadedTiles.addAll(local.distinctUnloadedTiles);
|
||||
ctx.loadedTiles += local.loadedTiles;
|
||||
ctx.visitedSegments += local.visitedSegments;
|
||||
ctx.loadedPrevUnloadedTiles += local.loadedPrevUnloadedTiles;
|
||||
ctx.timeToCalculate += local.timeToCalculate;
|
||||
ctx.timeToLoad += local.timeToLoad;
|
||||
ctx.relaxedSegments += local.relaxedSegments;
|
||||
|
||||
List<RoutingTile> toUnload = new ArrayList<RoutingContext.RoutingTile>();
|
||||
for(RoutingTile t : local.tiles.valueCollection()){
|
||||
if(!ctx.tiles.contains(t.getId())) {
|
||||
toUnload.add(t);
|
||||
}
|
||||
}
|
||||
for(RoutingTile tl : toUnload) {
|
||||
local.unloadTile(tl, false);
|
||||
}
|
||||
if(restPartRecalculatedRoute != null) {
|
||||
results.addAll(restPartRecalculatedRoute);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Object[] vls = ctx.tiles.values();
|
||||
for (Object tl : vls) {
|
||||
if (((RoutingTile) tl).isLoaded()) {
|
||||
ctx.unloadTile((RoutingTile) tl, false);
|
||||
}
|
||||
}
|
||||
printResults(ctx, start, end, results);
|
||||
return results;
|
||||
|
@ -196,6 +235,10 @@ public class BinaryRoutePlanner {
|
|||
if(result != null) {
|
||||
printResults(ctx, start, end, result);
|
||||
}
|
||||
Object[] vls = ctx.tiles.values();
|
||||
for(Object tl : vls) {
|
||||
ctx.unloadTile((RoutingTile) tl, false);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -352,10 +395,6 @@ public class BinaryRoutePlanner {
|
|||
|
||||
// 4. Route is found : collect all segments and prepare result
|
||||
List<RouteSegmentResult> resultPrepared = prepareResult(ctx, start, end, leftSideNavigation);
|
||||
Object[] vls = ctx.tiles.values();
|
||||
for(Object tl : vls) {
|
||||
ctx.unloadTile((RoutingTile) tl, false);
|
||||
}
|
||||
return resultPrepared;
|
||||
}
|
||||
|
||||
|
@ -1050,8 +1089,15 @@ public class BinaryRoutePlanner {
|
|||
}
|
||||
TurnType t = null;
|
||||
if (prev != null) {
|
||||
boolean noAttachedRoads = rr.getAttachedRoutes(rr.getStartPointIndex()).size() == 0;
|
||||
// add description about turn
|
||||
double mpi = MapUtils.degreesDiff(prev.getBearingEnd(), rr.getBearingBegin());
|
||||
if(noAttachedRoads){
|
||||
// TODO VICTOR : look at the comment inside direction route
|
||||
// double begin = rr.getObject().directionRoute(rr.getStartPointIndex(), rr.getStartPointIndex() <
|
||||
// rr.getEndPointIndex(), 25);
|
||||
// mpi = MapUtils.degreesDiff(prev.getBearingEnd(), begin);
|
||||
}
|
||||
if (mpi >= TURN_DEGREE_MIN) {
|
||||
if (mpi < 60) {
|
||||
t = TurnType.valueOf(TurnType.TSLL, leftSide);
|
||||
|
|
|
@ -372,6 +372,24 @@ public class RoutingContext {
|
|||
}
|
||||
}
|
||||
|
||||
public void copyLoadedDataAndClearCaches(RoutingContext ctx) {
|
||||
for(RoutingTile tl : ctx.tiles.valueCollection()) {
|
||||
if(tl.isLoaded()) {
|
||||
this.tiles.put(tl.getId(), tl);
|
||||
for(RouteSegment rs : tl.routes.valueCollection()) {
|
||||
RouteSegment s = rs;
|
||||
while(s != null) {
|
||||
s.parentRoute = null;
|
||||
s.parentSegmentEnd = 0;
|
||||
s.distanceFromStart = 0;
|
||||
s.distanceToEnd = 0;
|
||||
s = s.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RoutingTile {
|
||||
private int tileX;
|
||||
private int tileY;
|
||||
|
@ -489,4 +507,5 @@ public class RoutingContext {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -1 +1,4 @@
|
|||
bin
|
||||
.project
|
||||
.classpath
|
||||
.externalToolBuilders
|
||||
target
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>net.osmand.translator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -1,7 +0,0 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -1,15 +0,0 @@
|
|||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Translator
|
||||
Bundle-SymbolicName: net.osmand.translator;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: net.osmand.translator.Activator
|
||||
Require-Bundle: org.eclipse.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.jdt;bundle-version="3.7.2",
|
||||
org.eclipse.jdt.core;bundle-version="3.7.3",
|
||||
org.eclipse.jdt.ui;bundle-version="3.7.2",
|
||||
org.eclipse.jface.text;bundle-version="3.7.2",
|
||||
org.eclipse.core.resources;bundle-version="3.7.101"
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
|
@ -1,6 +0,0 @@
|
|||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.,\
|
||||
icons/
|
Binary file not shown.
Before Width: | Height: | Size: 983 B |
|
@ -1,62 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<category
|
||||
name="Sample Category"
|
||||
id="net.osmand.translator.commands.category">
|
||||
</category>
|
||||
<command
|
||||
name="Sample Command"
|
||||
categoryId="net.osmand.translator.commands.category"
|
||||
id="net.osmand.translator.commands.sampleCommand">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
commandId="net.osmand.translator.commands.sampleCommand"
|
||||
class="net.osmand.translator.handlers.TranslationHandler">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.bindings">
|
||||
<key
|
||||
commandId="net.osmand.translator.commands.sampleCommand"
|
||||
contextId="org.eclipse.ui.contexts.window"
|
||||
sequence="M1+6"
|
||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||
</key>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
|
||||
<menu
|
||||
label="Translate To C++"
|
||||
mnemonic="M"
|
||||
id="net.osmand.translator.menus.sampleMenu">
|
||||
<command
|
||||
commandId="net.osmand.translator.commands.sampleCommand"
|
||||
mnemonic="S"
|
||||
id="net.osmand.translator.menus.sampleCommand">
|
||||
</command>
|
||||
</menu>
|
||||
</menuContribution>
|
||||
<menuContribution
|
||||
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
|
||||
<toolbar
|
||||
id="net.osmand.translator.toolbars.sampleToolbar">
|
||||
<command
|
||||
commandId="net.osmand.translator.commands.sampleCommand"
|
||||
icon="icons/sample.gif"
|
||||
tooltip="Say hello world"
|
||||
id="net.osmand.translator.toolbars.sampleCommand">
|
||||
</command>
|
||||
</toolbar>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
147
build-scripts/net.osmand.translator/pom.xml
Normal file
147
build-scripts/net.osmand.translator/pom.xml
Normal file
|
@ -0,0 +1,147 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.osmand.translator</groupId>
|
||||
<artifactId>OsmAndTranslator</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1</version>
|
||||
<name>OsmAndTranslator</name>
|
||||
|
||||
<build>
|
||||
<directory>target</directory>
|
||||
<outputDirectory>target/classes</outputDirectory>
|
||||
<finalName>${artifactId}-${version}</finalName>
|
||||
<testOutputDirectory>target/test-classes</testOutputDirectory>
|
||||
<sourceDirectory>src</sourceDirectory>
|
||||
<testSourceDirectory>test/src</testSourceDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<testResources>
|
||||
<testResource>
|
||||
<directory>test/resources</directory>
|
||||
</testResource>
|
||||
</testResources>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!-- Copy dependent jars -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<!-- <executions> <execution> <id>copy-dependencies</id> <phase>generate-resources</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <excludeTransitive>true</excludeTransitive>
|
||||
</configuration> </execution> </executions> -->
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-plugin-plugin</artifactId>
|
||||
<version>2.4.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-eclipse-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<goals>
|
||||
<project>OsmAndTranslator</project>
|
||||
</goals>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>13.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>2.0.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.core</groupId>
|
||||
<artifactId>org.eclipse.core.contenttype</artifactId>
|
||||
<version>3.4.100.v20100505-1235</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.registry</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.core</groupId>
|
||||
<artifactId>org.eclipse.core.jobs</artifactId>
|
||||
<version>3.5.0.v20100515</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.core</groupId>
|
||||
<artifactId>org.eclipse.core.resources</artifactId>
|
||||
<version>3.6.0.v20100526-0737</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.core</groupId>
|
||||
<artifactId>org.eclipse.core.expressions</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.core</groupId>
|
||||
<artifactId>org.eclipse.core.filesystem</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.core</groupId>
|
||||
<artifactId>org.eclipse.core.runtime</artifactId>
|
||||
<version>3.6.0.v20100505</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.app</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.common</artifactId>
|
||||
<version>3.6.0.v20100503</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.equinox</groupId>
|
||||
<artifactId>org.eclipse.equinox.preferences</artifactId>
|
||||
<version>3.3.0.v20100503</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>org.eclipse.jdt.core</artifactId>
|
||||
<version>3.8.1.v20120531-0637</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.osgi</groupId>
|
||||
<artifactId>org.eclipse.osgi</artifactId>
|
||||
<version>3.6.0.v20100517</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jibx.config.3rdparty.org.eclipse</groupId>
|
||||
<artifactId>org.eclipse.text</artifactId>
|
||||
<version>3.5.100.v20110505-0800</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,61 +0,0 @@
|
|||
package net.osmand.translator;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "net.osmand.translator"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public Activator() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package net.osmand.translator;
|
||||
|
||||
public class TranslatorMain {
|
||||
|
||||
}
|
|
@ -3,9 +3,6 @@ package net.osmand.translator.handlers;
|
|||
import net.osmand.translator.utils.FieldsHandler;
|
||||
import net.osmand.translator.utils.MethodHandler;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IWorkspace;
|
||||
|
@ -13,7 +10,6 @@ import org.eclipse.core.resources.IWorkspaceRoot;
|
|||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.jdt.core.ICompilationUnit;
|
||||
import org.eclipse.jdt.core.IJavaProject;
|
||||
import org.eclipse.jdt.core.IMethod;
|
||||
|
@ -28,22 +24,22 @@ import org.eclipse.jdt.core.dom.CompilationUnit;
|
|||
import org.eclipse.jface.text.Document;
|
||||
//import org.eclipse.jface.text.Document;
|
||||
|
||||
public class TranslationHandler extends AbstractHandler {
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IWorkspaceRoot root = workspace.getRoot();
|
||||
IPath path = root.getProject("DataExtactionOSM").getFile("src/net/osmand/osm/MapUtils.java").getFullPath();
|
||||
// parse "MapUtils.java"
|
||||
// IPath path = Path.fromOSString("/DataExtractionOSM/src/net/osmand/osm/MapUtils.java");
|
||||
IFile iFile = root.getFileForLocation(path);
|
||||
ICompilationUnit unit = (ICompilationUnit)JavaCore.create(iFile);
|
||||
CompilationUnit parse = parse(unit);
|
||||
FieldsHandler.printFieldsInfo(parse);
|
||||
System.out.println();
|
||||
MethodHandler.printMethodsInfo(parse);
|
||||
return null;
|
||||
}
|
||||
|
||||
public class TranslationHandler {
|
||||
|
||||
public static void execute() {
|
||||
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||
IWorkspaceRoot root = workspace.getRoot();
|
||||
IPath path = root.getProject("DataExtactionOSM").getFile("src/net/osmand/osm/MapUtils.java").getFullPath();
|
||||
// parse "MapUtils.java"
|
||||
// IPath path = Path.fromOSString("/DataExtractionOSM/src/net/osmand/osm/MapUtils.java");
|
||||
IFile iFile = root.getFileForLocation(path);
|
||||
ICompilationUnit unit = (ICompilationUnit) JavaCore.create(iFile);
|
||||
CompilationUnit parse = parse(unit);
|
||||
FieldsHandler.printFieldsInfo(parse);
|
||||
System.out.println();
|
||||
MethodHandler.printMethodsInfo(parse);
|
||||
}
|
||||
|
||||
private static CompilationUnit parse(ICompilationUnit unit) {
|
||||
ASTParser parser = ASTParser.newParser(AST.JLS3);
|
||||
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||
|
@ -52,21 +48,20 @@ public class TranslationHandler extends AbstractHandler {
|
|||
return (CompilationUnit) parser.createAST(null); // parse
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void getProjects(IWorkspaceRoot root) {
|
||||
IProject[] projects = root.getProjects();
|
||||
for (IProject project : projects) {
|
||||
try {
|
||||
printProjectInfo(project);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (IProject project : projects) {
|
||||
try {
|
||||
printProjectInfo(project);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printProjectInfo(IProject project) throws CoreException,
|
||||
JavaModelException {
|
||||
|
||||
private void printProjectInfo(IProject project) throws CoreException, JavaModelException {
|
||||
System.out.println("Working in project " + project.getName());
|
||||
// Check if we have a Java project
|
||||
if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
|
||||
|
@ -75,34 +70,31 @@ public class TranslationHandler extends AbstractHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private void printPackageInfos(IJavaProject javaProject)
|
||||
throws JavaModelException {
|
||||
IPackageFragment[] packages = javaProject.getPackageFragments();
|
||||
for (IPackageFragment mypackage : packages) {
|
||||
// Package fragments include all packages in the
|
||||
// classpath
|
||||
// We will only look at the package from the source
|
||||
// folder
|
||||
// K_BINARY would include also included JARS, e.g.
|
||||
// rt.jar
|
||||
if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
|
||||
System.out.println("Package " + mypackage.getElementName());
|
||||
printICompilationUnitInfo(mypackage);
|
||||
private void printPackageInfos(IJavaProject javaProject) throws JavaModelException {
|
||||
IPackageFragment[] packages = javaProject.getPackageFragments();
|
||||
for (IPackageFragment mypackage : packages) {
|
||||
// Package fragments include all packages in the
|
||||
// classpath
|
||||
// We will only look at the package from the source
|
||||
// folder
|
||||
// K_BINARY would include also included JARS, e.g.
|
||||
// rt.jar
|
||||
if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
|
||||
System.out.println("Package " + mypackage.getElementName());
|
||||
printICompilationUnitInfo(mypackage);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void printICompilationUnitInfo(IPackageFragment mypackage)
|
||||
throws JavaModelException {
|
||||
private void printICompilationUnitInfo(IPackageFragment mypackage) throws JavaModelException {
|
||||
for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
|
||||
printCompilationUnitDetails(unit);
|
||||
}
|
||||
}
|
||||
|
||||
private void printCompilationUnitDetails(ICompilationUnit unit)
|
||||
throws JavaModelException {
|
||||
private void printCompilationUnitDetails(ICompilationUnit unit) throws JavaModelException {
|
||||
System.out.println("Source file " + unit.getElementName());
|
||||
Document doc = new Document(unit.getSource());
|
||||
System.out.println("Has number of lines: " + doc.getNumberOfLines());
|
||||
|
|
475
build-scripts/net.osmand.translator/test/resources/MapUtils.java
Normal file
475
build-scripts/net.osmand.translator/test/resources/MapUtils.java
Normal file
|
@ -0,0 +1,475 @@
|
|||
package net.osmand.osm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.data.MapObject;
|
||||
|
||||
|
||||
/**
|
||||
* This utility class includes :
|
||||
* 1. distance algorithms
|
||||
* 2. finding center for array of nodes
|
||||
* 3. tile evaluation algorithms
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class MapUtils {
|
||||
|
||||
private static final String BASE_SHORT_OSM_URL = "http://osm.org/go/";
|
||||
|
||||
/**
|
||||
* This array is a lookup table that translates 6-bit positive integer
|
||||
* index values into their "Base64 Alphabet" equivalents as specified
|
||||
* in Table 1 of RFC 2045.
|
||||
*/
|
||||
private static final char intToBase64[] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_', '@'
|
||||
};
|
||||
|
||||
public static double getDistance(Node e1, Node e2){
|
||||
return getDistance(e1.getLatitude(), e1.getLongitude(), e2.getLatitude(), e2.getLongitude());
|
||||
}
|
||||
|
||||
public static double getDistance(LatLon l, double latitude, double longitude){
|
||||
return getDistance(l.getLatitude(), l.getLongitude(), latitude, longitude);
|
||||
}
|
||||
|
||||
public static double getDistance(Node e1, double latitude, double longitude){
|
||||
return getDistance(e1.getLatitude(), e1.getLongitude(), latitude, longitude);
|
||||
}
|
||||
|
||||
public static double getDistance(Node e1, LatLon point){
|
||||
return getDistance(e1.getLatitude(), e1.getLongitude(), point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
private static double scalarMultiplication(double xA, double yA, double xB, double yB, double xC, double yC) {
|
||||
// Scalar multiplication between (AB, AC)
|
||||
double multiple = (xB - xA) * (xC - xA) + (yB- yA) * (yC -yA);
|
||||
return multiple;
|
||||
}
|
||||
|
||||
public static double getOrthogonalDistance(double lat, double lon, double fromLat, double fromLon, double toLat, double toLon) {
|
||||
return getDistance(getProjection(lat, lon, fromLat, fromLon, toLat, toLon), lat, lon);
|
||||
}
|
||||
|
||||
public static LatLon getProjection(double lat, double lon, double fromLat, double fromLon, double toLat, double toLon) {
|
||||
// not very accurate computation on sphere but for distances < 1000m it is ok
|
||||
double mDist = (fromLat - toLat) * (fromLat - toLat) + (fromLon - toLon) * (fromLon - toLon);
|
||||
double projection = scalarMultiplication(fromLat, fromLon, toLat, toLon, lat, lon);
|
||||
double prlat;
|
||||
double prlon;
|
||||
if (projection < 0) {
|
||||
prlat = fromLat;
|
||||
prlon = fromLon;
|
||||
} else if (projection >= mDist) {
|
||||
prlat = toLat;
|
||||
prlon = toLon;
|
||||
} else {
|
||||
prlat = fromLat + (toLat - fromLat) * (projection / mDist);
|
||||
prlon = fromLon + (toLon - fromLon) * (projection / mDist);
|
||||
}
|
||||
return new LatLon(prlat, prlon);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets distance in meters
|
||||
*/
|
||||
public static double getDistance(double lat1, double lon1, double lat2, double lon2){
|
||||
double R = 6371; // km
|
||||
double dLat = Math.toRadians(lat2-lat1);
|
||||
double dLon = Math.toRadians(lon2-lon1);
|
||||
double a = Math.sin(dLat/2) * Math.sin(dLat/2) +
|
||||
Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) *
|
||||
Math.sin(dLon/2) * Math.sin(dLon/2);
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||
return R * c * 1000;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets distance in meters
|
||||
*/
|
||||
public static double getDistance(LatLon l1, LatLon l2){
|
||||
return getDistance(l1.getLatitude(), l1.getLongitude(), l2.getLatitude(), l2.getLongitude());
|
||||
}
|
||||
|
||||
public static LatLon getCenter(Entity e){
|
||||
if(e instanceof Node){
|
||||
return ((Node) e).getLatLon();
|
||||
} else if(e instanceof Way){
|
||||
return getWeightCenterForNodes(((Way) e).getNodes());
|
||||
} else if(e instanceof Relation){
|
||||
List<LatLon> list = new ArrayList<LatLon>();
|
||||
for(Entity fe : ((Relation) e).getMembers(null)){
|
||||
LatLon c = null;
|
||||
// skip relations to avoid circular dependencies
|
||||
if(!(fe instanceof Relation)){
|
||||
c = getCenter(fe);
|
||||
}
|
||||
if(c != null){
|
||||
list.add(c);
|
||||
}
|
||||
}
|
||||
return getWeightCenter(list);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static LatLon getWeightCenter(Collection<LatLon> nodes){
|
||||
if(nodes.isEmpty()){
|
||||
return null;
|
||||
}
|
||||
double longitude = 0;
|
||||
double latitude = 0;
|
||||
for(LatLon n : nodes){
|
||||
longitude += n.getLongitude();
|
||||
latitude += n.getLatitude();
|
||||
}
|
||||
return new LatLon(latitude/nodes.size(), longitude/nodes.size());
|
||||
}
|
||||
|
||||
public static LatLon getWeightCenterForNodes(Collection<Node> nodes){
|
||||
if (nodes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
double longitude = 0;
|
||||
double latitude = 0;
|
||||
int count = 0;
|
||||
for (Node n : nodes) {
|
||||
if (n != null) {
|
||||
count++;
|
||||
longitude += n.getLongitude();
|
||||
latitude += n.getLatitude();
|
||||
}
|
||||
}
|
||||
if (count == 0) {
|
||||
return null;
|
||||
}
|
||||
return new LatLon(latitude/count, longitude/count);
|
||||
}
|
||||
|
||||
|
||||
public static LatLon getMathWeightCenterForNodes(Collection<Node> nodes){
|
||||
if (nodes.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
double longitude = 0;
|
||||
double latitude = 0;
|
||||
double sumDist = 0;
|
||||
Node prev = null;
|
||||
for (Node n : nodes) {
|
||||
if (n != null) {
|
||||
if(prev == null){
|
||||
prev = n;
|
||||
} else {
|
||||
double dist = MapUtils.getDistance(prev, n);
|
||||
sumDist += dist;
|
||||
longitude += (prev.getLongitude() + n.getLongitude()) * dist / 2;
|
||||
latitude += (n.getLatitude() + n.getLatitude()) * dist / 2;
|
||||
prev = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sumDist == 0) {
|
||||
if(prev == null){
|
||||
return null;
|
||||
}
|
||||
return prev.getLatLon();
|
||||
}
|
||||
return new LatLon(latitude/sumDist, longitude/sumDist);
|
||||
}
|
||||
|
||||
public static double checkLongitude(double longitude) {
|
||||
while (longitude < -180 || longitude > 180) {
|
||||
if (longitude < 0) {
|
||||
longitude += 360;
|
||||
} else {
|
||||
longitude -= 360;
|
||||
}
|
||||
}
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public static double checkLatitude(double latitude) {
|
||||
while (latitude < -90 || latitude > 90) {
|
||||
if (latitude < 0) {
|
||||
latitude += 180;
|
||||
} else {
|
||||
latitude -= 180;
|
||||
}
|
||||
}
|
||||
if(latitude < -85.0511) {
|
||||
return -85.0511;
|
||||
} else if(latitude > 85.0511){
|
||||
return 85.0511;
|
||||
}
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public static int get31TileNumberX(double longitude){
|
||||
longitude = checkLongitude(longitude);
|
||||
long l = 1l << 31;
|
||||
return (int)((longitude + 180d)/360d * l);
|
||||
}
|
||||
public static int get31TileNumberY( double latitude){
|
||||
latitude = checkLatitude(latitude);
|
||||
double eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) );
|
||||
long l = 1l << 31;
|
||||
if(eval > Math.PI){
|
||||
eval = Math.PI;
|
||||
}
|
||||
return (int) ((1 - eval / Math.PI) / 2 * l);
|
||||
}
|
||||
|
||||
public static double get31LongitudeX(int tileX){
|
||||
return MapUtils.getLongitudeFromTile(21, tileX /1024f);
|
||||
}
|
||||
|
||||
public static double get31LatitudeY(int tileY){
|
||||
return MapUtils.getLatitudeFromTile(21, tileY /1024f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Theses methods operate with degrees (evaluating tiles & vice versa)
|
||||
* degree longitude measurements (-180, 180) [27.56 Minsk]
|
||||
// degree latitude measurements (90, -90) [53.9]
|
||||
*/
|
||||
|
||||
public static double getTileNumberX(float zoom, double longitude){
|
||||
if(longitude == 180d) {
|
||||
return getPowZoom(zoom) - 1;
|
||||
}
|
||||
longitude = checkLongitude(longitude);
|
||||
return (longitude + 180d)/360d * getPowZoom(zoom);
|
||||
}
|
||||
|
||||
public static double getTileNumberY(float zoom, double latitude){
|
||||
latitude = checkLatitude(latitude);
|
||||
double eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) );
|
||||
if (Double.isInfinite(eval) || Double.isNaN(eval)) {
|
||||
latitude = latitude < 0 ? - 89.9 : 89.9;
|
||||
eval = Math.log( Math.tan(Math.toRadians(latitude)) + 1/Math.cos(Math.toRadians(latitude)) );
|
||||
}
|
||||
double result = (1 - eval / Math.PI) / 2 * getPowZoom(zoom);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static double getTileEllipsoidNumberY(float zoom, double latitude){
|
||||
final double E2 = (double) latitude * Math.PI / 180;
|
||||
final long sradiusa = 6378137;
|
||||
final long sradiusb = 6356752;
|
||||
final double J2 = (double) Math.sqrt(sradiusa * sradiusa - sradiusb * sradiusb) / sradiusa;
|
||||
final double M2 = (double) Math.log((1 + Math.sin(E2))
|
||||
/ (1 - Math.sin(E2)))/ 2- J2 * Math.log((1 + J2 * Math.sin(E2))/ (1 - J2 * Math.sin(E2))) / 2;
|
||||
final double B2 = getPowZoom(zoom);
|
||||
return B2 / 2 - M2 * B2 / 2 / Math.PI;
|
||||
}
|
||||
|
||||
public static double getLatitudeFromEllipsoidTileY(float zoom, float tileNumberY){
|
||||
final double MerkElipsK = 0.0000001;
|
||||
final long sradiusa = 6378137;
|
||||
final long sradiusb = 6356752;
|
||||
final double FExct = (double) Math.sqrt(sradiusa * sradiusa
|
||||
- sradiusb * sradiusb)
|
||||
/ sradiusa;
|
||||
final double TilesAtZoom = getPowZoom(zoom);
|
||||
double result = (tileNumberY - TilesAtZoom / 2)
|
||||
/ -(TilesAtZoom / (2 * Math.PI));
|
||||
result = (2 * Math.atan(Math.exp(result)) - Math.PI / 2) * 180
|
||||
/ Math.PI;
|
||||
double Zu = result / (180 / Math.PI);
|
||||
double yy = (tileNumberY - TilesAtZoom / 2);
|
||||
|
||||
double Zum1 = Zu;
|
||||
Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
|
||||
/ (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
|
||||
while (Math.abs(Zum1 - Zu) >= MerkElipsK) {
|
||||
Zum1 = Zu;
|
||||
Zu = Math.asin(1 - ((1 + Math.sin(Zum1)) * Math.pow(1 - FExct * Math.sin(Zum1), FExct))
|
||||
/ (Math.exp((2 * yy) / -(TilesAtZoom / (2 * Math.PI))) * Math.pow(1 + FExct * Math.sin(Zum1), FExct)));
|
||||
}
|
||||
|
||||
return Zu * 180 / Math.PI;
|
||||
}
|
||||
|
||||
|
||||
public static double getLongitudeFromTile(float zoom, double x) {
|
||||
return x / getPowZoom(zoom) * 360.0 - 180.0;
|
||||
}
|
||||
|
||||
public static double getPowZoom(float zoom){
|
||||
if(zoom >= 0 && zoom - Math.floor(zoom) < 0.05f){
|
||||
return 1 << ((int)zoom);
|
||||
} else {
|
||||
return Math.pow(2, zoom);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static float calcDiffPixelX(float rotateSin, float rotateCos, float dTileX, float dTileY, float tileSize){
|
||||
return (rotateCos * dTileX - rotateSin * dTileY) * tileSize ;
|
||||
}
|
||||
|
||||
public static float calcDiffPixelY(float rotateSin, float rotateCos, float dTileX, float dTileY, float tileSize){
|
||||
return (rotateSin * dTileX + rotateCos * dTileY) * tileSize ;
|
||||
}
|
||||
|
||||
public static double getLatitudeFromTile(float zoom, double y){
|
||||
int sign = y < 0 ? -1 : 1;
|
||||
double result = Math.atan(sign*Math.sinh(Math.PI * (1 - 2 * y / getPowZoom(zoom)))) * 180d / Math.PI;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static int getPixelShiftX(int zoom, double long1, double long2, int tileSize){
|
||||
return (int) ((getTileNumberX(zoom, long1) - getTileNumberX(zoom, long2)) * tileSize);
|
||||
}
|
||||
|
||||
|
||||
public static int getPixelShiftY(int zoom, double lat1, double lat2, int tileSize){
|
||||
return (int) ((getTileNumberY(zoom, lat1) - getTileNumberY(zoom, lat2)) * tileSize);
|
||||
}
|
||||
|
||||
public static void addIdsToList(Collection<? extends Entity> source, List<Long> ids){
|
||||
for(Entity e : source){
|
||||
ids.add(e.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static void sortListOfMapObject(List<? extends MapObject> list, final double lat, final double lon){
|
||||
Collections.sort(list, new Comparator<MapObject>() {
|
||||
@Override
|
||||
public int compare(MapObject o1, MapObject o2) {
|
||||
return Double.compare(MapUtils.getDistance(o1.getLocation(), lat, lon), MapUtils.getDistance(o2.getLocation(),
|
||||
lat, lon));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void sortListOfEntities(List<? extends Entity> list, final double lat, final double lon){
|
||||
Collections.sort(list, new Comparator<Entity>() {
|
||||
@Override
|
||||
public int compare(Entity o1, Entity o2) {
|
||||
return Double.compare(MapUtils.getDistance(o1.getLatLon(), lat, lon), MapUtils.getDistance(o2.getLatLon(),
|
||||
lat, lon));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Examples
|
||||
// System.out.println(buildShortOsmUrl(51.51829d, 0.07347d, 16)); // http://osm.org/go/0EEQsyfu
|
||||
// System.out.println(buildShortOsmUrl(52.30103d, 4.862927d, 18)); // http://osm.org/go/0E4_JiVhs
|
||||
// System.out.println(buildShortOsmUrl(40.59d, -115.213d, 9)); // http://osm.org/go/TelHTB--
|
||||
public static String buildShortOsmUrl(double latitude, double longitude, int zoom){
|
||||
long lat = (long) (((latitude + 90d)/180d)*(1l << 32));
|
||||
long lon = (long) (((longitude + 180d)/360d)*(1l << 32));
|
||||
long code = interleaveBits(lon, lat);
|
||||
StringBuilder str = new StringBuilder(10);
|
||||
str.append(BASE_SHORT_OSM_URL);
|
||||
// add eight to the zoom level, which approximates an accuracy of one pixel in a tile.
|
||||
for(int i=0; i< Math.ceil((zoom+8)/3d); i++){
|
||||
str.append(intToBase64[(int) ((code >> (58 - 6 * i)) & 0x3f)]);
|
||||
}
|
||||
// append characters onto the end of the string to represent
|
||||
// partial zoom levels (characters themselves have a granularity of 3 zoom levels).
|
||||
for(int j=0; j< (zoom + 8) % 3 ; j++){
|
||||
str.append('-');
|
||||
}
|
||||
str.append("?m");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* interleaves the bits of two 32-bit numbers. the result is known as a Morton code.
|
||||
*/
|
||||
private static long interleaveBits(long x, long y){
|
||||
long c = 0;
|
||||
for(byte b = 31; b>=0; b--){
|
||||
c = (c << 1) | ((x >> b) & 1);
|
||||
c = (c << 1) | ((y >> b) & 1);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate rotation diff D, that R (rotate) + D = T (targetRotate)
|
||||
* D is between -180, 180
|
||||
* @param rotate
|
||||
* @param targetRotate
|
||||
* @return
|
||||
*/
|
||||
public static float unifyRotationDiff(float rotate, float targetRotate) {
|
||||
float d = targetRotate - rotate;
|
||||
while(d >= 180){
|
||||
d -= 360;
|
||||
}
|
||||
while(d < -180){
|
||||
d += 360;
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate rotation diff D, that R (rotate) + D = T (targetRotate)
|
||||
* D is between -180, 180
|
||||
* @param rotate
|
||||
* @param targetRotate
|
||||
* @return
|
||||
*/
|
||||
public static float unifyRotationTo360(float rotate) {
|
||||
while(rotate < 0){
|
||||
rotate += 360;
|
||||
}
|
||||
while(rotate > 360){
|
||||
rotate -= 360;
|
||||
}
|
||||
return rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param diff align difference between 2 angles ]-PI, PI]
|
||||
* @return
|
||||
*/
|
||||
public static double alignAngleDifference(double diff) {
|
||||
while(diff > Math.PI) {
|
||||
diff -= 2 * Math.PI;
|
||||
}
|
||||
while(diff <=-Math.PI) {
|
||||
diff += 2 * Math.PI;
|
||||
}
|
||||
return diff;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param diff align difference between 2 angles ]-180, 180]
|
||||
* @return
|
||||
*/
|
||||
public static double degreesDiff(double a1, double a2) {
|
||||
double diff = a1 - a2;
|
||||
while(diff > 180) {
|
||||
diff -= 360;
|
||||
}
|
||||
while(diff <=-180) {
|
||||
diff += 360;
|
||||
}
|
||||
return diff;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package net.osmand.translator.test;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class TranslatorTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void simpleTest(){
|
||||
|
||||
System.out.println("SUCCESS !!!!! ");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue