public static double[][] computeWeightMatrix(final int quanth, final int quants, final int quantb) {
    final int dim = quanth * quants * quantb;
    final DoubleWrapper tmp = new DoubleWrapper(); // To return cosine
    assert (dim > 0);
    final double[][] m = new double[dim][dim];
    for(int x = 0; x < dim; x++) {
      final int hx = x / (quantb * quants);
      final int sx = (x / quantb) % quants;
      final int bx = x % quantb;
      for(int y = x; y < dim; y++) {
        final int hy = y / (quantb * quants);
        final int sy = (y / quantb) % quants;
        final int by = y % quantb;

        final double shx = FastMath.sinAndCos((hx + .5) / quanth * MathUtil.TWOPI, tmp);
        final double chx = tmp.value;
        final double shy = FastMath.sinAndCos((hy + .5) / quanth * MathUtil.TWOPI, tmp);
        final double chy = tmp.value;
        final double cos = chx * (sx + .5) / quants - chy * (sy + .5) / quants;
        final double sin = shx * (sx + .5) / quants - shy * (sy + .5) / quants;
        final double db = (bx - by) / (double) quantb;
        final double val = 1. - FastMath.sqrt((db * db + sin * sin + cos * cos) / 5);
        m[x][y] = m[y][x] = val;
      }
    }
    return m;
  }
Similar code snippets
1.
lessthanoptimal/GeoRegression · Area2D_F64.java
Match rating: 64.65% · See similar code snippets
java logo
public static double quadrilateral( Quadrilateral_F64 quad ) {
		double bx = quad.b.x-quad.a.x;
		double by = quad.b.y-quad.a.y;
		double cx = quad.c.x-quad.a.x;
		double cy = quad.c.y-quad.a.y;
		double dx = quad.d.x-quad.a.x;
		double dy = quad.d.y-quad.a.y;

		if( (bx * cy - by * cx >= 0) == (cx * dy - cy * dx >= 0)) {
			return triangle(quad.a,quad.b,quad.c) + triangle(quad.a,quad.c,quad.d);
		} else {
			return triangle(quad.a,quad.b,quad.d) + triangle(quad.b,quad.c,quad.d);
		}
	}
2.
jcodec/jcodec · MPEG4Bitstream.java
Match rating: 62.58% · See similar code snippets
java logo
private static void dequantH263Intra(MPEG4DecodingContext ctx, short[] block, final int quant, final int dcscalar) {
        final int quantM2 = quant << 1;
        final int quantAdd = ((quant & 1) != 0 ? quant : quant - 1);

        block[0] = (short) MathUtil.clip(block[0] * dcscalar, -2048, 2047);

        for (int i = 1; i < 64; i++) {
            int acLevel = block[i];

            if (acLevel == 0) {
                block[i] = 0;
            } else if (acLevel < 0) {
                acLevel = quantM2 * -acLevel + quantAdd;
                block[i] = (short) (acLevel <= 2048 ? -acLevel : -2048);
            } else {
                acLevel = quantM2 * acLevel + quantAdd;
                block[i] = (short) (acLevel <= 2047 ? acLevel : 2047);
            }
        }
    }
3.
lessthanoptimal/BoofCV · VisualizeShapes.java
Match rating: 61.58% · See similar code snippets
java logo
public static void drawQuad( Quadrilateral_F64 quad , Graphics2D g2 , boolean subpixel  ) {
		if( subpixel ) {
			Line2D.Double line = new Line2D.Double();

			line.setLine(quad.a.x,quad.a.y,quad.b.x,quad.b.y);  g2.draw(line);
			line.setLine(quad.b.x,quad.b.y,quad.c.x,quad.c.y);  g2.draw(line);
			line.setLine(quad.c.x,quad.c.y,quad.d.x,quad.d.y);  g2.draw(line);
			line.setLine(quad.d.x,quad.d.y,quad.a.x,quad.a.y);  g2.draw(line);
		} else {
			g2.drawLine((int) (quad.a.x + 0.5), (int) (quad.a.y + 0.5), (int) (quad.b.x + 0.5), (int) (quad.b.y + 0.5));
			g2.drawLine((int) (quad.b.x + 0.5), (int) (quad.b.y + 0.5), (int) (quad.c.x + 0.5), (int) (quad.c.y + 0.5));
			g2.drawLine((int) (quad.c.x + 0.5), (int) (quad.c.y + 0.5), (int) (quad.d.x + 0.5), (int) (quad.d.y + 0.5));
			g2.drawLine((int) (quad.d.x + 0.5), (int) (quad.d.y + 0.5), (int) (quad.a.x + 0.5), (int) (quad.a.y + 0.5));
		}
	}
