@Override public final boolean isFacing(Vector vector) { vector = vector.copy(); vector.subtract(vectors.get(0)); return normal.getDotProduct(vector) >= 0.0D; }
public void testIterator() throws Exception { Iterator<Vector.Element> iterator = test.iterateNonZero(); checkIterator(iterator, gold); iterator = test.iterator(); checkIterator(iterator, gold); double[] doubles = {0.0, 5.0, 0, 3.0}; RandomAccessSparseVector zeros = new RandomAccessSparseVector(doubles.length); for (int i = 0; i < doubles.length; i++) { zeros.setQuick(i, doubles[i]); } iterator = zeros.iterateNonZero(); checkIterator(iterator, doubles); iterator = zeros.iterator(); checkIterator(iterator, doubles); doubles = new double[] {0.0, 0.0, 0, 0.0}; zeros = new RandomAccessSparseVector(doubles.length); for (int i = 0; i < doubles.length; i++) { zeros.setQuick(i, doubles[i]); } iterator = zeros.iterateNonZero(); checkIterator(iterator, doubles); iterator = zeros.iterator(); checkIterator(iterator, doubles); }
private void boundary(Particle particle) { Vector positionInBoundary = particle.getPosition().clone(); Vector velocityInBoundary = particle.getVelocity().clone(); /* der lantern renderer verändert die übergebenen winkel, somit muss ich hier schauen, dass auch die auslenkung wieder ausgleiche. */ if (positionInBoundary.x < -(BOUNDARY * 0.5f)) { positionInBoundary.x = -(BOUNDARY * 0.5f); velocityInBoundary.x *= -BUMP_DECELERATION; // reverse and damp } if (positionInBoundary.x > (BOUNDARY * 0.5f)) { positionInBoundary.x = (BOUNDARY * 0.5f); velocityInBoundary.x *= -BUMP_DECELERATION; // reverse and damp } if (positionInBoundary.y < -(BOUNDARY * 0.5f)) { positionInBoundary.y = -(BOUNDARY * 0.5f); velocityInBoundary.y *= -BUMP_DECELERATION; // reverse and damp } if (positionInBoundary.y > (BOUNDARY * 1.8)) { positionInBoundary.y = (BOUNDARY * 1.8f); velocityInBoundary.y *= -BUMP_DECELERATION; // reverse and damp } particle.setPosition(positionInBoundary); particle.setVelocity(velocityInBoundary); }
public void testSparseDoubleVectorInt() throws Exception { Vector val = new RandomAccessSparseVector(4); assertEquals("size", 4, val.size()); for (int i = 0; i < 4; i++) { assertEquals("get [" + i + ']', 0.0, val.get(i)); } }
public void testAssignDoubleArray() throws Exception { double[] array = new double[test.size()]; test.assign(array); for (int i = 0; i < values.length; i++) { assertEquals("value[" + i + ']', 0.0, test.getQuick(i)); } }
@Command( aliases = {"clipboard", "copy"}, usage = "", desc = "Choose the clipboard brush", help = "Chooses the clipboard brush.\n" + "The -a flag makes it not paste air.\n" + "Without the -p flag, the paste will appear centered at the target location. " + "With the flag, then the paste will appear relative to where you had " + "stood relative to the copied area when you copied it.") @CommandPermissions("worldedit.brush.clipboard") public void clipboardBrush( Player player, LocalSession session, EditSession editSession, @Switch('a') boolean ignoreAir, @Switch('p') boolean usingOrigin) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); Vector size = clipboard.getDimensions(); worldEdit.checkMaxBrushRadius(size.getBlockX()); worldEdit.checkMaxBrushRadius(size.getBlockY()); worldEdit.checkMaxBrushRadius(size.getBlockZ()); BrushTool tool = session.getBrushTool(player.getItemInHand()); tool.setBrush(new ClipboardBrush(holder, ignoreAir, usingOrigin), "worldedit.brush.clipboard"); player.print("Clipboard brush shape equipped."); }
@Test public void extendedConstructorTest_ComponentsMatchGivenComponents_IllegalYComponent() { Vector v = new Vector(5, Double.NaN); assertTrue(Util.fuzzyEquals(v._X(), 5)); assertFalse(Util.fuzzyEquals(v._Y(), 6)); assertTrue(Util.fuzzyEquals(v._Y(), 0)); }
/** * Returns the dot product of the two vectors. It's the user responsibility to make sure that each * vector has the same dimensions. */ public static double unCheckedDotProduct(Vector A, Vector B) { double result = 0; double[] dataA = A.getData(); double[] dataB = B.getData(); for (int i = 0; i < A.getLength(); i++) result += dataA[i] * dataB[i]; return result; }
public static void crossProduct3D(Vector A, Vector B, Vector C) { if (B.getData().equals(C.getData())) throw new IllegalArgumentException("Inner data structures are the same."); if (A.getLength() != 3 || B.getLength() != 3) throw new IllegalArgumentException("Vectors should both be 3D vectors"); unCheckedCrossPorduct3D(A, B, C); }
@Test public void testEquals() { assertTrue(!vector.equals(null)); assertTrue(vector.equals(vector)); assertTrue(vector.equals(vector2)); assertTrue(!vector.equals(vector3)); }
/** * Multiplies the matrix A with the vector B and stores the result in vector C, the inner data * arrays of C may NOT be the same as the one in B (So be careful when using vectors from methods * like {@link Vector.wrapAround()} or {@link Matrix.wrapAround()}). * * @throws IllegalArgumentException If the dimensions of A, B and C are illegal for a * matrix-vector multiplication. * @throws IllegalArgumentException If the inner data arrays of B and C are the same. */ public static void mult(Matrix A, Vector B, Vector C) { if (B.getData().equals(C.getData())) throw new IllegalArgumentException("Inner data structures are the same."); if (A.getnCols() != B.getLength() || A.getnRows() != C.getLength()) throw new IllegalArgumentException("Illegal matrix dimensions."); else unCheckedMult(A, B, C); }
/* сложение векторов поэлементно */ public void Add(Vector summandVector) { if (summandVector.GetSize() == this.GetSize()) { for (int i = 0; i < this.GetSize(); i++) { this.SetValue(i, this.GetValue(i) + summandVector.GetValue(i)); } } }
@Command( aliases = {"/hsphere"}, usage = "<block> <radius> [raised?] ", desc = "Generate a hollow sphere", min = 2, max = 3) @CommandPermissions({"worldedit.generation.sphere"}) @Logging(PLACEMENT) public static void hsphere( CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { Pattern block = we.getBlockPattern(player, args.getString(0)); double radius = Math.max(1, args.getDouble(1)); boolean raised = args.argsLength() > 2 ? (args.getString(2).equalsIgnoreCase("true") || args.getString(2).equalsIgnoreCase("yes")) : false; Vector pos = session.getPlacementPosition(player); if (raised) { pos = pos.add(0, radius, 0); } int affected = editSession.makeSphere(pos, block, radius, false); player.findFreePosition(); player.print(affected + " block(s) have been created."); }
private String transformationStr(Transformation trf) { NumberFormat fmt = FloatFormat.getInstance(); Matrix matrix = trf.matrix(); Vector vector = trf.vector(); return "matrix <" + fmt.format(matrix.get(Transformation.X, Transformation.X)) + "," + fmt.format(matrix.get(Transformation.Z, Transformation.X)) + "," + fmt.format(matrix.get(Transformation.Y, Transformation.X)) + "," + fmt.format(matrix.get(Transformation.X, Transformation.Z)) + "," + fmt.format(matrix.get(Transformation.Z, Transformation.Z)) + "," + fmt.format(matrix.get(Transformation.Y, Transformation.Z)) + "," + fmt.format(matrix.get(Transformation.X, Transformation.Y)) + "," + fmt.format(matrix.get(Transformation.Z, Transformation.Y)) + "," + fmt.format(matrix.get(Transformation.Y, Transformation.Y)) + "," + fmt.format(vector.getX()) + "," + fmt.format(vector.getZ()) + "," + fmt.format(vector.getY()) + ">"; }
public void testAddToPoint() { MapPoint point = new MapPoint(2637887.25, 6815777.50); Vector vector = new Vector(600, 800).setLength(1); MapPoint newPoint = vector.clone().multiply(0.1).addToPoint(point); assertEquals(2637887.31, newPoint.getX(), 0.001); assertEquals(6815777.58, newPoint.getY(), 0.001); }
@Override public <M extends Number> void sub(Vector<M> vector) { assert (vector.length() == n); for (Map.Entry<Integer, M> e : vector.entrySet()) { sub(e.getKey(), e.getValue().intValue()); } }
/** * Paste from the clipboard. * * @param editSession * @param newOrigin Position to paste it from * @param noAir True to not paste air * @throws MaxChangedBlocksException */ public void paste(EditSession editSession, Vector newOrigin, boolean noAir, boolean entities) throws MaxChangedBlocksException { place(editSession, newOrigin.add(offset), noAir); if (entities) { pasteEntities(newOrigin.add(offset)); } }
public Vector getSurfaceNormal(Coordinates c) { Vector s = immerseVector(c, ddu); Vector t = immerseVector(c, ddv); s.normalize(); t.normalize(); return s.crossProduct(t); }
public float getDistance(Vector vector) { return (float) Math.sqrt( Math.pow(vector.getX() - x, 2) + Math.pow(vector.getY() - y, 2) + Math.pow(vector.getZ() - z, 2)); }
public static Point intersectionPoint(Ray ray, Plane plane) { Vector rayToPlaneVector = vectorBetween(ray.point, plane.point); float scaleFactor = rayToPlaneVector.dotProduct(plane.normal) / ray.vector.dotProduct(plane.normal); Point intersectionPoint = ray.point.translate(ray.vector.scale(scaleFactor)); return intersectionPoint; }
public void testGetOver() { try { test.get(test.size()); fail("expected exception"); } catch (IndexException e) { } }
/** * Returns the winding number of this polygon, treated as closed. It will be > 0, if the corners * are in countercock sense, and < 0, if the corners are in clockwise sense. */ public int winding_number_after_closing() { Point[] corner_arr = corner_array(); if (corner_arr.length < 2) { return 0; } Vector first_side_vector = corner_arr[1].difference_by(corner_arr[0]); Vector prev_side_vector = first_side_vector; int corner_count = corner_arr.length; // Skip the last corner, if it is equal to the first corner. if (corner_arr[0].equals(corner_arr[corner_count - 1])) { --corner_count; } double angle_sum = 0; for (int i = 1; i <= corner_count; ++i) { Vector next_side_vector; if (i == corner_count - 1) { next_side_vector = corner_arr[0].difference_by(corner_arr[i]); } else if (i == corner_count) { next_side_vector = first_side_vector; } else { next_side_vector = corner_arr[i + 1].difference_by(corner_arr[i]); } angle_sum += prev_side_vector.angle_approx(next_side_vector); prev_side_vector = next_side_vector; } angle_sum /= 2.0 * Math.PI; if (Math.abs(angle_sum) < 0.5) { System.out.println("Polygon.winding_number_after_closing: winding number != 0 expected"); } return (int) Math.round(angle_sum); }
public void testTimesVectorCardinality() { try { test.times(new DenseVector(test.size() + 1)); fail("expected exception"); } catch (CardinalityException e) { } }
public Vector backProp(Vector error) { derivs = fcn.applyDerivative(outputs); errors = derivs.multiply(error); Vector blame = weights.transpose().multiply(errors); // take off the bias signal, the previous layer need not know return blame.slice(blame.dim() - 1); }
public void testAssignVector() throws Exception { Vector other = new DenseVector(test.size()); test.assign(other); for (int i = 0; i < values.length; i++) { assertEquals("value[" + i + ']', 0.0, test.getQuick(i)); } }
public void train() { for (int i = 0; i < weights.getM(); ++i) { for (int j = 0; j < weights.getN(); ++j) { weights.set(i, j, weights.get(i, j) + (learning * inputs.get(i) * errors.get(j))); } } }
public List<String> query(String query, Integer type) { Vector qfea = features.get(query); TreeMap<Double, String> score_id = new TreeMap<Double, String>( new Comparator<Double>() { public int compare(Double a, Double b) { return -a.compareTo(b); } }); Double score; for (String eid : type_entities.get(type)) { score = qfea.dot(features.get(eid)); score_id.put(score, eid); } List<String> rank = new ArrayList<String>(); for (String id : score_id.values()) { if (!query.equals(id)) rank.add(id); } return rank; }
/** * Adds a position to be used a source. * * @param pos * @return */ public void addSingleSourcePosition(Vector pos) { int x = pos.getBlockX(); int y = pos.getBlockY(); int z = pos.getBlockZ(); if (CraftBook.getBlockID(pos) == BlockType.CHEST) { ComplexBlock complexBlock = etc.getServer().getComplexBlock(x, y, z); if (complexBlock instanceof Chest) { Chest chest = (Chest) complexBlock; Item[] itemArray = chest.getContents(); boolean occupied = false; // Got to make sure that at least one slot is occupied for (int i = 0; itemArray.length > i; i++) { if (itemArray[i] != null) { // Found an item if (itemArray[i].getAmount() > 0) { occupied = true; break; } } } if (occupied) { chests.add(new ComparableComplexBlock<Chest>(pos.toBlockVector(), chest)); } } } }
@Override public void shift(Vector change) throws RegionOperationException { pos1 = pos1.add(change); pos2 = pos2.add(change); recalculate(); }
private void directory_to_directory( String source_base_name, String destination_base_name, String directory_name) throws IOException, InterruptedException { // E.g. // source_base_name: /foo/bar // destination_base_name: /x/y // directory_name: abc // // - Create /x/y/abc // - Copy /foo/bar/abc/* to /x/y/abc/* // Get source directory. String source_directory_name = Path.concatenate(source_base_name, directory_name); File source_directory = File.create(source_directory_name); Assertion.check(source_directory.isDirectory()); // Get destination directory, creating it if // necessary. String destination_directory_name = Path.concatenate(destination_base_name, directory_name); File destination_directory = File.create(destination_directory_name); destination_directory.mkdirs(); // Get files in source directory String[] source_file_names = source_directory.list(); Vector source_files = new Vector(); for (int i = 0; i < source_file_names.length; i++) source_files.addElement(File.create(source_directory_name, source_file_names[i])); // Copy to_directory(source_files, destination_directory); }