static gboolean curvature_set_selection(GwyDataField *dfield, const Intersection *i1, const Intersection *i2, GwySelection *selection) { gdouble xreal, yreal; gdouble xy[4]; gint xres, yres; guint i; xreal = gwy_data_field_get_xreal(dfield); yreal = gwy_data_field_get_yreal(dfield); xres = gwy_data_field_get_xres(dfield); yres = gwy_data_field_get_yres(dfield); for (i = 0; i < 2; i++) { xy[0] = CLAMP(i1[i].x, 0, xreal*(xres - 1)/xres); xy[1] = CLAMP(i1[i].y, 0, yreal*(yres - 1)/yres); xy[2] = CLAMP(i2[i].x, 0, xreal*(xres - 1)/xres); xy[3] = CLAMP(i2[i].y, 0, yreal*(yres - 1)/yres); gwy_selection_set_object(selection, i, xy); } return TRUE; }
static GwySelection* gwyfile_gather_old_rect_selection(GwyContainer *data) { GwySelection *sel; GType type; gboolean selected; gdouble xy[4]; type = g_type_from_name("GwySelectionRectangle"); if (!type || !gwy_container_gis_boolean_by_name(data, "/0/select/rect/selected", &selected) || !selected) return NULL; if (!gwy_container_gis_double_by_name(data, "/0/select/rect/x0", &xy[0]) || !gwy_container_gis_double_by_name(data, "/0/select/rect/y0", &xy[1]) || !gwy_container_gis_double_by_name(data, "/0/select/rect/x1", &xy[2]) || !gwy_container_gis_double_by_name(data, "/0/select/rect/y1", &xy[3])) return NULL; sel = GWY_SELECTION(g_object_new(type, "max-objects", 1, NULL)); gwy_selection_set_object(sel, 0, xy); return sel; }
static GwySelection* gwyfile_gather_old_line_selection(GwyContainer *data) { GwySelection *sel; GType type; gint i, nselected; gdouble xy[4]; gchar key[40]; type = g_type_from_name("GwySelectionLine"); if (!type || !gwy_container_gis_int32_by_name(data, "/0/select/lines/nselected", &nselected)) return NULL; nselected = CLAMP(nselected, 0, 16); if (!nselected) return NULL; sel = GWY_SELECTION(g_object_new(type, "max-objects", nselected, NULL)); for (i = 0; i < nselected; i++) { g_snprintf(key, sizeof(key), "/0/select/lines/%d/x0", i); if (!gwy_container_gis_double_by_name(data, key, &xy[0])) break; g_snprintf(key, sizeof(key), "/0/select/lines/%d/y0", i); if (!gwy_container_gis_double_by_name(data, key, &xy[1])) break; g_snprintf(key, sizeof(key), "/0/select/lines/%d/x1", i); if (!gwy_container_gis_double_by_name(data, key, &xy[2])) break; g_snprintf(key, sizeof(key), "/0/select/lines/%d/y1", i); if (!gwy_container_gis_double_by_name(data, key, &xy[3])) break; gwy_selection_set_object(sel, i, xy); } if (!i) gwy_object_unref(sel); return sel; }
static void facet_view_select_angle(FacetsControls *controls, gdouble theta, gdouble phi) { gdouble x, y, q, xy[2]; GwyVectorLayer *layer; GwySelection *selection; const gchar *key; angles_to_xy(theta, phi, &x, &y); controls->in_update = TRUE; q = gwy_container_get_double_by_name(controls->fdata, "/q"); xy[0] = x + G_SQRT2/q; xy[1] = y + G_SQRT2/q; layer = gwy_data_view_get_top_layer(GWY_DATA_VIEW(controls->fview)); key = gwy_vector_layer_get_selection_key(layer); selection = gwy_container_get_object_by_name(controls->fdata, key); gwy_selection_set_object(selection, 0, xy); controls->in_update = FALSE; }