4.
JOML-CI/JOML · Quaterniond.java
Match rating: 59.59% · See similar code snippets
java logo
public double dot(Quaterniondc otherQuat) {
        return this.x * otherQuat.x() + this.y * otherQuat.y() + this.z * otherQuat.z() + this.w * otherQuat.w();
    }
5.
JOML-CI/JOML · Quaternionf.java
Match rating: 58.77% · See similar code snippets
java logo
public float dot(Quaternionf otherQuat) {
        return this.x * otherQuat.x + this.y * otherQuat.y + this.z * otherQuat.z + this.w * otherQuat.w;
    }
6.
Esri/geometry-api-java · QuadTreeImpl.java
Match rating: 58.37% · See similar code snippets
java logo
Envelope2D getExtent(int quad_handle) {
		Envelope2D quad_extent = new Envelope2D();
		quad_extent.setCoords(m_extent);

		if (quad_handle == m_root)
			return quad_extent;

		AttributeStreamOfInt32 quadrants = new AttributeStreamOfInt32(0);

		int q = quad_handle;

		do {
			quadrants.add(get_quadrant_(q));
			q = get_parent_(q);

		} while (q != m_root);

		int sz = quadrants.size();
		assert (sz == getHeight(quad_handle));

		for (int i = 0; i < sz; i++) {
			int child = quadrants.getLast();
			quadrants.removeLast();

			if (child == 0) {//northeast
				quad_extent.xmin = 0.5 * (quad_extent.xmin + quad_extent.xmax);
				quad_extent.ymin = 0.5 * (quad_extent.ymin + quad_extent.ymax);
			} else if (child == 1) {//northwest
				quad_extent.xmax = 0.5 * (quad_extent.xmin + quad_extent.xmax);
				quad_extent.ymin = 0.5 * (quad_extent.ymin + quad_extent.ymax);
			} else if (child == 2) {//southwest
				quad_extent.xmax = 0.5 * (quad_extent.xmin + quad_extent.xmax);
				quad_extent.ymax = 0.5 * (quad_extent.ymin + quad_extent.ymax);
			} else {//southeast
				quad_extent.xmin = 0.5 * (quad_extent.xmin + quad_extent.xmax);
				quad_extent.ymax = 0.5 * (quad_extent.ymin + quad_extent.ymax);
			}
		}

		return quad_extent;
	}
7.
jcodec/jcodec · MPEG4Bitstream.java
Match rating: 58.32% · See similar code snippets
java logo
static void readInterBlockH263(BitReader br, short[] block, int direction, int quant) {
        final short[] scan = SCAN_TABLES[direction];
        final int quant_m_2 = quant << 1;
        final int quant_add = ((quant & 1) != 0 ? quant : quant - 1);
        int p = 0;

        p = 0;
        int coeff;
        do {
            coeff = readCoeffs(br, false, false);
            int level = level(coeff);
            p += run(coeff);
            if ((p & ~63) != 0) {
                Logger.error("invalid run or index");
                break;
            }

            if (level < 0) {
                level = level * quant_m_2 - quant_add;
                block[scan[p]] = (short) (level >= -2048 ? level : -2048);
            } else {
                level = level * quant_m_2 + quant_add;
                block[scan[p]] = (short) (level <= 2047 ? level : 2047);
            }
            p++;
        } while (last(coeff) == 0);
    }
8.
basho/riak-java-client · DescribeQueryResultParser.java
Match rating: 58.05% · See similar code snippets
java logo
private static Quantum parseQuantumCells(List<Cell> cells)
    {
        if (cells.size() < 7)
        {
            return null;
        }

        final Cell quantumIntervalCell = cells.get(QUANTUM_INTERVAL_IDX);
        final Cell quantumUnitCell = cells.get(QUANTUM_UNIT_IDX);

        final boolean hasQuantum = quantumIntervalCell != null && quantumUnitCell != null;

        if (!hasQuantum)
        {
            return null;
        }

        final Long quantumInterval = quantumIntervalCell.getLong();
        final TimeUnit quantumUnit = Quantum.parseTimeUnit(quantumUnitCell.getVarcharAsUTF8String());

        return new Quantum(quantumInterval.intValue(), quantumUnit);
    }
9.
jcodec/jcodec · GradGen.java
Match rating: 57.45% · See similar code snippets
java logo
private static byte colr(double i, double j, double from, double to, int quant) {
        int val = ((int) ((1 << quant) * (from + (to - from) * i))) << (8 - quant);
        return (byte) (MathUtil.clip(val, 0, 255) - 128);
    }
10.
gallandarakhneorg/afc · Quaternion.java
Match rating: 57.25% · See similar code snippets
java logo
public final void mulInverse(Quaternion q1) {  
		Quaternion  tempQuat = q1.clone();

		tempQuat.inverse();
		this.mul(tempQuat);
	}