static gboolean set_shapes(GwyCoordsView *view, GwyShapes *shapes) { CoordsView *priv = view->priv; if (!gwy_set_member_object(view, shapes, GWY_TYPE_SHAPES, &priv->shapes, "notify", shapes_notify, &priv->shapes_notify_id, G_CONNECT_SWAPPED, NULL)) return FALSE; set_coords(view, shapes ? gwy_shapes_get_coords(shapes) : NULL); gwy_set_member_object(view, shapes ? shapes->selection : NULL, GWY_TYPE_INT_SET, &priv->shapes_selection, "added", shapes_selection_added, &priv->shapes_selection_added_id, G_CONNECT_SWAPPED, "removed", shapes_selection_removed, &priv->shapes_selection_removed_id, G_CONNECT_SWAPPED, "assigned", shapes_selection_assigned, &priv->shapes_selection_assigned_id, G_CONNECT_SWAPPED, NULL); sync_selection_shapes_to_view(view); return TRUE; }
static void gwy_coords_view_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GwyCoordsView *view = GWY_COORDS_VIEW(object); switch (prop_id) { case PROP_COORDS: set_shapes(view, NULL); set_coords(view, g_value_get_object(value)); break; case PROP_SHAPES: set_shapes(view, g_value_get_object(value)); break; case PROP_SCALE_TYPE: set_scale_type(view, g_value_get_enum(value)); break; case PROP_SPLIT_UNITS: set_split_units(view, g_value_get_boolean(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
Ion::Ion(WaterSystem * sys, double * tmp_coords, double tmp_charge) : DISPLACEMENT_DISTANCE(sys->DISPLACEMENT_DISTANCE), BOX_LENGTH(sys->BOX_LENGTH), BOX_Z_LENGTH(sys->BOX_Z_LENGTH) { charge = tmp_charge; old_coords = new double [3]; coords = new double [3]; set_coords(tmp_coords); }
/** * gwy_coords_view_set_coords: * @view: A coords view. * @coords: (allow-none) (transfer full): * Coordinates to display. * * Sets the coordinates that a coords view displays. **/ void gwy_coords_view_set_coords(GwyCoordsView *view, GwyCoords *coords) { g_return_if_fail(GWY_IS_COORDS_VIEW(view)); set_shapes(view, NULL); if (!set_coords(view, coords)) return; g_object_notify_by_pspec(G_OBJECT(view), properties[PROP_COORDS]); }
static void gwy_coords_view_dispose(GObject *object) { GwyCoordsView *view = GWY_COORDS_VIEW(object); CoordsView *priv = view->priv; if (priv->shapes) set_shapes(view, NULL); else set_coords(view, NULL); G_OBJECT_CLASS(gwy_coords_view_parent_class)->dispose(object); }
static void shapes_notify(GwyCoordsView *view, GParamSpec *pspec, GwyShapes *shapes) { CoordsView *priv = view->priv; if (gwy_strequal(pspec->name, "coords")) set_coords(view, gwy_shapes_get_coords(shapes)); else if (gwy_strequal(pspec->name, "editable")) priv->editable = gwy_shapes_get_editable(shapes); else if (gwy_strequal(pspec->name, "selectable")) { GtkTreeView *treeview = GTK_TREE_VIEW(view); GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); if (gwy_shapes_get_selectable(shapes)) { gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); sync_selection_shapes_to_view(view); } else { clear_selection(view); gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); } } }
/*! Create vertex from input coordinates \param[in] id is the id of the vertex \param[in] coords are the vertex coordinates */ Vertex::Vertex(const long &id, std::array<double, 3> &coords) { set_id(id); set_coords(coords); }
// Vertex translation functionality. void Vertex::translate(Vertex p) {set_coords(x=x+p.getx(), y=y+p.gety(), z=z+p.getz()); return;}
// Vertex scaling functionality. void Vertex::scale(float a) {set_coords(a*x, a*y, a*z); return;}
/*! * \brief Get the bounding box of a set of entities. */ void Octree::getEntSetBox( iBase_EntitySetHandle entity_set, Box &bounding_box ) { int error = 0; int num_set_vertices = 0; iMesh_getNumOfTopo( d_mesh, entity_set, iMesh_POINT, &num_set_vertices, &error ); assert( iBase_SUCCESS == error ); iBase_EntityHandle *set_vertices = 0; int set_vertices_allocated = 0; int set_vertices_size = 0; iMesh_getEntities( d_mesh, entity_set, iBase_VERTEX, iMesh_POINT, &set_vertices, &set_vertices_allocated, &set_vertices_size, &error ); assert( iBase_SUCCESS == error ); int set_coords_allocated = 3*set_vertices_size; int set_coords_size = 0; double *coords = 0; iMesh_getVtxArrCoords( d_mesh, set_vertices, set_vertices_size, iBase_BLOCKED, &coords, &set_coords_allocated, &set_coords_size, &error ); assert( iBase_SUCCESS == error ); Teuchos::ArrayView<double> set_coords( coords, set_coords_size ); Teuchos::ArrayView<double>::const_iterator set_x_it_begin = set_coords.begin(); Teuchos::ArrayView<double>::const_iterator set_x_it_end = set_x_it_begin + set_vertices_size; Teuchos::ArrayView<double>::const_iterator set_y_it_begin = set_x_it_end; Teuchos::ArrayView<double>::const_iterator set_y_it_end = set_y_it_begin + set_vertices_size; Teuchos::ArrayView<double>::const_iterator set_z_it_begin = set_y_it_end; Teuchos::ArrayView<double>::const_iterator set_z_it_end = set_z_it_begin + set_vertices_size; bounding_box[0] = *(std::min_element( set_x_it_begin, set_x_it_end )); bounding_box[1] = *(std::max_element( set_x_it_begin, set_x_it_end )); bounding_box[2] = *(std::min_element( set_y_it_begin, set_y_it_end )); bounding_box[3] = *(std::max_element( set_y_it_begin, set_y_it_end )); bounding_box[4] = *(std::min_element( set_z_it_begin, set_z_it_end )); bounding_box[5] = *(std::max_element( set_z_it_begin, set_z_it_end )); free( set_vertices ); free( coords ); }
bool MapCorridor::create(GeoVector vec) { unsigned int numTries = 0; uniform_int_dist lenDist(minLength, maxLength); sf::Vector2i& startingCoords = vec.start_point; Direction& direction = vec.direction; while (numTries < maxRetries) { int corridorLen(lenDist(the_RNG)); int xMin, xMax, yMin, yMax; switch (direction) { case Direction::North: yMax = startingCoords.y - 1; yMin = yMax - (corridorLen - 1); xMin = startingCoords.x; xMax = startingCoords.x; pImpl->endingCoords.x = startingCoords.x; pImpl->endingCoords.y = yMin - 1; break; case Direction::South: yMin = startingCoords.y + 1; yMax = yMin + (corridorLen - 1); xMin = startingCoords.x; xMax = startingCoords.x; pImpl->endingCoords.x = startingCoords.x; pImpl->endingCoords.y = yMax + 1; break; case Direction::West: xMax = startingCoords.x - 1; xMin = xMax - (corridorLen - 1); yMin = startingCoords.y; yMax = startingCoords.y; pImpl->endingCoords.x = xMin - 1; pImpl->endingCoords.y = startingCoords.y; break; case Direction::East: xMin = startingCoords.x + 1; xMax = xMin + (corridorLen - 1); yMin = startingCoords.y; yMax = startingCoords.y; pImpl->endingCoords.x = xMax + 1; pImpl->endingCoords.y = startingCoords.y; break; default: MINOR_ERROR("Invalid Direction passed into createCorridor"); return false; } if ((get_map().is_in_bounds(xMin - 1, yMin - 1)) && (get_map().is_in_bounds(xMax + 1, yMax + 1))) { bool okay = true; // Verify that corridor and surrounding area are solid walls. for (int xCheck = xMin - 1; xCheck <= xMax + 1; ++xCheck) { for (int yCheck = yMin - 1; yCheck <= yMax + 1; ++yCheck) { auto& tile = get_map().get_tile(xCheck, yCheck); if (tile.is_empty_space()) { okay = false; break; } } if (okay == false) break; } if (okay) { // Clear out the box. for (int xCheck = xMin; xCheck <= xMax; ++xCheck) { for (int yCheck = yMin; yCheck <= yMax; ++yCheck) { auto& tile = get_map().get_tile(xCheck, yCheck); tile.set_type("FloorStone"); } } set_coords(sf::IntRect(xMin, yMin, (xMax - xMin) + 1, (yMax - yMin) + 1)); // Add the surrounding walls as potential connection points. // First the horizontal walls... for (int xCoord = xMin; xCoord <= xMax; ++xCoord) { add_growth_vector(GeoVector(xCoord, yMin - 1, Direction::North)); add_growth_vector(GeoVector(xCoord, yMax + 1, Direction::South)); } // Now the vertical walls. for (int yCoord = yMin; yCoord <= yMax; ++yCoord) { add_growth_vector(GeoVector(xMin - 1, yCoord, Direction::West)); add_growth_vector(GeoVector(xMax + 1, yCoord, Direction::East)); } /// @todo: Put either a door or an open area at the starting coords. /// Right now we just make it an open area. auto& startTile = get_map().get_tile(startingCoords.x, startingCoords.y); startTile.set_type("FloorStone"); /// Check the tile two past the ending tile. /// If it is open space, there should be a small chance /// (maybe 5%) that the corridor opens up into it. This /// will allow for some loops in the map instead of it being /// nothing but a tree. sf::Vector2i checkCoords; switch (direction) { case Direction::North: checkCoords.x = startingCoords.x; checkCoords.y = pImpl->endingCoords.y - 1; break; case Direction::South: checkCoords.x = startingCoords.x; checkCoords.y = pImpl->endingCoords.y + 1; break; case Direction::West: checkCoords.x = pImpl->endingCoords.x - 1; checkCoords.y = startingCoords.y; break; case Direction::East: checkCoords.x = pImpl->endingCoords.x + 1; checkCoords.y = startingCoords.y; break; default: // shouldn't happen at this point MINOR_ERROR("Invalid Direction passed into createCorridor"); return false; } if (get_map().is_in_bounds(checkCoords.x, checkCoords.y)) { auto& checkTile = get_map().get_tile(checkCoords.x, checkCoords.y); if (checkTile.is_empty_space()) { auto& endTile = get_map().get_tile(pImpl->endingCoords.x, pImpl->endingCoords.y); endTile.set_type("FloorStone"); /// @todo Keep going here } } return true; } } ++numTries; } return false; }