Skip to content

Commit

Permalink
Merge pull request #653 from Gustl22/sun_utils
Browse files Browse the repository at this point in the history
Utils for sun calculations
  • Loading branch information
devemux86 authored Feb 10, 2019
2 parents a449ea9 + 24ce5bf commit 7647850
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
35 changes: 35 additions & 0 deletions vtm/src/org/oscim/utils/ColorUtil.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/
package org.oscim.utils;

import org.oscim.backend.canvas.Color;
Expand Down Expand Up @@ -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))
);
}
}
20 changes: 19 additions & 1 deletion vtm/src/org/oscim/utils/geom/GeometryUtils.java
Original file line number Diff line number Diff line change
@@ -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).
*
Expand Down Expand Up @@ -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)
*
Expand Down

0 comments on commit 7647850

Please sign in to comment.