📄 hirescoord.java
字号:
*/ public void getHiResCoordZ(int[] Z) { Z[0] = this.z[0]; Z[1] = this.z[1]; Z[2] = this.z[2]; Z[3] = this.z[3]; Z[4] = this.z[4]; Z[5] = this.z[5]; Z[6] = this.z[6]; Z[7] = this.z[7]; } /** * Compares the specified HiResCoord to this HiResCoord. * @param h1 the second HiResCoord * @return true if equal, false if not equal */ public boolean equals(HiResCoord h1) { try { return ((this.x[0] == h1.x[0]) && (this.x[1] == h1.x[1]) && (this.x[2] == h1.x[2]) && (this.x[3] == h1.x[3]) && (this.x[4] == h1.x[4]) && (this.x[5] == h1.x[5]) && (this.x[6] == h1.x[6]) && (this.x[7] == h1.x[7]) && (this.y[0] == h1.y[0]) && (this.y[1] == h1.y[1]) && (this.y[2] == h1.y[2]) && (this.y[3] == h1.y[3]) && (this.y[4] == h1.y[4]) && (this.y[5] == h1.y[5]) && (this.y[6] == h1.y[6]) && (this.y[7] == h1.y[7]) && (this.z[0] == h1.z[0]) && (this.z[1] == h1.z[1]) && (this.z[2] == h1.z[2]) && (this.z[3] == h1.z[3]) && (this.z[4] == h1.z[4]) && (this.z[5] == h1.z[5]) && (this.z[6] == h1.z[6]) && (this.z[7] == h1.z[7])); } catch (NullPointerException e2) {return false;} } /** * Returns true if the Object o1 is of type HiResCoord and all of the * data members of o1 are equal to the corresponding data members in * this HiResCoord. * @param o1 the second HiResCoord * @return true if equal, false if not equal */ public boolean equals(Object o1) { try { HiResCoord h1 = (HiResCoord)o1; return ((this.x[0] == h1.x[0]) && (this.x[1] == h1.x[1]) && (this.x[2] == h1.x[2]) && (this.x[3] == h1.x[3]) && (this.x[4] == h1.x[4]) && (this.x[5] == h1.x[5]) && (this.x[6] == h1.x[6]) && (this.x[7] == h1.x[7]) && (this.y[0] == h1.y[0]) && (this.y[1] == h1.y[1]) && (this.y[2] == h1.y[2]) && (this.y[3] == h1.y[3]) && (this.y[4] == h1.y[4]) && (this.y[5] == h1.y[5]) && (this.y[6] == h1.y[6]) && (this.y[7] == h1.y[7]) && (this.z[0] == h1.z[0]) && (this.z[1] == h1.z[1]) && (this.z[2] == h1.z[2]) && (this.z[3] == h1.z[3]) && (this.z[4] == h1.z[4]) && (this.z[5] == h1.z[5]) && (this.z[6] == h1.z[6]) && (this.z[7] == h1.z[7])); } catch (NullPointerException e2) {return false;} catch (ClassCastException e1) {return false;} } /** * Adds two HiResCoords placing the results into this HiResCoord. * @param h1 the first HiResCoord * @param h2 the second HiResCoord */ public void add(HiResCoord h1, HiResCoord h2) { // needs to handle carry bits // move to long, add, add in carry bit hiResAdd( this, h1, h2 ); } /** * Subtracts two HiResCoords placing the results into this HiResCoord. * @param h1 the first HiResCoord * @param h2 the second HiResCoord */ public void sub(HiResCoord h1, HiResCoord h2) { HiResCoord tmpHc = new HiResCoord(); // negate via two's complement then add // hiResNegate( tmpHc, h2); hiResAdd( this, h1, tmpHc); } /** * Negates the specified HiResCoords and places the * results into this HiResCoord. * @param h1 the source HiResCoord */ public void negate(HiResCoord h1) { hiResNegate( this, h1); } /** * Negates this HiResCoord */ public void negate() { hiResNegate( this, this ); } /** * Scales the specified HiResCoords by the specified value and * places the results into this HiResCoord. * @param scale the amount to scale the specified HiResCoord * @param h1 the source HiResCoord */ public void scale(int scale, HiResCoord h1) { hiResScale( h1.x, this.x, scale); hiResScale( h1.y, this.y, scale); hiResScale( h1.z, this.z, scale); } /** * Scales this HiResCoord by the specified value. * @param scale the amount to scale the specified HiResCoord */ public void scale(int scale) { hiResScale( this.x, this.x, scale); hiResScale( this.y, this.y, scale); hiResScale( this.z, this.z, scale); return; } /** * Subtracts the specified HiResCoord from this HiResCoord * placing the difference vector into the specified * double-precision vector. * @param h1 the HiResCoord to be subtracted from this * @param v the vector that will receive the result */ public void difference(HiResCoord h1, Vector3d v) { // negate coord via two compliment, add, convert result to double // by scaling each bit set appropriately hiResDiff( this, h1, v); return; } /** * The floating point distance between the specified * HiResCoord and this HiResCoord. * @param h1 the second HiResCoord */ public double distance(HiResCoord h1) { Vector3d diff = new Vector3d(); hiResDiff( this, h1, diff); return( Math.sqrt( diff.x*diff.x + diff.y*diff.y + diff.z*diff.z)); } private void hiResNegate( HiResCoord ho, HiResCoord hi) { negateCoord( ho.x, hi.x); negateCoord( ho.y, hi.y); negateCoord( ho.z, hi.z); return; } private void negateCoord( int cout[], int cin[] ) { int i; for(i=0;i<8;i++) { cout[i] = ~cin[i]; // take compliment of each } for(i=7;i>=0;i--) { // add one if( cout[i] == 0xffffffff) { cout[i] = 0; } else { cout[i] += 1; break; } } return; } private void hiResAdd(HiResCoord ho, HiResCoord h1, HiResCoord h2 ){ int i; long tmp1, tmp2,carry; long signMask = Integer.MAX_VALUE; long signBit = 1; signBit = signBit << 31; long carryMask = 0x7fffffff; carryMask = carryMask <<1; carryMask += 1; carry = 0; for(i=7;i>0;i--) { tmp1 = 0; tmp1 = signMask & h1.x[i]; // mask off sign bit so will not get put in msb if( h1.x[i] < 0 ) tmp1 |= signBit; // add sign bit back tmp2 = 0; tmp2 = signMask & h2.x[i]; // mask off sign bit so will not get put in msb if( h2.x[i] < 0 ) tmp2 |= signBit; // add sign bit back tmp2 = tmp2+tmp1 + carry; carry = tmp2 >> 32; // get carry bits for next operation ho.x[i] = (int)(tmp2 & carryMask); // mask off high bits } ho.x[0] = h1.x[0] + h2.x[0] + (int)carry; carry = 0; for(i=7;i>0;i--) { tmp1 = 0; tmp1 = signMask & h1.y[i]; // mask off sign bit so will not get put in msb if( h1.y[i] < 0 ) tmp1 |= signBit; // add sign bit back tmp2 = 0; tmp2 = signMask & h2.y[i]; // mask off sign bit so will not get put in msb if( h2.y[i] < 0 ) tmp2 |= signBit; // add sign bit back tmp2 = tmp2+tmp1 + carry; carry = tmp2 >> 32; // get carry bits for next operation ho.y[i] = (int)(tmp2 & carryMask); // mask off high bits } ho.y[0] = h1.y[0] + h2.y[0] + (int)carry; carry = 0; for(i=7;i>0;i--) { tmp1 = 0; tmp1 = signMask & h1.z[i]; // mask off sign bit so will not get put in msb if( h1.z[i] < 0 ) tmp1 |= signBit; // add sign bit back tmp2 = 0; tmp2 = signMask & h2.z[i]; // mask off sign bit so will not get put in msb if( h2.z[i] < 0 ) tmp2 |= signBit; // add sign bit back tmp2 = tmp2+tmp1 + carry; carry = tmp2 >> 32; // get carry bits for next operation ho.z[i] = (int)(tmp2 & carryMask); // mask off high bits } ho.z[0] = h1.z[0] + h2.z[0] + (int)carry; return; } private void hiResScale( int tin[], int tout[], double scale) { int i; long tmp,carry; int signMask = Integer.MAX_VALUE; long carryMask = 0x7fffffff; carryMask = carryMask <<1; carryMask += 1; long signBit = 1; signBit = signBit << 31; carry = 0; for(i=7;i>0;i--) { tmp = 0; tmp = (long)(signMask & tin[i]); // mask off sign bit if( tin[i] < 0 ) tmp |= signBit; // add sign bit back tmp = (long)(tmp*scale + carry); carry = tmp >> 32; // get carry bits for next operation tout[i] = (int)(tmp & carryMask); // mask off high bits } tout[0] = (int)(tin[0]*scale + carry); return; } private void hiResDiff( HiResCoord h1, HiResCoord h2, Vector3d diff) { int i; HiResCoord diffHi = new HiResCoord(); long value; int coordSpace[] = new int[8]; int[] tempCoord; int signMask = Integer.MAX_VALUE; long signBit = 1; signBit = signBit << 31; // negate via two's complement then add // hiResNegate( diffHi, h2); hiResAdd( diffHi, h1, diffHi); if( diffHi.x[0] < 0 ) { tempCoord = coordSpace; negateCoord( tempCoord, diffHi.x ); } else { tempCoord = diffHi.x; } diff.x = 0; for(i=7;i>0;i--) { value = (long)(tempCoord[i] & signMask); if( tempCoord[i] < 0) value |= signBit; diff.x += (double)(scales[i]*value); } diff.x += scales[0]*tempCoord[0]; if( diffHi.x[0] < 0 )diff.x = -diff.x; if( diffHi.y[0] < 0 ) { tempCoord = coordSpace; negateCoord( tempCoord, diffHi.y ); } else { tempCoord = diffHi.y; } diff.y = 0; for(i=7;i>0;i--) { value = (long)(tempCoord[i] & signMask); if( tempCoord[i] < 0) value |= signBit; diff.y += scales[i]*value; } diff.y += scales[0]*tempCoord[0]; if( diffHi.y[0] < 0 )diff.y = -diff.y; if( diffHi.z[0] < 0 ) { tempCoord = coordSpace; negateCoord( tempCoord, diffHi.z ); } else { tempCoord = diffHi.z; } diff.z = 0; for(i=7;i>0;i--) { value = (long)(tempCoord[i] & signMask); if( tempCoord[i] < 0) value |= signBit; diff.z += scales[i]*value; } diff.z += scales[0]*tempCoord[0]; if( diffHi.z[0] < 0 )diff.z = -diff.z; return; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -