| | |
| | | package com.ximple.io.dgn7; |
| | | |
| | | //~--- non-JDK imports -------------------------------------------------------- |
| | | |
| | | import com.vividsolutions.jts.geom.Envelope; |
| | | |
| | | /** |
| | |
| | | */ |
| | | public final class Utility |
| | | { |
| | | public static double ConverIntToDouble(int src) |
| | | public static double converIntToDouble(int src) |
| | | { |
| | | double newVal = (double) ((long) ((src * 6) / 1000.0 + 0.5)) / 1000.0; // ?[0.5?O?¢X?F?|¡Ó????J |
| | | |
| | | return newVal; |
| | | return (double) ((long) ((src * 6) / 1000.0 + 0.5)) / 1000.0; |
| | | } |
| | | |
| | | public static int ConverDoubleToInt(double src) |
| | | public static int converDoubleToInt(double src) |
| | | { |
| | | int newVal = (int) (src / 6 * 1000000.0); |
| | | |
| | | return newVal; |
| | | return (int) (src / 6 * 1000000.0); |
| | | } |
| | | |
| | | public static int ConvertFromDGN(int aValue) |
| | | public static int convertFromDGN(int aValue) |
| | | { |
| | | int newVal = 0; |
| | | int newVal; |
| | | |
| | | newVal = (((aValue ^ 0x00008000) << 16) & 0xffff0000); |
| | | newVal += (aValue >>> 16) & 0x0000ffff; |
| | | newVal |= (aValue >>> 16) & 0x0000ffff; |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static int ConverToDGN(int aValue) |
| | | public static int converToDGN(int aValue) |
| | | { |
| | | int newVal = 0; |
| | | int newVal; |
| | | |
| | | newVal = (aValue << 16 & 0xffff0000); |
| | | newVal += (((aValue ^ 0x80000000) >>> 16) & 0x0000ffff); |
| | | newVal |= (((aValue ^ 0x80000000) >>> 16) & 0x0000ffff); |
| | | |
| | | return newVal; |
| | | } |
| | | |
| | | public static double ConverIntToRotation(int aValue) |
| | | public static double converIntToRotation(int aValue) |
| | | { |
| | | double newVal = aValue / 360000.0; |
| | | |
| | | if (newVal > 0) |
| | | { |
| | | newVal = (int) (newVal + 0.5); |
| | | } else |
| | | { |
| | | newVal = (int) (newVal - 0.5); |
| | | } |
| | | |
| | | return newVal; |
| | | return aValue / 360000.0; |
| | | } |
| | | |
| | | public static int ConverRotatioToInt(double aValue) |
| | | public static int converRotatioToInt(double aValue) |
| | | { |
| | | int newVal = (int) (aValue * 360000.0); |
| | | |
| | | return newVal; |
| | | return (int) (aValue * 360000.0); |
| | | } |
| | | |
| | | public static double ConverRotationToRadian(double aValue) |
| | | public static double converRotationToRadian(double aValue) |
| | | { |
| | | double newVal = aValue * Math.PI / 180; |
| | | |
| | | return newVal; |
| | | return aValue * Math.PI / 180; |
| | | } |
| | | |
| | | public static double ConverUnitToCoord(int aValue) |
| | | public static double converUnitToCoord(int aValue) |
| | | { |
| | | double newVal = 0; |
| | | double newVal; |
| | | |
| | | newVal = aValue / 1000.0; |
| | | newVal += 2147483.648; // 2147483.648 = 2 ^ 31 |
| | |
| | | return newVal; |
| | | } |
| | | |
| | | public static int ConverCoordToUnit(double aValue) |
| | | public static int converCoordToUnit(double aValue) |
| | | { |
| | | double newVal = aValue; |
| | | |
| | |
| | | return (int) newVal; |
| | | } |
| | | |
| | | public static Envelope ConverUnitToCoord(Envelope range) |
| | | public static Envelope converUnitToCoord(Envelope range) |
| | | { |
| | | if (range == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | Envelope newRange = new Envelope(ConverUnitToCoord((int) range.getMinX()), ConverUnitToCoord((int) range.getMaxX()), |
| | | ConverUnitToCoord((int) range.getMinY()), ConverUnitToCoord((int) range.getMaxY())); |
| | | |
| | | return newRange; |
| | | return new Envelope(converUnitToCoord((int) range.getMinX()), converUnitToCoord((int) range.getMaxX()), |
| | | converUnitToCoord((int) range.getMinY()), converUnitToCoord((int) range.getMaxY())); |
| | | } |
| | | |
| | | public static Envelope ConverCoordToUnit(Envelope range) |
| | | public static Envelope converCoordToUnit(Envelope range) |
| | | { |
| | | if (range == null) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | Envelope newRange = new Envelope(ConverCoordToUnit(range.getMinX()), ConverCoordToUnit(range.getMaxX()), |
| | | ConverCoordToUnit(range.getMinY()), ConverCoordToUnit(range.getMaxY())); |
| | | |
| | | return newRange; |
| | | return new Envelope(converCoordToUnit(range.getMinX()), converCoordToUnit(range.getMaxX()), |
| | | converCoordToUnit(range.getMinY()), converCoordToUnit(range.getMaxY())); |
| | | } |
| | | |
| | | public static double DGNToIEEEDouble(short[] src) |
| | | public static double convertDGNToIEEEDouble(short[] src) |
| | | { |
| | | int[] tmp = new int[2]; |
| | | long des = 0; |
| | | long des; |
| | | int sign; |
| | | int exponent; |
| | | int rndbits; |
| | |
| | | throw new RuntimeException("Source short array is null"); |
| | | } |
| | | |
| | | tmp[0] = (int) ((src[0] << 16) & 0xffff0000) | (src[1] & 0x0000ffff); // ¢X????? |
| | | tmp[1] = (int) ((src[2] << 16) & 0xffff0000) | (src[3] & 0x0000ffff); // ¡±C???? |
| | | sign = (int) (tmp[0] & 0x80000000); |
| | | tmp[0] = ((src[0] << 16) & 0xffff0000) | (src[1] & 0x0000ffff); |
| | | tmp[1] = ((src[2] << 16) & 0xffff0000) | (src[3] & 0x0000ffff); |
| | | sign = (tmp[0] & 0x80000000); |
| | | exponent = (tmp[0] >>> 23) & 0x000000ff; |
| | | |
| | | if (exponent != 0) |
| | |
| | | tmp[0] = (tmp[0] >>> 3) & 0x000fffff; |
| | | tmp[0] = tmp[0] | (exponent << 20) | sign; |
| | | des = (((long) tmp[0] << 32)); |
| | | des = des | (long) tmp[1] & 0x00000000ffffffff; |
| | | des = des | (long) tmp[1]; |
| | | |
| | | return Double.longBitsToDouble(des); |
| | | } |
| | | |
| | | public static short[] IEEEDoubleToDGN(double src) |
| | | public static short[] convertIEEEDoubleToDGN(double src) |
| | | { |
| | | long newVal = Double.doubleToLongBits(src); |
| | | |
| | |
| | | int sign; |
| | | int exponent; |
| | | |
| | | tmp[0] = (int) ((newVal >>> 32) & 0x0ffffffff); |
| | | tmp[1] = (int) (newVal & 0x0ffffffff); |
| | | tmp[0] = (int) ((newVal >>> 32)); |
| | | tmp[1] = (int) (newVal); |
| | | |
| | | // sign = ( int ) ( ( uint ) tmp[ 0 ] & 0x80000000 ); |
| | | sign = (int) tmp[0] & 0x80000000; |
| | | sign = tmp[0] & 0x80000000; |
| | | exponent = (tmp[0] >>> 20) & 0x07ff; |
| | | |
| | | if (exponent != 0) |
| | |
| | | { |
| | | double dx = x1 - x2; |
| | | double dy = y1 - y2; |
| | | double length = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); |
| | | |
| | | return length; |
| | | return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)); |
| | | } |
| | | } |