summaryrefslogtreecommitdiff
path: root/src/ext/plantuml/com/ctreber/acearth/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/ext/plantuml/com/ctreber/acearth/util')
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/Coordinate.java153
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/EdgeCrossing.java59
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/Point2D.java35
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/Point3D.java48
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/Polygon.java49
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/StringParser.java99
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/SunPositionCalculator.java260
-rw-r--r--src/ext/plantuml/com/ctreber/acearth/util/Toolkit.java135
8 files changed, 0 insertions, 838 deletions
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/Coordinate.java b/src/ext/plantuml/com/ctreber/acearth/util/Coordinate.java
deleted file mode 100644
index 76d16ae..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/Coordinate.java
+++ /dev/null
@@ -1,153 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * <p>
- * Latitude and longitude coordinate. Can be used as declination and right
- * ascension as well.
- *
- * <p>
- * &copy; 2002 Christian Treber, ct@ctreber.com
- *
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class Coordinate {
- /*
- * MeanObliquity gives the mean obliquity of the earth's axis at epoch
- * 1990.0 (computed as 23.440592 degrees according to the method given in
- * duffett-smith, section 27)
- */
- private static final double MEAN_OBLIQUITY = 23.440592 * Toolkit.TWOPI / 360;
-
- // Or DE
- private double fLat;
- // Or RA
- private double fLong;
-
- public Coordinate() {
- }
-
- /**
- * <p>
- * Construct a location specfied by two angles. Your choice if in degrees or
- * rads, but keep track!
- *
- * @param pLong
- * Longitude or RA
- * @param pLat
- * Latitude or DE
- */
- public Coordinate(double pLat, double pLong) {
- fLat = pLat;
- fLong = pLong;
- }
-
- public void renderAsXML(Writer writer) throws IOException {
- writer.write("<Coordinate>\n");
- writer.write(" <latitude>" + fLat + "</latitude>\n");
- writer.write(" <longitude>" + fLong + "</longitude>\n");
- writer.write("</Coordinate>\n");
- }
-
- public Point3D getPoint3D() {
- final double lLatRad = Toolkit.degsToRads(fLat);
- final double lLongRad = Toolkit.degsToRads(fLong);
-
- final double lX = Math.cos(lLatRad) * Math.sin(lLongRad);
- final double lY = Math.sin(lLatRad);
- final double lZ = Math.cos(lLatRad) * Math.cos(lLongRad);
-
- return new Point3D(lX, lY, lZ);
- }
-
- /**
- * <p>
- * Assumes coordinate is not in degrees but rads.
- *
- * @return
- */
- public Point3D getPoint3DRads() {
- final double lX = Math.cos(fLat) * Math.sin(fLong);
- final double lY = Math.sin(fLat);
- final double lZ = Math.cos(fLat) * Math.cos(fLong);
-
- return new Point3D(lX, lY, lZ);
- }
-
- /**
- * <p>
- * Convert from ecliptic to equatorial coordinates (after duffett-smith,
- * section 27)
- */
- public Coordinate eclipticToEquatorial() {
- final double sin_e = Math.sin(MEAN_OBLIQUITY);
- final double cos_e = Math.cos(MEAN_OBLIQUITY);
-
- final double lRA = Math.atan2(Math.sin(fLong) * cos_e - Math.tan(fLat) * sin_e, Math.cos(fLong));
- final double lDE = Math.asin(Math.sin(fLat) * cos_e + Math.cos(fLat) * sin_e * Math.sin(fLong));
-
- return new Coordinate(lDE, lRA);
- }
-
- /**
- * <p>
- * Add position to this position, make sure coordinates are valid.
- */
- public void add(Coordinate lOther) {
- fLat += lOther.fLat;
- fLong += lOther.fLong;
- wrap();
- }
-
- /**
- * <p>
- * Warp coordinates exceeding valid values. Happens when latitudes and
- * longitudes are added or substracted.
- */
- public void wrap() {
- if (fLat > 90) {
- fLat = 180 - fLat;
- fLong += 180;
- } else if (fLat < -90) {
- fLat = -180 - fLat;
- fLong += 180;
- }
-
- if (fLong > 180) {
- do {
- fLong -= 360;
- } while (fLong > 180);
- } else if (fLong < -180) {
- do {
- fLong += 360;
- } while (fLong < -180);
- }
- }
-
- public double getLat() {
- return fLat;
- }
-
- public double getDE() {
- return fLat;
- }
-
- public double getLong() {
- return fLong;
- }
-
- public double getRA() {
- return fLong;
- }
-
- public boolean check() {
- return (-90 <= fLat) && (fLat <= 90) && (-180 <= fLong) && (fLong <= 180);
- }
-
- public String toString() {
- return "lat: " + fLat + ", long: " + fLong;
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/EdgeCrossing.java b/src/ext/plantuml/com/ctreber/acearth/util/EdgeCrossing.java
deleted file mode 100644
index adc3e23..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/EdgeCrossing.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-/**
- * <p>Holds information about a line crossing "the edge of Earth".
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class EdgeCrossing
-{
- public static final int XingTypeEntry = 0;
- public static final int XingTypeExit = 1;
-
- private int fType;
- private int fIndex;
- private double fX;
- private double fY;
- private double fAngle;
-
- public EdgeCrossing(int pType, int pIndex, double pX, double pY, double pAngle)
- {
- fType = pType;
- fX = pX;
- fY = pY;
- fAngle = pAngle;
- fIndex = pIndex;
- }
-
- public String toString()
- {
- return fType + ": " + fX + ", " + fY + ", " + fAngle + " (" + fIndex + ")";
- }
-
- public int getType()
- {
- return fType;
- }
-
- public double getX()
- {
- return fX;
- }
-
- public double getY()
- {
- return fY;
- }
-
- public double getAngle()
- {
- return fAngle;
- }
-
- public int getIndex()
- {
- return fIndex;
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/Point2D.java b/src/ext/plantuml/com/ctreber/acearth/util/Point2D.java
deleted file mode 100644
index 596f2b4..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/Point2D.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-/**
- * <p>A point in a 2 axis space.
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class Point2D
-{
- private double fX;
- private double fY;
-
- public Point2D(double pX, double pY)
- {
- fX = pX;
- fY = pY;
- }
-
- public double getX()
- {
- return fX;
- }
-
- public double getY()
- {
- return fY;
- }
-
- public String toString()
- {
- return "x: " + fX + ", y: " + fY;
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/Point3D.java b/src/ext/plantuml/com/ctreber/acearth/util/Point3D.java
deleted file mode 100644
index 3d38bdc..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/Point3D.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-/**
- * <p>A point in a 2 axis space.
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class Point3D
-{
- private double fX;
- private double fY;
- private double fZ;
-
- public Point3D(double pX, double pY, double pZ)
- {
- fX = pX;
- fY = pY;
- fZ = pZ;
- }
-
- public double getX()
- {
- return fX;
- }
-
- public double getY()
- {
- return fY;
- }
-
- public double getZ()
- {
- return fZ;
- }
-
- public String toString()
- {
- return "x: " + fX + ", y: " + fY + ", z: " + fZ;
- }
-
- public Coordinate getCoordinate()
- {
- return new Coordinate(Toolkit.radsToDegs(Math.asin(fY)),
- Toolkit.radsToDegs(Math.atan2(fX, fZ)));
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/Polygon.java b/src/ext/plantuml/com/ctreber/acearth/util/Polygon.java
deleted file mode 100644
index 9ea5f71..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/Polygon.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-
-/**
- * <p>A polygon in a 3 axis space.
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class Polygon
-{
- public static final int LAND = 1;
- public static final int WATER = -1;
-
- private int fType;
- private Point3D[] fPoints;
-
- public Polygon(int pType, Point3D[] pPoints)
- {
- fType = pType;
- fPoints = pPoints;
- }
-
- public int getType()
- {
- return fType;
- }
-
- public Point3D[] getPoints()
- {
- return fPoints;
- }
-
- public Point3D getPoint(int pIndex)
- {
- return fPoints[pIndex];
- }
-
- public int getSize()
- {
- return fPoints.length;
- }
-
- public String toString()
- {
- return "Type " + fType + ", " + fPoints.length + " points";
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/StringParser.java b/src/ext/plantuml/com/ctreber/acearth/util/StringParser.java
deleted file mode 100644
index 3ba3b1c..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/StringParser.java
+++ /dev/null
@@ -1,99 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * <p>Cuts a string in words separated by white space. Quotes and square
- * brackets are recognized (that is, white space within is ignored).
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class StringParser
-{
- public static List parse(String pLine)
- {
- final List lSections = new ArrayList();
-
- // True if within word.
- boolean lInSectionP = false;
- // Current char
- char lChar;
- // Wait for this character before switching back to normal parsing.
- char lSeparator = ' ';
- // Part count.
- int lSectionNo = 0;
- // Part start position
- int lSectionStart = 0;
- // Part end position
- int lSectionEnd = 0;
-
- final int lLen = pLine.length();
- for(int lCharNo = 0; lCharNo <= lLen; lCharNo++)
- {
- if(lCharNo < lLen)
- {
- lChar = pLine.charAt(lCharNo);
- } else
- {
- // This is a fictional last character.
- lChar = ' ';
- }
-
- if(lInSectionP)
- {
- // In section. Termination is by space or specific separator.
- if((lChar != ' ') || (lSeparator != ' '))
- {
- // It's not a space, or it is a space, but we wait for a special separator.
- if(lChar == lSeparator)
- {
- // We waited for this separator. Switch back to normal parsing.
- lSeparator = ' ';
- lSectionEnd = lCharNo - 1;
- } else
- {
- lSectionEnd = lCharNo;
- }
- } else
- {
- // Section has ended (with a space).
- lSections.add(pLine.substring(lSectionStart, lSectionEnd + 1));
- lSectionNo++;
- lInSectionP = false;
- }
- } else
- {
- // Not in a section, skipping white space.
- if(lChar != ' ')
- {
- // No white space: a section has started.
- if(lChar == '"')
- {
- // Special parsing "string"
- lSeparator = '"';
- lSectionStart = lCharNo + 1;
- } else if(lChar == '[')
- {
- // Special parsing "square brackets"
- lSeparator = ']';
- lSectionStart = lCharNo + 1;
- } else
- {
- // Use normal parsing.
- lSeparator = ' ';
- lSectionEnd = lSectionStart = lCharNo;
- }
- lInSectionP = true;
- } else
- {
- // More void...
- }
- }
- }
-
- return lSections;
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/SunPositionCalculator.java b/src/ext/plantuml/com/ctreber/acearth/util/SunPositionCalculator.java
deleted file mode 100644
index 736a2c3..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/SunPositionCalculator.java
+++ /dev/null
@@ -1,260 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-
-/**
- * <p>Calculates the position of the point on Earth which is directly
- * below the sun or the moon.
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class SunPositionCalculator
-{
- /*
- * the epoch upon which these astronomical calculations are based is
- * 1990 january 0.0, 631065600 seconds since the beginning of the
- * "unix epoch" (00:00:00 GMT, Jan. 1, 1970)
- *
- * given a number of seconds since the start of the unix epoch,
- * daysSinceEpoch() computes the number of days since the start of the
- * astronomical epoch (1990 january 0.0)
- */
-
- private static final long EPOCH_START = 631065600000l;
-
- /*
- * assuming the apparent orbit of the sun about the earth is circular,
- * the rate at which the orbit progresses is given by RadsPerDay --
- * TWOPI radians per orbit divided by 365.242191 days per year:
- */
-
- private static final double RADS_PER_DAY = Toolkit.TWOPI / 365.242191;
-
- /*
- * details of sun's apparent orbit at epoch 1990.0 (after
- * duffett-smith, table 6, section 46)
- *
- * Epsilon_g (ecliptic longitude at epoch 1990.0) 279.403303 degrees
- * OmegaBar_g (ecliptic longitude of perigee) 282.768422 degrees
- * Eccentricity (eccentricity of orbit) 0.016713
- */
-
- private static final double EPSILON_G = Toolkit.degsToRads(279.403303);
- private static final double OMEGA_BAR_G = Toolkit.degsToRads(282.768422);
- private static final double ECCENTRICITY = 0.016713;
-
- /*
- * Lunar parameters, epoch January 0, 1990.0
- */
- private static final double MOON_MEAN_LONGITUDE = Toolkit.degsToRads(318.351648);
- private static final double MOON_MEAN_LONGITUDE_PERIGEE = Toolkit.degsToRads(36.340410);
- private static final double MOON_MEAN_LONGITUDE_NODE = Toolkit.degsToRads(318.510107);
- private static final double MOON_INCLINATION = Toolkit.degsToRads(5.145396);
-
- private static final double SIDERAL_MONTH = 27.3217;
-
- /**
- * <p>Calculate the position of the mean sun: where the sun would
- * be if the earth's orbit were circular instead of ellipictal.
- *
- * <p>Verified.
- *
- * @param pDays days since ephemeris epoch
- */
- private static double getMeanSunLongitude(double pDays)
- {
- double N, M;
-
- N = RADS_PER_DAY * pDays;
- N = Toolkit.fmod(N, 0, Toolkit.TWOPI);
- if(N < 0)
- {
- N += Toolkit.TWOPI;
- }
-
- M = N + EPSILON_G - OMEGA_BAR_G;
- if(M < 0)
- {
- M += Toolkit.TWOPI;
- }
-
- return M;
- }
-
- /**
- * <p>Compute ecliptic longitude of sun (in radians)
- * (after duffett-smith, section 47)
- *
- * <p>Verified.
- *
- * @param pMillis Milliseconds since unix epoch
- */
- private static double getSunEclipticLongitude(long pMillis)
- {
- final double lDays = daysSinceEpoch(pMillis);
- final double M_sun = getMeanSunLongitude(lDays);
-
- final double E = doKepler(M_sun);
- final double v = 2 * Math.atan(Math.sqrt((1 + ECCENTRICITY) / (1 - ECCENTRICITY)) * Math.tan(E / 2));
-
- return (v + OMEGA_BAR_G);
- }
-
- static double daysSinceEpoch(long pMillis)
- {
- return (double)(pMillis - EPOCH_START) / 24 / 3600 / 1000;
- }
-
- /**
- * solve Kepler's equation via Newton's method
- * (after duffett-smith, section 47)
- *
- * <p>Verified.
- */
- private static double doKepler(double M)
- {
- double E;
- double lDelta;
-
- E = M;
- while(true)
- {
- lDelta = E - ECCENTRICITY * Math.sin(E) - M;
- if(Math.abs(lDelta) <= 1e-10)
- {
- break;
- }
- E -= lDelta / (1 - ECCENTRICITY * Math.cos(E));
- }
-
- return E;
- }
-
-
- /**
- * <p>computing julian dates (assuming gregorian calendar, thus this is
- * only valid for dates of 1582 oct 15 or later)
- * (after duffett-smith, section 4)
- *
- * <p>Verified.
- *
- * @param pYear year (e.g. 19xx)
- * @param pMonth month (jan=1, feb=2, ...)
- * @param pDay day of month
- */
- private static double getJulianDate(int pYear, int pMonth, int pDay)
- {
- if((pMonth == 1) || (pMonth == 2))
- {
- pYear -= 1;
- pMonth += 12;
- }
-
- final int A = pYear / 100;
- final int B = 2 - A + (A / 4);
- final int C = (int)(365.25 * pYear);
- final int D = (int)(30.6001 * (pMonth + 1));
-
- return B + C + D + pDay + 1720994.5;
- }
-
-
- /**
- * <p>compute greenwich mean sidereal time (getGST) corresponding to a given
- * number of milliseconds since the unix epoch
- * (after duffett-smith, section 12)
- *
- * <p>Verified.
- */
- private static double getGST(long pMillis)
- {
- final Calendar lCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
- lCal.setTime(new Date(pMillis));
-
- final double lJulianDate = getJulianDate(lCal.get(Calendar.YEAR), lCal.get(Calendar.MONTH) + 1,
- lCal.get(Calendar.DAY_OF_MONTH));
- final double T = (lJulianDate - 2451545) / 36525;
- double T0 = ((T + 2.5862e-5) * T + 2400.051336) * T + 6.697374558;
-
- T0 = Toolkit.fmod(T0, 0, 24.0);
- if(T0 < 0)
- {
- T0 += 24;
- }
-
- final double UT = lCal.get(Calendar.HOUR_OF_DAY) +
- (lCal.get(Calendar.MINUTE) + lCal.get(Calendar.SECOND) / 60.0) / 60.0;
-
- T0 += UT * 1.002737909;
- T0 = Toolkit.fmod(T0, 0, 24.0);
- if(T0 < 0)
- {
- T0 += 24;
- }
-
- return T0;
- }
-
- /**
- * <p>Given a particular time (expressed in milliseconds since the unix
- * epoch), compute position on the earth (lat, lon) such that sun is
- * directly overhead.
- *
- * <p>Verified.
- *
- * @param pMillis seconds since unix epoch
- *
- */
- public static Coordinate getSunPositionOnEarth(long pMillis)
- {
- final Coordinate lSunPosEc = new Coordinate(0.0, getSunEclipticLongitude(pMillis));
- final Coordinate lSunPosEq = lSunPosEc.eclipticToEquatorial();
-
- final double lRA = Toolkit.limitRads(lSunPosEq.getRA() - (Toolkit.TWOPI / 24) * getGST(pMillis));
-
- return new Coordinate(Toolkit.radsToDegs(lSunPosEq.getDE()), Toolkit.radsToDegs(lRA));
- }
-
- /**
- * <p>Given a particular time (expressed in milliseconds since the unix
- * epoch), compute position on the earth (lat, lon) such that the
- * moon is directly overhead.
- *
- * Based on duffett-smith **2nd ed** section 61; combines some steps
- * into single expressions to reduce the number of extra variables.
- *
- * <p>Verified.
- */
- public static Coordinate getMoonPositionOnEarth(long pMillis)
- {
- final double lDays = daysSinceEpoch(pMillis);
- double lSunLongEc = getSunEclipticLongitude(pMillis);
- final double Ms = getMeanSunLongitude(lDays);
-
- double L = Toolkit.limitRads(Toolkit.fmod(lDays / SIDERAL_MONTH, 0, 1.0) * Toolkit.TWOPI + MOON_MEAN_LONGITUDE);
- double Mm = Toolkit.limitRads(L - Toolkit.degsToRads(0.1114041 * lDays) - MOON_MEAN_LONGITUDE_PERIGEE);
- double N = Toolkit.limitRads(MOON_MEAN_LONGITUDE_NODE - Toolkit.degsToRads(0.0529539 * lDays));
- final double Ev = Toolkit.degsToRads(1.2739) * Math.sin(2.0 * (L - lSunLongEc) - Mm);
- final double Ae = Toolkit.degsToRads(0.1858) * Math.sin(Ms);
- Mm += Ev - Ae - Toolkit.degsToRads(0.37) * Math.sin(Ms);
- final double Ec = Toolkit.degsToRads(6.2886) * Math.sin(Mm);
- L += Ev + Ec - Ae + Toolkit.degsToRads(0.214) * Math.sin(2.0 * Mm);
- L += Toolkit.degsToRads(0.6583) * Math.sin(2.0 * (L - lSunLongEc));
- N -= Toolkit.degsToRads(0.16) * Math.sin(Ms);
-
- L -= N;
- lSunLongEc = Toolkit.limitRads((Math.abs(Math.cos(L)) < 1e-12) ?
- (N + Math.sin(L) * Math.cos(MOON_INCLINATION) * Math.PI / 2) :
- (N + Math.atan2(Math.sin(L) * Math.cos(MOON_INCLINATION), Math.cos(L))));
- final double lSunLatEc = Math.asin(Math.sin(L) * Math.sin(MOON_INCLINATION));
-
- final Coordinate lSunPosEq = new Coordinate(lSunLatEc, lSunLongEc).eclipticToEquatorial();
- final double lRA = Toolkit.limitRads(lSunPosEq.getRA() - (Toolkit.TWOPI / 24) * getGST(pMillis));
-
- return new Coordinate(Toolkit.radsToDegs(lSunPosEq.getDE()), Toolkit.radsToDegs(lRA));
- }
-}
diff --git a/src/ext/plantuml/com/ctreber/acearth/util/Toolkit.java b/src/ext/plantuml/com/ctreber/acearth/util/Toolkit.java
deleted file mode 100644
index 12f3655..0000000
--- a/src/ext/plantuml/com/ctreber/acearth/util/Toolkit.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package ext.plantuml.com.ctreber.acearth.util;
-
-import java.util.HashSet;
-import java.util.StringTokenizer;
-
-/**
- * <p>Some tools.
- *
- * <p>&copy; 2002 Christian Treber, ct@ctreber.com
- * @author Christian Treber, ct@ctreber.com
- *
- */
-public class Toolkit
-{
- public static final double TWOPI = Math.PI * 2;
- public static final double PI = Math.PI;
- public static final double HALFPI = Math.PI / 2;
- private static final HashSet fsNoCap;
-
- static
- {
- fsNoCap = new HashSet();
- fsNoCap.add("a");
- fsNoCap.add("as");
- fsNoCap.add("to");
- fsNoCap.add("of");
- fsNoCap.add("the");
- fsNoCap.add("off");
- fsNoCap.add("and");
- fsNoCap.add("mid");
- }
-
- public static double degsToRads(double pDegrees)
- {
- return pDegrees * TWOPI / 360;
- }
-
- public static double radsToDegs(double pRadians)
- {
- return pRadians * 360 / TWOPI;
- }
-
- /**
- * Force an angular value into the range [-PI, +PI]
- */
- public static double limitRads(double x)
- {
- return fmod(x, -Math.PI, Math.PI);
- }
-
- /**
- * <p>Verified.
- */
- public static double fmod(double pValue, double pMod)
- {
- while(pValue < 0)
- {
- pValue += pMod;
- }
- while(pValue > pMod)
- {
- pValue -= pMod;
- }
-
- return pValue;
- }
-
- /**
- * <p>Examples: min -2, max 2: range 4
- *
- * <ul>
- * <li> value 1: lFact = 0
- * <li> value 3: lFact = 1, value -1
- * <li> value 9: lFact = 2, value 1
- * <li> value -3: lFact = -1, value 1
- * </ul>
- */
- public static double fmod(double pValue, double pMinValue, double pMaxValue)
- {
- final double lRange = pMaxValue - pMinValue;
- int lFact = (int)((pValue - pMinValue) / lRange);
- if(pValue < pMinValue)
- {
- lFact--;
- }
-
- return pValue - lFact * lRange;
- }
-
- /**
- * <p>Capitalize String. Uppercase words smaller/equal than 3 chars,
- * lowercase defined exceptions. Capitalize within word after '.' and '-'.
- * Capitalize all others.
- */
- public static String intelligentCapitalize(String pText)
- {
- boolean lDoCap = false;
- final StringTokenizer lST = new StringTokenizer(pText, ".- ", true);
- final StringBuffer lSB = new StringBuffer(50);
- while(lST.hasMoreTokens())
- {
- String lWord = lST.nextToken();
-
- if(lWord.equals(".") || lWord.equals("-"))
- {
- lDoCap = true;
- lSB.append(lWord);
- continue;
- }
- if(lWord.equals(" "))
- {
- lDoCap = false;
- lSB.append(lWord);
- continue;
- }
-
- if(lDoCap || (lWord.length() > 3))
- {
- lSB.append(Character.toUpperCase(lWord.charAt(0)));
- lSB.append(lWord.substring(1).toLowerCase());
- } else
- {
- if(fsNoCap.contains(lWord.toLowerCase()))
- {
- lSB.append(lWord.toLowerCase());
- } else
- {
- lSB.append(lWord.toUpperCase());
- }
- }
- }
-
- return lSB.toString();
- }
-}