forked from geodmms/xdgnjobs

Dennis Kao
2014-01-15 94ae08701bbd7585a0b7e5a92d1975965a503c03
xdgnjobs/ximple-dgnio/src/main/java/com/ximple/util/DgnUtility.java
@@ -12,25 +12,21 @@
 *
 * @author Ulysses
 * @version 0.1
 * @since 2006/5/18 ¤U¤È 01:33:00
 * @since 2006/5/18
 */
public final class DgnUtility
{
public final class DgnUtility {
    private static final Logger logger = Logger.getLogger(DgnUtility.class);
    public static double converIntToDouble(int src)
    {
    public static double converIntToDouble(int src) {
        return (double) ((long) ((src * 6) / 1000.0 + 0.5)) / 1000.0;
    }
    public static int converDoubleToInt(double src)
    {
    public static int converDoubleToInt(double src) {
        return (int) (src / 6 * 1000000.0);
    }
    public static int convertFromDGN(int aValue)
    {
    public static int convertFromDGN(int aValue) {
        int newVal;
        newVal = (((aValue ^ 0x00008000) << 16) & 0xffff0000);
@@ -39,8 +35,7 @@
        return newVal;
    }
    public static int converToDGN(int aValue)
    {
    public static int converToDGN(int aValue) {
        int newVal;
        newVal = (aValue << 16 & 0xffff0000);
@@ -49,26 +44,22 @@
        return newVal;
    }
    public static double converIntToRotation(int aValue)
    {
    public static double converIntToRotation(int aValue) {
        return aValue / 360000.0;
    }
    public static int converRotatioToInt(double aValue)
    {
    public static int converRotatioToInt(double aValue) {
        return (int) (aValue * 360000.0);
    }
    public static double converRotationToRadian(double aValue)
    {
    public static double converRotationToRadian(double aValue) {
        return aValue * Math.PI / 180;
    }
    public static double converUnitToCoord(int aValue)
    {
    public static double converUnitToCoord(int aValue) {
        double newVal;
        newVal = aValue / 1000.0;
@@ -77,8 +68,7 @@
        return newVal;
    }
    public static double converUnitToCoord(double aValue)
    {
    public static double converUnitToCoord(double aValue) {
        double newVal;
        newVal = aValue / 1000.0;
@@ -87,8 +77,7 @@
        return newVal;
    }
    public static int converCoordToUnit(double aValue)
    {
    public static int converCoordToUnit(double aValue) {
        double newVal = aValue;
        newVal -= 2147483.648;
@@ -97,30 +86,25 @@
        return (int) newVal;
    }
    public static Envelope converUnitToCoord(Envelope range)
    {
        if (range == null)
        {
    public static Envelope converUnitToCoord(Envelope range) {
        if (range == null) {
            return null;
        }
        return new Envelope(converUnitToCoord((int) range.getMinX()), converUnitToCoord((int) range.getMaxX()),
                converUnitToCoord((int) range.getMinY()), converUnitToCoord((int) range.getMaxY()));
                            converUnitToCoord((int) range.getMinY()), converUnitToCoord((int) range.getMaxY()));
    }
    public static Envelope converCoordToUnit(Envelope range)
    {
        if (range == null)
        {
    public static Envelope converCoordToUnit(Envelope range) {
        if (range == null) {
            return null;
        }
        return new Envelope(converCoordToUnit(range.getMinX()), converCoordToUnit(range.getMaxX()),
                converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY()));
                            converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY()));
    }
    public static long convertDGNToRAWIEEEDouble(byte[] org)
    {
    public static long convertDGNToRAWIEEEDouble(byte[] org) {
        ByteBuffer buf = ByteBuffer.allocate(8);
        buf.order(ByteOrder.LITTLE_ENDIAN);
        buf.mark();
@@ -144,8 +128,7 @@
        int sign = (tmp[0] & 0x80000000);
        exponent = (tmp[0] >>> 23) & 0x000000ff;
        if (exponent != 0)
        {
        if (exponent != 0) {
            exponent = exponent - 129 + 1023;
        }
@@ -153,8 +136,7 @@
        tmp[1] = tmp[1] >>> 3;
        tmp[1] = (tmp[1] & 0x1fffffff) | (tmp[0] << 29);
        if (rndbits != 0)
        {
        if (rndbits != 0) {
            tmp[1] = tmp[1] | 0x00000001;
        }
@@ -170,8 +152,7 @@
        buf.get(tmpRaw);
        buf.position(0);
        buf.order(ByteOrder.LITTLE_ENDIAN);
        for (int i = tmpRaw.length; i > 0; i--)
        {
        for (int i = tmpRaw.length; i > 0; i--) {
            buf.put(tmpRaw[i - 1]);
        }
        buf.position(0);
@@ -179,13 +160,11 @@
        return result;
    }
    public static double convertDGNToIEEEDouble(byte[] src)
    {
    public static double convertDGNToIEEEDouble(byte[] src) {
        return Double.longBitsToDouble(convertDGNToRAWIEEEDouble(src));
    }
    public static short[] convertIEEEDoubleToDGN(double src)
    {
    public static short[] convertIEEEDoubleToDGN(double src) {
        long newVal = Double.doubleToLongBits(src);
        // uint[]   tmp = new int[ 2 ];
@@ -202,18 +181,14 @@
        sign = tmp[0] & 0x80000000;
        exponent = (tmp[0] >>> 20) & 0x07ff;
        if (exponent != 0)
        {
        if (exponent != 0) {
            exponent = exponent - 1023 + 129;
        }
        if (exponent > 255)
        {
            if (sign != 0)
            {
        if (exponent > 255) {
            if (sign != 0) {
                des[0] = -1;
            } else
            {
            } else {
                des[0] = 0x7fff;
            }
@@ -222,16 +197,14 @@
            des[3] = -1;
            return des;
        } else if ((exponent < 0) || ((exponent == 0) && (sign == 0)))
        {
        } else if ((exponent < 0) || ((exponent == 0) && (sign == 0))) {
            des[0] = 0x0;
            des[1] = 0x0;
            des[2] = 0x0;
            des[3] = 0x0;
            return des;
        } else
        {
        } else {
            tmp[0] = (tmp[0] << 3) | (tmp[1] >> 29);
            tmp[0] = tmp[0] & 0x007fffff;
            tmp[0] = tmp[0] | (exponent << 23) | sign;
@@ -249,8 +222,7 @@
        return des;
    }
    public static double getLength(double x1, double y1, double x2, double y2)
    {
    public static double getLength(double x1, double y1, double x2, double y2) {
        double dx = x1 - x2;
        double dy = y1 - y2;