diff --git a/vtm/src/org/oscim/utils/ColorUtil.java b/vtm/src/org/oscim/utils/ColorUtil.java index b3f4e05b1..fe4a4687d 100644 --- a/vtm/src/org/oscim/utils/ColorUtil.java +++ b/vtm/src/org/oscim/utils/ColorUtil.java @@ -1,3 +1,20 @@ +/* + * Copyright 2014 Hannes Janetzek + * Copyright 2019 Gustl22 + * + * 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; import org.oscim.backend.canvas.Color; @@ -261,4 +278,22 @@ public static int hsvToRgb(double h, double s, double v) { public static int hslToRgb(double h, double s, double l) { return hslToRgb(h, s, l, null); } + + /** + * Blend two colors. + * + * @param color1 the first color + * @param color2 the second color + * @param mix the mixing proportion in range 0 to 1 + * @return the blended color + */ + public static int blend(int color1, int color2, float mix) { + float mix2 = 1f - mix; + return Color.get( + (int) ((((color2 >>> 24) & 0xff) * mix) + (((color1 >>> 24) & 0xff) * mix2)), + (int) ((((color2 >>> 16) & 0xff) * mix) + (((color1 >>> 16) & 0xff) * mix2)), + (int) ((((color2 >>> 8) & 0xff) * mix) + (((color1 >>> 8) & 0xff) * mix2)), + (int) ((((color2 >>> 0) & 0xff) * mix) + (((color1 >>> 0) & 0xff) * mix2)) + ); + } } diff --git a/vtm/src/org/oscim/utils/geom/GeometryUtils.java b/vtm/src/org/oscim/utils/geom/GeometryUtils.java index 0eeb7d376..1156eae0d 100644 --- a/vtm/src/org/oscim/utils/geom/GeometryUtils.java +++ b/vtm/src/org/oscim/utils/geom/GeometryUtils.java @@ -1,6 +1,6 @@ /* * Copyright 2012, 2013 Hannes Janetzek - * Copyright 2018 Gustl22 + * Copyright 2018-2019 Gustl22 * * This file is part of the OpenScienceMap project (http://www.opensciencemap.org). * @@ -280,6 +280,24 @@ public static float isTrisClockwise(float[] pA, float[] pB, float[] pC) { return (pB[0] - pA[0]) * (pC[1] - pA[1]) - (pB[1] - pA[1]) * (pC[0] - pA[0]); } + /** + * @return the length of the vector + */ + public static double length(float[] vec) { + float length = 0f; + for (float coord : vec) { + length += coord * coord; + } + return Math.sqrt(length); + } + + /** + * @return the normalized vector (with length 1) + */ + public static float[] normalize(float[] vec) { + return scale(vec, 1f / (float) length(vec)); + } + /** * Calculate the normalized direction vectors of point list (polygon) *