/** * gwy_si_unit_divide: * @siunit1: An SI unit. * @siunit2: An SI unit. * @result: An SI unit to set to quotient of @siunit1 and @siunit2. It is * safe to pass one of @siunit1, @siunit2. It can be %NULL * too, a new SI unit is created then and returned. * * Divides two SI units. * * Returns: When @result is %NULL, a newly created SI unit that has to be * dereferenced when no longer used later. Otherwise @result itself * is simply returned, its reference count is NOT increased. **/ GwySIUnit* gwy_si_unit_divide(GwySIUnit *siunit1, GwySIUnit *siunit2, GwySIUnit *result) { return gwy_si_unit_power_multiply(siunit1, 1, siunit2, -1, result); }
static void set_up_quantity(GFilterControls *controls, GwyGrainValue *gvalue, guint id) { GFilterArgs *args = controls->args; GwyInventory *inventory; GwyDataField *dfield; RangeRecord *rr; const gchar *name; const gdouble *v; gchar *s, *t; gdouble vmin, vmax, lower = -G_MAXDOUBLE, upper = G_MAXDOUBLE; GwySIUnit *siunit, *siunitxy, *siunitz; gboolean was_in_init = controls->in_init; guint i, nuniq; controls->in_init = TRUE; name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); args->ranges[id].quantity = name; /* TRANSLATORS: %c is replaced with quantity label A, B or C. */ s = g_strdup_printf(_("Condition %c: %s"), 'A' + id, name); t = g_strconcat("<b>", s, "</b>", NULL); gtk_label_set_markup(GTK_LABEL(controls->header[id]), t); g_free(t); g_free(s); rr = g_hash_table_lookup(args->ranges_history, (gpointer)name); if (rr) { lower = rr->lower; upper = rr->upper; } inventory = gwy_grain_values(); i = gwy_inventory_get_item_position(inventory, name); nuniq = args->nuniqvalues[i]; v = g_ptr_array_index(args->sortedvaluedata, i); vmin = v[0]; vmax = v[nuniq-1]; lower = CLAMP(lower, vmin, vmax); upper = CLAMP(upper, vmin, vmax); gtk_adjustment_set_upper(GTK_ADJUSTMENT(controls->lower[id]), nuniq-1); gtk_adjustment_set_upper(GTK_ADJUSTMENT(controls->upper[id]), nuniq-1); dfield = gwy_container_get_object_by_name(controls->mydata, "/0/data"); siunitxy = gwy_data_field_get_si_unit_xy(dfield); siunitz = gwy_data_field_get_si_unit_z(dfield); siunit = gwy_si_unit_power_multiply(siunitxy, gwy_grain_value_get_power_xy(gvalue), siunitz, gwy_grain_value_get_power_z(gvalue), NULL); gwy_si_unit_get_format_with_digits(siunit, GWY_SI_UNIT_FORMAT_VFMARKUP, MAX(fabs(vmin), fabs(vmax)), 4, controls->vf[id]); g_object_unref(siunit); /* Special-case the pixel area format. */ if (gwy_strequal(name, "Pixel area")) { controls->vf[id]->magnitude = 1.0; controls->vf[id]->precision = 0; gwy_si_unit_value_format_set_units(controls->vf[id], ""); } gtk_label_set_markup(GTK_LABEL(controls->lower_units[id]), controls->vf[id]->units); gtk_label_set_markup(GTK_LABEL(controls->upper_units[id]), controls->vf[id]->units); args->ranges[id].quantity = name; args->ranges[id].lower = lower; args->ranges[id].upper = upper; set_adjustment_to_grain_value(controls, gvalue, GTK_ADJUSTMENT(controls->lower[id]), lower); set_adjustment_to_grain_value(controls, gvalue, GTK_ADJUSTMENT(controls->upper[id]), upper); s = g_strdup_printf("%.*f", controls->vf[id]->precision, lower/controls->vf[id]->magnitude); gtk_entry_set_text(GTK_ENTRY(controls->lower_entry[id]), s); g_free(s); s = g_strdup_printf("%.*f", controls->vf[id]->precision, upper/controls->vf[id]->magnitude); gtk_entry_set_text(GTK_ENTRY(controls->upper_entry[id]), s); g_free(s); /* XXX: We might have modified the range by CLAMP(). Store the new one * right here? Pro: consistency. Con: the user did not do anything, * he just may be browsing. */ controls->in_init = was_in_init; gfilter_invalidate(controls); }
static GwyGraphModel* create_corr_graph(GrainCrossArgs *args, GwyDataField *dfield) { GwyGraphCurveModel *cmodel; GwyGraphModel *gmodel; GwyGrainValue *gvalues[2]; gdouble *xdata, *ydata, *bothdata, *rdata[2]; GwySIUnit *siunitxy, *siunitz, *siunitx, *siunity; const gchar *title; gint i; gvalues[0] = gwy_grain_values_get_grain_value(args->abscissa); gvalues[1] = gwy_grain_values_get_grain_value(args->ordinate); bothdata = g_new(gdouble, 4*args->ngrains + 2); rdata[0] = xdata = bothdata + 2*args->ngrains; rdata[1] = ydata = bothdata + 3*args->ngrains + 1; gwy_grain_values_calculate(2, gvalues, rdata, dfield, args->ngrains, args->grains); for (i = 0; i < args->ngrains; i++) { bothdata[2*i + 0] = xdata[i+1]; bothdata[2*i + 1] = ydata[i+1]; } qsort(bothdata, args->ngrains, 2*sizeof(gdouble), compare_doubles); for (i = 0; i < args->ngrains; i++) { xdata[i] = bothdata[2*i + 0]; ydata[i] = bothdata[2*i + 1]; } gmodel = gwy_graph_model_new(); cmodel = gwy_graph_curve_model_new(); gwy_graph_model_add_curve(gmodel, cmodel); g_object_unref(cmodel); siunitxy = gwy_data_field_get_si_unit_xy(dfield); siunitz = gwy_data_field_get_si_unit_z(dfield); siunitx = gwy_si_unit_power_multiply (siunitxy, gwy_grain_value_get_power_xy(gvalues[0]), siunitz, gwy_grain_value_get_power_z(gvalues[0]), NULL); siunity = gwy_si_unit_power_multiply (siunitxy, gwy_grain_value_get_power_xy(gvalues[1]), siunitz, gwy_grain_value_get_power_z(gvalues[1]), NULL); /* FIXME */ title = gettext(gwy_resource_get_name(GWY_RESOURCE(gvalues[1]))); g_object_set (gmodel, "title", title, "axis-label-left", gwy_grain_value_get_symbol_markup(gvalues[1]), "axis-label-bottom", gwy_grain_value_get_symbol_markup(gvalues[0]), "si-unit-x", siunitx, "si-unit-y", siunity, NULL); g_object_unref(siunitx); g_object_unref(siunity); g_object_set(cmodel, "description", title, "mode", GWY_GRAPH_CURVE_POINTS, NULL); gwy_graph_curve_model_set_data(cmodel, xdata, ydata, args->ngrains); g_free(bothdata); return gmodel; }