From 7d57b8e9ec3747d6b244fe49e6d6cf1399d74834 Mon Sep 17 00:00:00 2001 From: Hannes Janetzek Date: Sun, 19 Jan 2014 14:52:01 +0100 Subject: [PATCH] merge Vec2 class into OBB2D --- vtm/src/org/oscim/utils/OBB2D.java | 64 ++++++++++++++++++++++++ vtm/src/org/oscim/utils/Vec2.java | 80 ------------------------------ 2 files changed, 64 insertions(+), 80 deletions(-) delete mode 100644 vtm/src/org/oscim/utils/Vec2.java diff --git a/vtm/src/org/oscim/utils/OBB2D.java b/vtm/src/org/oscim/utils/OBB2D.java index e016a057..0a2cb27e 100644 --- a/vtm/src/org/oscim/utils/OBB2D.java +++ b/vtm/src/org/oscim/utils/OBB2D.java @@ -24,6 +24,70 @@ package org.oscim.utils; */ public class OBB2D { + + public static class Vec2 { + + public static void set(float[] v, int pos, float x, float y) { + v[(pos << 1) + 0] = x; + v[(pos << 1) + 1] = y; + } + + public static float dot(float[] a, int apos, float[] b, int bpos) { + return a[apos << 1] * b[bpos << 1] + a[(apos << 1) + 1] * b[(bpos << 1) + 1]; + } + + public final static float lengthSquared(float[] v, int pos) { + float x = v[(pos << 1) + 0]; + float y = v[(pos << 1) + 1]; + + return x * x + y * y; + } + + public final static void normalizeSquared(float[] v, int pos) { + float x = v[(pos << 1) + 0]; + float y = v[(pos << 1) + 1]; + + float length = x * x + y * y; + + v[(pos << 1) + 0] = x / length; + v[(pos << 1) + 1] = y / length; + } + + public final static void normalize(float[] v, int pos) { + float x = v[(pos << 1) + 0]; + float y = v[(pos << 1) + 1]; + + double length = Math.sqrt(x * x + y * y); + + v[(pos << 1) + 0] = (float) (x / length); + v[(pos << 1) + 1] = (float) (y / length); + } + + public final static float length(float[] v, int pos) { + float x = v[(pos << 1) + 0]; + float y = v[(pos << 1) + 1]; + + return (float) Math.sqrt(x * x + y * y); + } + + public final static void add(float[] result, int rpos, float[] a, int apos, float[] b, + int bpos) { + result[(rpos << 1) + 0] = a[(apos << 1) + 0] + b[(bpos << 1) + 0]; + result[(rpos << 1) + 1] = a[(apos << 1) + 1] + b[(bpos << 1) + 1]; + } + + public final static void sub(float[] result, int rpos, float[] a, int apos, float[] b, + int bpos) { + result[(rpos << 1) + 0] = a[(apos << 1) + 0] - b[(bpos << 1) + 0]; + result[(rpos << 1) + 1] = a[(apos << 1) + 1] - b[(bpos << 1) + 1]; + } + + public final static void mul(float[] v, int pos, float a) { + v[(pos << 1) + 0] *= a; + v[(pos << 1) + 1] *= a; + } + } + // Corners of the box, where 0 is the lower left. public final float[] corner = new float[4 * 2]; diff --git a/vtm/src/org/oscim/utils/Vec2.java b/vtm/src/org/oscim/utils/Vec2.java deleted file mode 100644 index a127fbb6..00000000 --- a/vtm/src/org/oscim/utils/Vec2.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2012, 2013 Hannes Janetzek - * - * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). - * - * This program is free software: you can redistribute it and/or modify it under the - * terms of the GNU Lesser General Public License as published by the Free Software - * Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A - * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License along with - * this program. If not, see . - */ - -package org.oscim.utils; - -public final class Vec2 { - - public static void set(float[] v, int pos, float x, float y) { - v[(pos << 1) + 0] = x; - v[(pos << 1) + 1] = y; - } - - public static float dot(float[] a, int apos, float[] b, int bpos) { - return a[apos << 1] * b[bpos << 1] + a[(apos << 1) + 1] * b[(bpos << 1) + 1]; - } - - public final static float lengthSquared(float[] v, int pos) { - float x = v[(pos << 1) + 0]; - float y = v[(pos << 1) + 1]; - - return x * x + y * y; - } - - public final static void normalizeSquared(float[] v, int pos) { - float x = v[(pos << 1) + 0]; - float y = v[(pos << 1) + 1]; - - float length = x * x + y * y; - - v[(pos << 1) + 0] = x / length; - v[(pos << 1) + 1] = y / length; - } - - public final static void normalize(float[] v, int pos) { - float x = v[(pos << 1) + 0]; - float y = v[(pos << 1) + 1]; - - double length = Math.sqrt(x * x + y * y); - - v[(pos << 1) + 0] = (float) (x / length); - v[(pos << 1) + 1] = (float) (y / length); - } - - public final static float length(float[] v, int pos) { - float x = v[(pos << 1) + 0]; - float y = v[(pos << 1) + 1]; - - return (float) Math.sqrt(x * x + y * y); - } - - public final static void add(float[] result, int rpos, float[] a, int apos, float[] b, int bpos) { - result[(rpos << 1) + 0] = a[(apos << 1) + 0] + b[(bpos << 1) + 0]; - result[(rpos << 1) + 1] = a[(apos << 1) + 1] + b[(bpos << 1) + 1]; - } - - public final static void sub(float[] result, int rpos, float[] a, int apos, float[] b, int bpos) { - result[(rpos << 1) + 0] = a[(apos << 1) + 0] - b[(bpos << 1) + 0]; - result[(rpos << 1) + 1] = a[(apos << 1) + 1] - b[(bpos << 1) + 1]; - } - - public final static void mul(float[] v, int pos, float a) { - v[(pos << 1) + 0] *= a; - v[(pos << 1) + 1] *= a; - } - -}