Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils for sun calculations #653

Merged
merged 2 commits into from
Feb 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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