| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.ByteOrder; |
| | | |
| | | import org.apache.log4j.Logger; |
| | | |
| | | import com.vividsolutions.jts.geom.Envelope; |
| | | |
| | | /** |
| | |
| | | */ |
| | | public final class Utility |
| | | { |
| | | private static final Logger logger = Logger.getLogger(Utility.class); |
| | | |
| | | public static double converIntToDouble(int src) |
| | | { |
| | | |
| | | return (double) ((long) ((src * 6) / 1000.0 + 0.5)) / 1000.0; |
| | | } |
| | | |
| | |
| | | return newVal; |
| | | } |
| | | |
| | | public static double converUnitToCoord(double aValue) |
| | | { |
| | | double newVal; |
| | | |
| | | newVal = aValue / 1000.0; |
| | | newVal += 2147483.648; // 2147483.648 = 2 ^ 31 |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static int converCoordToUnit(double aValue) |
| | | { |
| | | double newVal = aValue; |
| | |
| | | converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY())); |
| | | } |
| | | |
| | | public static double convertDGNToIEEEDouble(short[] src) |
| | | public static long convertDGNToRAWIEEEDouble(byte[] org) |
| | | { |
| | | ByteBuffer buf = ByteBuffer.allocate(8); |
| | | buf.order(ByteOrder.LITTLE_ENDIAN); |
| | | buf.mark(); |
| | | buf.put(org[2]); |
| | | buf.put(org[3]); |
| | | buf.put(org[0]); |
| | | buf.put(org[1]); |
| | | buf.put(org[6]); |
| | | buf.put(org[7]); |
| | | buf.put(org[4]); |
| | | buf.put(org[5]); |
| | | buf.position(0); |
| | | |
| | | int[] tmp = new int[2]; |
| | | long des; |
| | | int sign; |
| | | |
| | | tmp[0] = buf.getInt(); |
| | | tmp[1] = buf.getInt(); |
| | | |
| | | int exponent; |
| | | int rndbits; |
| | | |
| | | if (src == null) |
| | | { |
| | | throw new RuntimeException("Source short array is null"); |
| | | } |
| | | |
| | | tmp[0] = ((src[0] << 16) & 0xffff0000) | (src[1] & 0x0000ffff); |
| | | tmp[1] = ((src[2] << 16) & 0xffff0000) | (src[3] & 0x0000ffff); |
| | | sign = (tmp[0] & 0x80000000); |
| | | int sign = (tmp[0] & 0x80000000); |
| | | exponent = (tmp[0] >>> 23) & 0x000000ff; |
| | | |
| | | if (exponent != 0) |
| | |
| | | exponent = exponent - 129 + 1023; |
| | | } |
| | | |
| | | rndbits = tmp[1] & 0x00000007; |
| | | int rndbits = tmp[1] & 0x00000007; |
| | | tmp[1] = tmp[1] >>> 3; |
| | | tmp[1] = (tmp[1] & 0x1fffffff) | (tmp[0] << 29); |
| | | |
| | |
| | | |
| | | tmp[0] = (tmp[0] >>> 3) & 0x000fffff; |
| | | tmp[0] = tmp[0] | (exponent << 20) | sign; |
| | | des = (((long) tmp[0] << 32)); |
| | | des = des | (long) tmp[1]; |
| | | |
| | | return Double.longBitsToDouble(des); |
| | | buf.position(0); |
| | | buf.order(ByteOrder.BIG_ENDIAN); |
| | | buf.putInt(tmp[0]); |
| | | buf.putInt(tmp[1]); |
| | | buf.position(0); |
| | | byte[] tmpRaw = new byte[8]; |
| | | buf.get(tmpRaw); |
| | | buf.position(0); |
| | | buf.order(ByteOrder.LITTLE_ENDIAN); |
| | | for (int i = tmpRaw.length; i > 0 ; i--) |
| | | { |
| | | buf.put(tmpRaw[i-1]); |
| | | } |
| | | buf.position(0); |
| | | long result = buf.getLong(); |
| | | return result; |
| | | } |
| | | |
| | | public static double convertDGNToIEEEDouble(byte[] src) |
| | | { |
| | | return Double.longBitsToDouble(convertDGNToRAWIEEEDouble(src)); |
| | | } |
| | | |
| | | public static short[] convertIEEEDoubleToDGN(double src) |