/* curve_fitting.c generated by valac 0.56.19, the Vala compiler
 * generated from curve_fitting.vala, do not modify */

/* SPDX-License-Identifier: GPL-3.0-or-later*/

#include "graphs.h"
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <float.h>
#include <math.h>
#include <glib-object.h>
#include <glib/gi18n-lib.h>
#include <adwaita.h>
#include <gtk/gtk.h>
#include <gio/gio.h>
#include <gee.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	GRAPHS_FITTING_PARAMETER_0_PROPERTY,
	GRAPHS_FITTING_PARAMETER_NAME_PROPERTY,
	GRAPHS_FITTING_PARAMETER_INITIAL_PROPERTY,
	GRAPHS_FITTING_PARAMETER_NUM_PROPERTIES
};
static GParamSpec* graphs_fitting_parameter_properties[GRAPHS_FITTING_PARAMETER_NUM_PROPERTIES];
#define _g_free0(var) (var = (g_free (var), NULL))
enum  {
	GRAPHS_FIT_RESULT_0_PROPERTY,
	GRAPHS_FIT_RESULT_NUM_PROPERTIES
};
static GParamSpec* graphs_fit_result_properties[GRAPHS_FIT_RESULT_NUM_PROPERTIES];
enum  {
	GRAPHS_CURVE_FITTING_DIALOG_0_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_WINDOW_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_SETTINGS_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_EQUATION_STRING_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_FITTED_EQUATION_STRING_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_FIT_RESULT_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_CANVAS_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_RESIDUALS_CANVAS_PROPERTY,
	GRAPHS_CURVE_FITTING_DIALOG_NUM_PROPERTIES
};
static GParamSpec* graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
enum  {
	GRAPHS_FITTING_PARAMETER_BOX_0_PROPERTY,
	GRAPHS_FITTING_PARAMETER_BOX_INITIAL_PROPERTY,
	GRAPHS_FITTING_PARAMETER_BOX_UPPER_BOUND_PROPERTY,
	GRAPHS_FITTING_PARAMETER_BOX_LOWER_BOUND_PROPERTY,
	GRAPHS_FITTING_PARAMETER_BOX_PARAM_PROPERTY,
	GRAPHS_FITTING_PARAMETER_BOX_NUM_PROPERTIES
};
static GParamSpec* graphs_fitting_parameter_box_properties[GRAPHS_FITTING_PARAMETER_BOX_NUM_PROPERTIES];

struct _GraphsFittingParameterPrivate {
	gchar* _name;
	gdouble _initial;
	gdouble lower_bound;
	gdouble upper_bound;
};

struct _GraphsFitResultPrivate {
	gdouble* parameters;
	gint parameters_length1;
	gint _parameters_size_;
	gdouble* diag_covars;
	gint diag_covars_length1;
	gint _diag_covars_size_;
	gdouble r2;
	gdouble rmse;
};

struct _GraphsCurveFittingDialogPrivate {
	AdwComboRow* _equation;
	GtkButton* _confirm_button;
	AdwEntryRow* _custom_equation;
	GtkBox* _fitting_params_box;
	GtkTextView* _text_view;
	AdwToastOverlay* _toast_overlay;
	AdwOverlaySplitView* _split_view;
	AdwBin* _canvas_container;
	AdwBin* _residuals_container;
	GraphsWindow* _window;
	GSettings* _settings;
	gchar* _equation_string;
	gchar* _fitted_equation_string;
	GraphsFitResult* _fit_result;
	GeeMap* fitting_parameters;
	gchar** free_vars;
	gint free_vars_length1;
	gint _free_vars_size_;
};

struct _GraphsFittingParameterBoxPrivate {
	GtkLabel* _label;
	AdwEntryRow* _initial;
	AdwEntryRow* _upper_bound;
	AdwEntryRow* _lower_bound;
	GraphsFittingParameter* _param;
};

static gint GraphsFittingParameter_private_offset;
static gpointer graphs_fitting_parameter_parent_class = NULL;
static gint GraphsFitResult_private_offset;
static gpointer graphs_fit_result_parent_class = NULL;
static gint GraphsCurveFittingDialog_private_offset;
static gpointer graphs_curve_fitting_dialog_parent_class = NULL;
static gint GraphsFittingParameterBox_private_offset;
static gpointer graphs_fitting_parameter_box_parent_class = NULL;

static void graphs_fitting_parameter_finalize (GObject * obj);
static GType graphs_fitting_parameter_get_type_once (void);
static void _vala_graphs_fitting_parameter_get_property (GObject * object,
                                                  guint property_id,
                                                  GValue * value,
                                                  GParamSpec * pspec);
static void _vala_graphs_fitting_parameter_set_property (GObject * object,
                                                  guint property_id,
                                                  const GValue * value,
                                                  GParamSpec * pspec);
static gdouble* _vala_array_dup13 (gdouble* self,
                            gssize length);
static gdouble* _vala_array_dup14 (gdouble* self,
                            gssize length);
static gdouble* _vala_array_dup15 (gdouble* self,
                            gssize length);
static gdouble* _vala_array_dup16 (gdouble* self,
                            gssize length);
static void graphs_fit_result_finalize (GObject * obj);
static GType graphs_fit_result_get_type_once (void);
static gchar** _vala_array_dup17 (gchar** self,
                           gssize length);
static GtkTextView* graphs_curve_fitting_dialog_get_text_view (GraphsCurveFittingDialog* self);
static GtkButton* graphs_curve_fitting_dialog_get_confirm_button (GraphsCurveFittingDialog* self);
static void graphs_curve_fitting_dialog_on_entry_change (GraphsCurveFittingDialog* self,
                                                  GObject* object,
                                                  GParamSpec* p);
static void graphs_curve_fitting_dialog_update_bounds_visibility (GraphsCurveFittingDialog* self);
static GtkBox* graphs_curve_fitting_dialog_get_fitting_params_box (GraphsCurveFittingDialog* self);
static void graphs_curve_fitting_dialog_on_custom_equation_text_changed (GraphsCurveFittingDialog* self);
static AdwComboRow* graphs_curve_fitting_dialog_get_equation (GraphsCurveFittingDialog* self);
static gboolean graphs_curve_fitting_dialog_handle_new_equation (GraphsCurveFittingDialog* self,
                                                          const gchar* equation);
static AdwEntryRow* graphs_curve_fitting_dialog_get_custom_equation (GraphsCurveFittingDialog* self);
static void graphs_curve_fitting_dialog_set_equation_from_selection (GraphsCurveFittingDialog* self);
static void graphs_curve_fitting_dialog_set_equation_string (GraphsCurveFittingDialog* self,
                                                      const gchar* value);
static void _graphs_curve_fitting_dialog_on_entry_change_g_object_notify (GObject* _sender,
                                                                   GParamSpec* pspec,
                                                                   gpointer self);
static void graphs_curve_fitting_dialog_on_accept (GraphsCurveFittingDialog* self);
static void _graphs_curve_fitting_dialog_on_accept_gtk_button_clicked (GtkButton* _sender,
                                                                gpointer self);
static AdwToastOverlay* graphs_curve_fitting_dialog_get_toast_overlay (GraphsCurveFittingDialog* self);
static AdwOverlaySplitView* graphs_curve_fitting_dialog_get_split_view (GraphsCurveFittingDialog* self);
static AdwBin* graphs_curve_fitting_dialog_get_canvas_container (GraphsCurveFittingDialog* self);
static AdwBin* graphs_curve_fitting_dialog_get_residuals_container (GraphsCurveFittingDialog* self);
static GObject * graphs_curve_fitting_dialog_constructor (GType type,
                                                   guint n_construct_properties,
                                                   GObjectConstructParam * construct_properties);
static void _graphs_curve_fitting_dialog___lambda18_ (GraphsCurveFittingDialog* self);
static void __graphs_curve_fitting_dialog___lambda18__g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
static void _graphs_curve_fitting_dialog___lambda19_ (GraphsCurveFittingDialog* self);
static void __graphs_curve_fitting_dialog___lambda19__g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
static void _graphs_curve_fitting_dialog___lambda20_ (GraphsCurveFittingDialog* self);
static void __graphs_curve_fitting_dialog___lambda20__g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
static void _graphs_curve_fitting_dialog___lambda21_ (GraphsCurveFittingDialog* self);
static void __graphs_curve_fitting_dialog___lambda21__g_simple_action_activate (GSimpleAction* _sender,
                                                                         GVariant* parameter,
                                                                         gpointer self);
static void _graphs_curve_fitting_dialog_set_equation_from_selection_g_object_notify (GObject* _sender,
                                                                               GParamSpec* pspec,
                                                                               gpointer self);
static void _graphs_curve_fitting_dialog_on_custom_equation_text_changed_g_object_notify (GObject* _sender,
                                                                                   GParamSpec* pspec,
                                                                                   gpointer self);
static void _graphs_curve_fitting_dialog___lambda22_ (GraphsCurveFittingDialog* self);
static void __graphs_curve_fitting_dialog___lambda22__g_object_notify (GObject* _sender,
                                                                GParamSpec* pspec,
                                                                gpointer self);
static void graphs_curve_fitting_dialog_finalize (GObject * obj);
static GType graphs_curve_fitting_dialog_get_type_once (void);
static void _vala_graphs_curve_fitting_dialog_get_property (GObject * object,
                                                     guint property_id,
                                                     GValue * value,
                                                     GParamSpec * pspec);
static void _vala_graphs_curve_fitting_dialog_set_property (GObject * object,
                                                     guint property_id,
                                                     const GValue * value,
                                                     GParamSpec * pspec);
static GtkLabel* graphs_fitting_parameter_box_get_label (GraphsFittingParameterBox* self);
static void graphs_fitting_parameter_box_finalize (GObject * obj);
static GType graphs_fitting_parameter_box_get_type_once (void);
static void _vala_graphs_fitting_parameter_box_get_property (GObject * object,
                                                      guint property_id,
                                                      GValue * value,
                                                      GParamSpec * pspec);
static void _vala_graphs_fitting_parameter_box_set_property (GObject * object,
                                                      guint property_id,
                                                      const GValue * value,
                                                      GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

const gchar* GRAPHS_EQUATIONS[7] = {"a*x+b", "a*x²+b*x+c", "a*exp(b*x)", "a*x^b", "a*log(x)+b", "L/(1+exp(-k*(x-b)))", "a*exp(-(x-mu)²/(2*s²))"};

static inline gpointer
graphs_fitting_parameter_get_instance_private (GraphsFittingParameter* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsFittingParameter_private_offset);
}

GraphsFittingParameter*
graphs_fitting_parameter_construct (GType object_type,
                                    const gchar* name)
{
	GraphsFittingParameter * self = NULL;
	g_return_val_if_fail (name != NULL, NULL);
	self = (GraphsFittingParameter*) g_object_new (object_type, "name", name, "initial", 1., NULL);
	return self;
}

GraphsFittingParameter*
graphs_fitting_parameter_new (const gchar* name)
{
	return graphs_fitting_parameter_construct (GRAPHS_TYPE_FITTING_PARAMETER, name);
}

gdouble
graphs_fitting_parameter_get_lower_bound (GraphsFittingParameter* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	result = self->priv->lower_bound;
	return result;
}

void
graphs_fitting_parameter_set_lower_bound (GraphsFittingParameter* self,
                                          gdouble lower_bound)
{
	g_return_if_fail (self != NULL);
	self->priv->lower_bound = lower_bound;
}

gdouble
graphs_fitting_parameter_get_upper_bound (GraphsFittingParameter* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	result = self->priv->upper_bound;
	return result;
}

void
graphs_fitting_parameter_set_upper_bound (GraphsFittingParameter* self,
                                          gdouble upper_bound)
{
	g_return_if_fail (self != NULL);
	self->priv->upper_bound = upper_bound;
}

const gchar*
graphs_fitting_parameter_get_name (GraphsFittingParameter* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_name;
	result = _tmp0_;
	return result;
}

void
graphs_fitting_parameter_set_name (GraphsFittingParameter* self,
                                   const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_fitting_parameter_get_name (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_name);
		self->priv->_name = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_fitting_parameter_properties[GRAPHS_FITTING_PARAMETER_NAME_PROPERTY]);
	}
}

gdouble
graphs_fitting_parameter_get_initial (GraphsFittingParameter* self)
{
	gdouble result;
	g_return_val_if_fail (self != NULL, -1.0);
	result = self->priv->_initial;
	return result;
}

void
graphs_fitting_parameter_set_initial (GraphsFittingParameter* self,
                                      gdouble value)
{
	gdouble old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_fitting_parameter_get_initial (self);
	if (old_value != value) {
		self->priv->_initial = value;
		g_object_notify_by_pspec ((GObject *) self, graphs_fitting_parameter_properties[GRAPHS_FITTING_PARAMETER_INITIAL_PROPERTY]);
	}
}

static void
graphs_fitting_parameter_class_init (GraphsFittingParameterClass * klass,
                                     gpointer klass_data)
{
	graphs_fitting_parameter_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsFittingParameter_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_fitting_parameter_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_graphs_fitting_parameter_set_property;
	G_OBJECT_CLASS (klass)->finalize = graphs_fitting_parameter_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_FITTING_PARAMETER_NAME_PROPERTY, graphs_fitting_parameter_properties[GRAPHS_FITTING_PARAMETER_NAME_PROPERTY] = g_param_spec_string ("name", "name", "name", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_FITTING_PARAMETER_INITIAL_PROPERTY, graphs_fitting_parameter_properties[GRAPHS_FITTING_PARAMETER_INITIAL_PROPERTY] = g_param_spec_double ("initial", "initial", "initial", -G_MAXDOUBLE, G_MAXDOUBLE, 0.0, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
}

static void
graphs_fitting_parameter_instance_init (GraphsFittingParameter * self,
                                        gpointer klass)
{
	self->priv = graphs_fitting_parameter_get_instance_private (self);
	self->priv->lower_bound = -((double) INFINITY);
	self->priv->upper_bound = ((double) INFINITY);
}

static void
graphs_fitting_parameter_finalize (GObject * obj)
{
	GraphsFittingParameter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_FITTING_PARAMETER, GraphsFittingParameter);
	_g_free0 (self->priv->_name);
	G_OBJECT_CLASS (graphs_fitting_parameter_parent_class)->finalize (obj);
}

static GType
graphs_fitting_parameter_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsFittingParameterClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_fitting_parameter_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsFittingParameter), 0, (GInstanceInitFunc) graphs_fitting_parameter_instance_init, NULL };
	GType graphs_fitting_parameter_type_id;
	graphs_fitting_parameter_type_id = g_type_register_static (G_TYPE_OBJECT, "GraphsFittingParameter", &g_define_type_info, 0);
	GraphsFittingParameter_private_offset = g_type_add_instance_private (graphs_fitting_parameter_type_id, sizeof (GraphsFittingParameterPrivate));
	return graphs_fitting_parameter_type_id;
}

GType
graphs_fitting_parameter_get_type (void)
{
	static volatile gsize graphs_fitting_parameter_type_id__once = 0;
	if (g_once_init_enter (&graphs_fitting_parameter_type_id__once)) {
		GType graphs_fitting_parameter_type_id;
		graphs_fitting_parameter_type_id = graphs_fitting_parameter_get_type_once ();
		g_once_init_leave (&graphs_fitting_parameter_type_id__once, graphs_fitting_parameter_type_id);
	}
	return graphs_fitting_parameter_type_id__once;
}

static void
_vala_graphs_fitting_parameter_get_property (GObject * object,
                                             guint property_id,
                                             GValue * value,
                                             GParamSpec * pspec)
{
	GraphsFittingParameter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_FITTING_PARAMETER, GraphsFittingParameter);
	switch (property_id) {
		case GRAPHS_FITTING_PARAMETER_NAME_PROPERTY:
		g_value_set_string (value, graphs_fitting_parameter_get_name (self));
		break;
		case GRAPHS_FITTING_PARAMETER_INITIAL_PROPERTY:
		g_value_set_double (value, graphs_fitting_parameter_get_initial (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_graphs_fitting_parameter_set_property (GObject * object,
                                             guint property_id,
                                             const GValue * value,
                                             GParamSpec * pspec)
{
	GraphsFittingParameter * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_FITTING_PARAMETER, GraphsFittingParameter);
	switch (property_id) {
		case GRAPHS_FITTING_PARAMETER_NAME_PROPERTY:
		graphs_fitting_parameter_set_name (self, g_value_get_string (value));
		break;
		case GRAPHS_FITTING_PARAMETER_INITIAL_PROPERTY:
		graphs_fitting_parameter_set_initial (self, g_value_get_double (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
graphs_fit_result_get_instance_private (GraphsFitResult* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsFitResult_private_offset);
}

static gdouble*
_vala_array_dup13 (gdouble* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gdouble));
	}
	return NULL;
}

static gdouble*
_vala_array_dup14 (gdouble* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gdouble));
	}
	return NULL;
}

GraphsFitResult*
graphs_fit_result_construct (GType object_type,
                             gdouble* parameters,
                             gint parameters_length1,
                             gdouble* diag_covars,
                             gint diag_covars_length1,
                             gdouble r2,
                             gdouble rmse)
{
	GraphsFitResult * self = NULL;
	gdouble* _tmp0_;
	gint _tmp0__length1;
	gdouble* _tmp1_;
	gint _tmp1__length1;
	self = (GraphsFitResult*) g_object_new (object_type, NULL);
	_tmp0_ = (parameters != NULL) ? _vala_array_dup13 (parameters, parameters_length1) : parameters;
	_tmp0__length1 = parameters_length1;
	self->priv->parameters = (g_free (self->priv->parameters), NULL);
	self->priv->parameters = _tmp0_;
	self->priv->parameters_length1 = _tmp0__length1;
	self->priv->_parameters_size_ = self->priv->parameters_length1;
	_tmp1_ = (diag_covars != NULL) ? _vala_array_dup14 (diag_covars, diag_covars_length1) : diag_covars;
	_tmp1__length1 = diag_covars_length1;
	self->priv->diag_covars = (g_free (self->priv->diag_covars), NULL);
	self->priv->diag_covars = _tmp1_;
	self->priv->diag_covars_length1 = _tmp1__length1;
	self->priv->_diag_covars_size_ = self->priv->diag_covars_length1;
	self->priv->r2 = r2;
	self->priv->rmse = rmse;
	return self;
}

GraphsFitResult*
graphs_fit_result_new (gdouble* parameters,
                       gint parameters_length1,
                       gdouble* diag_covars,
                       gint diag_covars_length1,
                       gdouble r2,
                       gdouble rmse)
{
	return graphs_fit_result_construct (GRAPHS_TYPE_FIT_RESULT, parameters, parameters_length1, diag_covars, diag_covars_length1, r2, rmse);
}

static gdouble*
_vala_array_dup15 (gdouble* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gdouble));
	}
	return NULL;
}

gdouble*
graphs_fit_result_get_parameters (GraphsFitResult* self,
                                  gint* result_length1)
{
	gdouble* _tmp0_;
	gint _tmp0__length1;
	gdouble* _tmp1_;
	gint _tmp1__length1;
	gdouble* _tmp2_;
	gint _tmp2__length1;
	gdouble* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->parameters;
	_tmp0__length1 = self->priv->parameters_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup15 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static gdouble*
_vala_array_dup16 (gdouble* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (gdouble));
	}
	return NULL;
}

gdouble*
graphs_fit_result_get_diag_covars (GraphsFitResult* self,
                                   gint* result_length1)
{
	gdouble* _tmp0_;
	gint _tmp0__length1;
	gdouble* _tmp1_;
	gint _tmp1__length1;
	gdouble* _tmp2_;
	gint _tmp2__length1;
	gdouble* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->diag_covars;
	_tmp0__length1 = self->priv->diag_covars_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup16 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

void
graphs_fit_result_get_r2_rmse (GraphsFitResult* self,
                               gdouble* r2,
                               gdouble* rmse)
{
	gdouble _vala_r2 = 0.0;
	gdouble _vala_rmse = 0.0;
	g_return_if_fail (self != NULL);
	_vala_r2 = self->priv->r2;
	_vala_rmse = self->priv->rmse;
	if (r2) {
		*r2 = _vala_r2;
	}
	if (rmse) {
		*rmse = _vala_rmse;
	}
}

static void
graphs_fit_result_class_init (GraphsFitResultClass * klass,
                              gpointer klass_data)
{
	graphs_fit_result_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsFitResult_private_offset);
	G_OBJECT_CLASS (klass)->finalize = graphs_fit_result_finalize;
}

static void
graphs_fit_result_instance_init (GraphsFitResult * self,
                                 gpointer klass)
{
	self->priv = graphs_fit_result_get_instance_private (self);
}

static void
graphs_fit_result_finalize (GObject * obj)
{
	GraphsFitResult * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_FIT_RESULT, GraphsFitResult);
	self->priv->parameters = (g_free (self->priv->parameters), NULL);
	self->priv->diag_covars = (g_free (self->priv->diag_covars), NULL);
	G_OBJECT_CLASS (graphs_fit_result_parent_class)->finalize (obj);
}

static GType
graphs_fit_result_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsFitResultClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_fit_result_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsFitResult), 0, (GInstanceInitFunc) graphs_fit_result_instance_init, NULL };
	GType graphs_fit_result_type_id;
	graphs_fit_result_type_id = g_type_register_static (G_TYPE_OBJECT, "GraphsFitResult", &g_define_type_info, 0);
	GraphsFitResult_private_offset = g_type_add_instance_private (graphs_fit_result_type_id, sizeof (GraphsFitResultPrivate));
	return graphs_fit_result_type_id;
}

GType
graphs_fit_result_get_type (void)
{
	static volatile gsize graphs_fit_result_type_id__once = 0;
	if (g_once_init_enter (&graphs_fit_result_type_id__once)) {
		GType graphs_fit_result_type_id;
		graphs_fit_result_type_id = graphs_fit_result_get_type_once ();
		g_once_init_leave (&graphs_fit_result_type_id__once, graphs_fit_result_type_id);
	}
	return graphs_fit_result_type_id__once;
}

gchar*
graphs_curve_fitting_error_to_text (GraphsCurveFittingError self)
{
	gchar* result;
	switch (self) {
		case GRAPHS_CURVE_FITTING_ERROR_VALUE:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup (_ ("Please enter valid \nnumeric parameters."));
			result = _tmp0_;
			return result;
		}
		case GRAPHS_CURVE_FITTING_ERROR_BOUNDS:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup (_ ("Constraint error: ensure \nLower < Initial < Upper."));
			result = _tmp1_;
			return result;
		}
		case GRAPHS_CURVE_FITTING_ERROR_SINGULAR:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup (_ ("Matrix error: Data is \ninsufficient for this model."));
			result = _tmp2_;
			return result;
		}
		case GRAPHS_CURVE_FITTING_ERROR_CONVERGENCE:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup (_ ("Fit failed: Max iterations \nreached without converging."));
			result = _tmp3_;
			return result;
		}
		case GRAPHS_CURVE_FITTING_ERROR_DOMAIN:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup (_ ("Domain error: Equation not \nvalid for this data range."));
			result = _tmp4_;
			return result;
		}
		case GRAPHS_CURVE_FITTING_ERROR_EQUATION:
		{
			gchar* _tmp5_;
			_tmp5_ = g_strdup (_ ("Invalid equation: Check \nsyntax and variables."));
			result = _tmp5_;
			return result;
		}
		case GRAPHS_CURVE_FITTING_ERROR_CONFIDENCE:
		{
			gchar* _tmp6_;
			_tmp6_ = g_strdup (_ ("Confidence band error: \nCovariance matrix is unstable."));
			result = _tmp6_;
			return result;
		}
		default:
		{
			g_assert_not_reached ();
		}
	}
}

static GType
graphs_curve_fitting_error_get_type_once (void)
{
	static const GEnumValue values[] = {{GRAPHS_CURVE_FITTING_ERROR_NONE, "GRAPHS_CURVE_FITTING_ERROR_NONE", "none"}, {GRAPHS_CURVE_FITTING_ERROR_VALUE, "GRAPHS_CURVE_FITTING_ERROR_VALUE", "value"}, {GRAPHS_CURVE_FITTING_ERROR_BOUNDS, "GRAPHS_CURVE_FITTING_ERROR_BOUNDS", "bounds"}, {GRAPHS_CURVE_FITTING_ERROR_SINGULAR, "GRAPHS_CURVE_FITTING_ERROR_SINGULAR", "singular"}, {GRAPHS_CURVE_FITTING_ERROR_CONVERGENCE, "GRAPHS_CURVE_FITTING_ERROR_CONVERGENCE", "convergence"}, {GRAPHS_CURVE_FITTING_ERROR_DOMAIN, "GRAPHS_CURVE_FITTING_ERROR_DOMAIN", "domain"}, {GRAPHS_CURVE_FITTING_ERROR_EQUATION, "GRAPHS_CURVE_FITTING_ERROR_EQUATION", "equation"}, {GRAPHS_CURVE_FITTING_ERROR_CONFIDENCE, "GRAPHS_CURVE_FITTING_ERROR_CONFIDENCE", "confidence"}, {0, NULL, NULL}};
	GType graphs_curve_fitting_error_type_id;
	graphs_curve_fitting_error_type_id = g_enum_register_static ("GraphsCurveFittingError", values);
	return graphs_curve_fitting_error_type_id;
}

GType
graphs_curve_fitting_error_get_type (void)
{
	static volatile gsize graphs_curve_fitting_error_type_id__once = 0;
	if (g_once_init_enter (&graphs_curve_fitting_error_type_id__once)) {
		GType graphs_curve_fitting_error_type_id;
		graphs_curve_fitting_error_type_id = graphs_curve_fitting_error_get_type_once ();
		g_once_init_leave (&graphs_curve_fitting_error_type_id__once, graphs_curve_fitting_error_type_id);
	}
	return graphs_curve_fitting_error_type_id__once;
}

static inline gpointer
graphs_curve_fitting_dialog_get_instance_private (GraphsCurveFittingDialog* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsCurveFittingDialog_private_offset);
}

gdouble*
graphs_curve_fitting_dialog_get_p0 (GraphsCurveFittingDialog* self,
                                    gint* result_length1)
{
	gdouble* _result_ = NULL;
	GeeMap* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gdouble* _tmp3_;
	gint _result__length1;
	gint __result__size_;
	GeeMapIterator* iterator = NULL;
	GeeMap* _tmp4_;
	GeeMapIterator* _tmp5_;
	gint idx = 0;
	gdouble* _tmp15_;
	gint _tmp15__length1;
	gdouble* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->fitting_parameters;
	_tmp1_ = gee_map_get_size (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_new0 (gdouble, _tmp2_);
	_result_ = _tmp3_;
	_result__length1 = _tmp2_;
	__result__size_ = _result__length1;
	_tmp4_ = self->priv->fitting_parameters;
	_tmp5_ = gee_map_map_iterator (_tmp4_);
	iterator = _tmp5_;
	idx = 0;
	while (TRUE) {
		GeeMapIterator* _tmp6_;
		GeeMapIterator* _tmp7_;
		gdouble* _tmp8_;
		gint _tmp8__length1;
		gint _tmp9_;
		GeeMapIterator* _tmp10_;
		gpointer _tmp11_;
		GraphsFittingParameter* _tmp12_;
		gdouble _tmp13_;
		gdouble _tmp14_;
		_tmp6_ = iterator;
		if (!gee_map_iterator_has_next (_tmp6_)) {
			break;
		}
		_tmp7_ = iterator;
		gee_map_iterator_next (_tmp7_);
		_tmp8_ = _result_;
		_tmp8__length1 = _result__length1;
		_tmp9_ = idx;
		idx = _tmp9_ + 1;
		_tmp10_ = iterator;
		_tmp11_ = gee_map_iterator_get_value (_tmp10_);
		_tmp12_ = (GraphsFittingParameter*) _tmp11_;
		_tmp13_ = graphs_fitting_parameter_get_initial (_tmp12_);
		_tmp14_ = _tmp13_;
		_tmp8_[_tmp9_] = _tmp14_;
		_g_object_unref0 (_tmp12_);
	}
	_tmp15_ = _result_;
	_tmp15__length1 = _result__length1;
	if (result_length1) {
		*result_length1 = _tmp15__length1;
	}
	result = _tmp15_;
	_g_object_unref0 (iterator);
	return result;
}

void
graphs_curve_fitting_dialog_get_bounds (GraphsCurveFittingDialog* self,
                                        gdouble** lower,
                                        gint* lower_length1,
                                        gdouble** upper,
                                        gint* upper_length1)
{
	gdouble* _vala_lower = NULL;
	gint _vala_lower_length1 = 0;
	gdouble* _vala_upper = NULL;
	gint _vala_upper_length1 = 0;
	GeeMap* _tmp0_;
	gint _tmp1_;
	gint _tmp2_;
	gdouble* _tmp3_;
	GeeMap* _tmp4_;
	gint _tmp5_;
	gint _tmp6_;
	gdouble* _tmp7_;
	GeeMapIterator* iterator = NULL;
	GeeMap* _tmp8_;
	GeeMapIterator* _tmp9_;
	gint idx = 0;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->fitting_parameters;
	_tmp1_ = gee_map_get_size (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_new0 (gdouble, _tmp2_);
	_vala_lower = (g_free (_vala_lower), NULL);
	_vala_lower = _tmp3_;
	_vala_lower_length1 = _tmp2_;
	_tmp4_ = self->priv->fitting_parameters;
	_tmp5_ = gee_map_get_size (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = g_new0 (gdouble, _tmp6_);
	_vala_upper = (g_free (_vala_upper), NULL);
	_vala_upper = _tmp7_;
	_vala_upper_length1 = _tmp6_;
	_tmp8_ = self->priv->fitting_parameters;
	_tmp9_ = gee_map_map_iterator (_tmp8_);
	iterator = _tmp9_;
	idx = 0;
	while (TRUE) {
		GeeMapIterator* _tmp10_;
		GeeMapIterator* _tmp11_;
		GraphsFittingParameter* param = NULL;
		GeeMapIterator* _tmp12_;
		gpointer _tmp13_;
		gdouble* _tmp14_;
		gint _tmp14__length1;
		GraphsFittingParameter* _tmp15_;
		gdouble* _tmp16_;
		gint _tmp16__length1;
		GraphsFittingParameter* _tmp17_;
		gint _tmp18_;
		_tmp10_ = iterator;
		if (!gee_map_iterator_has_next (_tmp10_)) {
			break;
		}
		_tmp11_ = iterator;
		gee_map_iterator_next (_tmp11_);
		_tmp12_ = iterator;
		_tmp13_ = gee_map_iterator_get_value (_tmp12_);
		param = (GraphsFittingParameter*) _tmp13_;
		_tmp14_ = _vala_lower;
		_tmp14__length1 = _vala_lower_length1;
		_tmp15_ = param;
		_tmp14_[idx] = graphs_fitting_parameter_get_lower_bound (_tmp15_);
		_tmp16_ = _vala_upper;
		_tmp16__length1 = _vala_upper_length1;
		_tmp17_ = param;
		_tmp16_[idx] = graphs_fitting_parameter_get_upper_bound (_tmp17_);
		_tmp18_ = idx;
		idx = _tmp18_ + 1;
		_g_object_unref0 (param);
	}
	_g_object_unref0 (iterator);
	if (lower) {
		*lower = _vala_lower;
	} else {
		_vala_lower = (g_free (_vala_lower), NULL);
	}
	if (lower_length1) {
		*lower_length1 = _vala_lower_length1;
	}
	if (upper) {
		*upper = _vala_upper;
	} else {
		_vala_upper = (g_free (_vala_upper), NULL);
	}
	if (upper_length1) {
		*upper_length1 = _vala_upper_length1;
	}
}

static gchar**
_vala_array_dup17 (gchar** self,
                   gssize length)
{
	if (length >= 0) {
		gchar** result;
		gssize i;
		result = g_new0 (gchar*, length + 1);
		for (i = 0; i < length; i++) {
			gchar* _tmp0_;
			_tmp0_ = g_strdup (self[i]);
			result[i] = _tmp0_;
		}
		return result;
	}
	return NULL;
}

gchar**
graphs_curve_fitting_dialog_get_free_vars (GraphsCurveFittingDialog* self,
                                           gint* result_length1)
{
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	gchar** _tmp2_;
	gint _tmp2__length1;
	gchar** result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->free_vars;
	_tmp0__length1 = self->priv->free_vars_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup17 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	_tmp2_ = _tmp1_;
	_tmp2__length1 = _tmp1__length1;
	if (result_length1) {
		*result_length1 = _tmp2__length1;
	}
	result = _tmp2_;
	return result;
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

void
graphs_curve_fitting_dialog_set_results (GraphsCurveFittingDialog* self,
                                         GraphsCurveFittingError _error_)
{
	GtkTextBuffer* buffer = NULL;
	GtkTextView* _tmp0_;
	GtkTextBuffer* _tmp1_;
	GtkTextBuffer* _tmp2_;
	GtkTextBuffer* _tmp3_;
	GtkTextTagTable* tag_table = NULL;
	GtkTextBuffer* _tmp4_;
	GtkTextTagTable* _tmp5_;
	GtkTextTagTable* _tmp6_;
	GtkTextTag* bold_tag = NULL;
	GtkTextTagTable* _tmp7_;
	GtkTextTag* _tmp8_;
	GtkTextTag* _tmp9_;
	GtkTextTag* _tmp10_;
	GtkTextIter end_iter = {0};
	GtkTextBuffer* _tmp14_;
	GtkTextIter _tmp15_ = {0};
	GtkButton* _tmp20_;
	GraphsFitResult* _tmp21_;
	GtkTextBuffer* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	gdouble* diag_covars = NULL;
	GraphsFitResult* _tmp25_;
	gint _tmp26_ = 0;
	gdouble* _tmp27_;
	gint diag_covars_length1;
	gint _diag_covars_size_;
	gdouble* parameters = NULL;
	GraphsFitResult* _tmp28_;
	gint _tmp29_ = 0;
	gdouble* _tmp30_;
	gint parameters_length1;
	gint _parameters_size_;
	gint conf_level = 0;
	GSettings* _tmp31_;
	gint n = 0;
	gchar** _tmp32_;
	gint _tmp32__length1;
	GtkTextBuffer* _tmp48_;
	gchar* _tmp49_;
	gchar* _tmp50_;
	gchar* _tmp51_;
	gchar* _tmp52_;
	gdouble r2 = 0.0;
	gdouble rmse = 0.0;
	GraphsFitResult* _tmp53_;
	gdouble _tmp54_ = 0.0;
	gdouble _tmp55_ = 0.0;
	gchar* r2_rmse = NULL;
	gchar* _tmp56_;
	GtkTextBuffer* _tmp57_;
	const gchar* _tmp58_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_text_view;
	_tmp1_ = gtk_text_view_get_buffer (_tmp0_);
	_tmp2_ = _g_object_ref0 (_tmp1_);
	buffer = _tmp2_;
	_tmp3_ = buffer;
	gtk_text_buffer_set_text (_tmp3_, "", -1);
	_tmp4_ = buffer;
	_tmp5_ = gtk_text_buffer_get_tag_table (_tmp4_);
	_tmp6_ = _g_object_ref0 (_tmp5_);
	tag_table = _tmp6_;
	_tmp7_ = tag_table;
	_tmp8_ = gtk_text_tag_table_lookup (_tmp7_, "bold");
	_tmp9_ = _g_object_ref0 (_tmp8_);
	bold_tag = _tmp9_;
	_tmp10_ = bold_tag;
	if (_tmp10_ == NULL) {
		GtkTextBuffer* _tmp11_;
		GtkTextTag* _tmp12_;
		GtkTextTag* _tmp13_;
		_tmp11_ = buffer;
		_tmp12_ = gtk_text_buffer_create_tag (_tmp11_, "bold", "weight", 700, NULL);
		_tmp13_ = _g_object_ref0 (_tmp12_);
		_g_object_unref0 (bold_tag);
		bold_tag = _tmp13_;
	}
	_tmp14_ = buffer;
	gtk_text_buffer_get_end_iter (_tmp14_, &_tmp15_);
	end_iter = _tmp15_;
	if (_error_ != GRAPHS_CURVE_FITTING_ERROR_NONE) {
		GtkTextBuffer* _tmp16_;
		gchar* _tmp17_;
		gchar* _tmp18_;
		GtkButton* _tmp19_;
		_tmp16_ = buffer;
		_tmp17_ = graphs_curve_fitting_error_to_text (_error_);
		_tmp18_ = _tmp17_;
		gtk_text_buffer_insert (_tmp16_, &end_iter, _tmp18_, -1);
		_g_free0 (_tmp18_);
		_tmp19_ = self->priv->_confirm_button;
		gtk_widget_set_sensitive ((GtkWidget*) _tmp19_, FALSE);
		graphs_curve_fitting_dialog_set_fit_result (self, NULL);
		graphs_python_helper_run_method ((GObject*) self, "_clear_fit");
		_g_object_unref0 (bold_tag);
		_g_object_unref0 (tag_table);
		_g_object_unref0 (buffer);
		return;
	}
	_tmp20_ = self->priv->_confirm_button;
	gtk_widget_set_sensitive ((GtkWidget*) _tmp20_, TRUE);
	_tmp21_ = self->priv->_fit_result;
	if (_tmp21_ == NULL) {
		_g_object_unref0 (bold_tag);
		_g_object_unref0 (tag_table);
		_g_object_unref0 (buffer);
		return;
	}
	_tmp22_ = buffer;
	_tmp23_ = g_strconcat (_ ("Parameters"), "\n", NULL);
	_tmp24_ = _tmp23_;
	gtk_text_buffer_insert_with_tags_by_name (_tmp22_, &end_iter, _tmp24_, -1, "bold", NULL);
	_g_free0 (_tmp24_);
	_tmp25_ = self->priv->_fit_result;
	_tmp27_ = graphs_fit_result_get_diag_covars (_tmp25_, &_tmp26_);
	diag_covars = _tmp27_;
	diag_covars_length1 = _tmp26_;
	_diag_covars_size_ = diag_covars_length1;
	_tmp28_ = self->priv->_fit_result;
	_tmp30_ = graphs_fit_result_get_parameters (_tmp28_, &_tmp29_);
	parameters = _tmp30_;
	parameters_length1 = _tmp29_;
	_parameters_size_ = parameters_length1;
	_tmp31_ = self->priv->_settings;
	conf_level = g_settings_get_enum (_tmp31_, "confidence");
	_tmp32_ = self->priv->free_vars;
	_tmp32__length1 = self->priv->free_vars_length1;
	n = _tmp32__length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp33_ = FALSE;
			_tmp33_ = TRUE;
			while (TRUE) {
				GtkTextBuffer* _tmp35_;
				gchar** _tmp36_;
				gint _tmp36__length1;
				const gchar* _tmp37_;
				gdouble* _tmp38_;
				gint _tmp38__length1;
				gdouble _tmp39_;
				gchar* _tmp40_;
				gchar* _tmp41_;
				GtkTextBuffer* _tmp47_;
				if (!_tmp33_) {
					gint _tmp34_;
					_tmp34_ = i;
					i = _tmp34_ + 1;
				}
				_tmp33_ = FALSE;
				if (!(i < n)) {
					break;
				}
				_tmp35_ = buffer;
				_tmp36_ = self->priv->free_vars;
				_tmp36__length1 = self->priv->free_vars_length1;
				_tmp37_ = _tmp36_[i];
				_tmp38_ = parameters;
				_tmp38__length1 = parameters_length1;
				_tmp39_ = _tmp38_[i];
				_tmp40_ = g_strdup_printf ("%s: %.3g", _tmp37_, _tmp39_);
				_tmp41_ = _tmp40_;
				gtk_text_buffer_insert (_tmp35_, &end_iter, _tmp41_, -1);
				_g_free0 (_tmp41_);
				if (conf_level > 0) {
					gdouble err = 0.0;
					gdouble* _tmp42_;
					gint _tmp42__length1;
					gdouble _tmp43_;
					GtkTextBuffer* _tmp44_;
					gchar* _tmp45_;
					gchar* _tmp46_;
					_tmp42_ = diag_covars;
					_tmp42__length1 = diag_covars_length1;
					_tmp43_ = _tmp42_[i];
					err = _tmp43_ * conf_level;
					_tmp44_ = buffer;
					_tmp45_ = g_strdup_printf (" (± %.3g)", err);
					_tmp46_ = _tmp45_;
					gtk_text_buffer_insert (_tmp44_, &end_iter, _tmp46_, -1);
					_g_free0 (_tmp46_);
				}
				_tmp47_ = buffer;
				gtk_text_buffer_insert (_tmp47_, &end_iter, "\n", -1);
			}
		}
	}
	_tmp48_ = buffer;
	_tmp49_ = g_strconcat ("\n", _ ("Statistics"), NULL);
	_tmp50_ = _tmp49_;
	_tmp51_ = g_strconcat (_tmp50_, "\n", NULL);
	_tmp52_ = _tmp51_;
	gtk_text_buffer_insert_with_tags_by_name (_tmp48_, &end_iter, _tmp52_, -1, "bold", NULL);
	_g_free0 (_tmp52_);
	_g_free0 (_tmp50_);
	_tmp53_ = self->priv->_fit_result;
	graphs_fit_result_get_r2_rmse (_tmp53_, &_tmp54_, &_tmp55_);
	r2 = _tmp54_;
	rmse = _tmp55_;
	_tmp56_ = g_strdup_printf ("%s: %.3g\n%s: %.3g", _ ("R²"), r2, _ ("RMSE"), rmse);
	r2_rmse = _tmp56_;
	_tmp57_ = buffer;
	_tmp58_ = r2_rmse;
	gtk_text_buffer_insert (_tmp57_, &end_iter, _tmp58_, -1);
	_g_free0 (r2_rmse);
	parameters = (g_free (parameters), NULL);
	diag_covars = (g_free (diag_covars), NULL);
	_g_object_unref0 (bold_tag);
	_g_object_unref0 (tag_table);
	_g_object_unref0 (buffer);
}

static void
graphs_curve_fitting_dialog_on_entry_change (GraphsCurveFittingDialog* self,
                                             GObject* object,
                                             GParamSpec* p)
{
	AdwEntryRow* entry = NULL;
	AdwEntryRow* _tmp0_;
	GraphsFittingParameterBox* row = NULL;
	AdwEntryRow* _tmp1_;
	GtkWidget* _tmp2_;
	GraphsFittingParameterBox* _tmp3_;
	gdouble init = 0.0;
	gdouble low = 0.0;
	gdouble high = 0.0;
	gboolean value_error = FALSE;
	AdwEntryRow* widget = NULL;
	GraphsFittingParameterBox* _tmp4_;
	AdwEntryRow* _tmp5_;
	AdwEntryRow* _tmp6_;
	AdwEntryRow* _tmp7_;
	AdwEntryRow* _tmp8_;
	const gchar* _tmp9_;
	gdouble* _tmp10_ = NULL;
	gboolean _tmp11_;
	gdouble* _tmp12_;
	gboolean _tmp13_;
	GraphsFittingParameterBox* _tmp16_;
	AdwEntryRow* _tmp17_;
	AdwEntryRow* _tmp18_;
	AdwEntryRow* _tmp19_;
	AdwEntryRow* _tmp20_;
	const gchar* _tmp21_;
	gdouble* _tmp22_ = NULL;
	gboolean _tmp23_;
	gdouble* _tmp24_;
	gboolean _tmp25_;
	GraphsFittingParameterBox* _tmp28_;
	AdwEntryRow* _tmp29_;
	AdwEntryRow* _tmp30_;
	AdwEntryRow* _tmp31_;
	AdwEntryRow* _tmp32_;
	const gchar* _tmp33_;
	gdouble* _tmp34_ = NULL;
	gboolean _tmp35_;
	gdouble* _tmp36_;
	gboolean _tmp37_;
	gdouble _tmp46_;
	GraphsFittingParameter* param = NULL;
	GraphsFittingParameterBox* _tmp50_;
	GraphsFittingParameter* _tmp51_;
	GraphsFittingParameter* _tmp52_;
	GraphsFittingParameter* _tmp53_;
	GraphsFittingParameter* _tmp54_;
	GraphsFittingParameter* _tmp55_;
	GraphsFittingParameter* _tmp56_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (object != NULL);
	g_return_if_fail (p != NULL);
	_tmp0_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (object, adw_entry_row_get_type (), AdwEntryRow));
	entry = _tmp0_;
	_tmp1_ = entry;
	_tmp2_ = gtk_widget_get_ancestor ((GtkWidget*) _tmp1_, GRAPHS_TYPE_FITTING_PARAMETER_BOX);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GRAPHS_TYPE_FITTING_PARAMETER_BOX, GraphsFittingParameterBox));
	row = _tmp3_;
	value_error = FALSE;
	_tmp4_ = row;
	_tmp5_ = graphs_fitting_parameter_box_get_initial (_tmp4_);
	_tmp6_ = _tmp5_;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	widget = _tmp7_;
	_tmp8_ = widget;
	_tmp9_ = gtk_editable_get_text ((GtkEditable*) _tmp8_);
	_tmp11_ = graphs_try_evaluate_string (_tmp9_, &_tmp10_, (gunichar) '.');
	_tmp12_ = _tmp10_;
	init = *_tmp12_;
	_tmp13_ = _tmp11_;
	_g_free0 (_tmp12_);
	if (_tmp13_) {
		AdwEntryRow* _tmp14_;
		_tmp14_ = widget;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp14_, "error");
	} else {
		AdwEntryRow* _tmp15_;
		_tmp15_ = widget;
		gtk_widget_add_css_class ((GtkWidget*) _tmp15_, "error");
		value_error = TRUE;
	}
	_tmp16_ = row;
	_tmp17_ = graphs_fitting_parameter_box_get_lower_bound (_tmp16_);
	_tmp18_ = _tmp17_;
	_tmp19_ = _g_object_ref0 (_tmp18_);
	_g_object_unref0 (widget);
	widget = _tmp19_;
	_tmp20_ = widget;
	_tmp21_ = gtk_editable_get_text ((GtkEditable*) _tmp20_);
	_tmp23_ = graphs_try_evaluate_string (_tmp21_, &_tmp22_, (gunichar) '.');
	_tmp24_ = _tmp22_;
	low = *_tmp24_;
	_tmp25_ = _tmp23_;
	_g_free0 (_tmp24_);
	if (_tmp25_) {
		AdwEntryRow* _tmp26_;
		_tmp26_ = widget;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp26_, "error");
	} else {
		AdwEntryRow* _tmp27_;
		_tmp27_ = widget;
		gtk_widget_add_css_class ((GtkWidget*) _tmp27_, "error");
		value_error = TRUE;
	}
	_tmp28_ = row;
	_tmp29_ = graphs_fitting_parameter_box_get_upper_bound (_tmp28_);
	_tmp30_ = _tmp29_;
	_tmp31_ = _g_object_ref0 (_tmp30_);
	_g_object_unref0 (widget);
	widget = _tmp31_;
	_tmp32_ = widget;
	_tmp33_ = gtk_editable_get_text ((GtkEditable*) _tmp32_);
	_tmp35_ = graphs_try_evaluate_string (_tmp33_, &_tmp34_, (gunichar) '.');
	_tmp36_ = _tmp34_;
	high = *_tmp36_;
	_tmp37_ = _tmp35_;
	_g_free0 (_tmp36_);
	if (_tmp37_) {
		AdwEntryRow* _tmp38_;
		_tmp38_ = widget;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp38_, "error");
	} else {
		AdwEntryRow* _tmp39_;
		_tmp39_ = widget;
		gtk_widget_add_css_class ((GtkWidget*) _tmp39_, "error");
		value_error = TRUE;
	}
	if (value_error) {
		graphs_curve_fitting_dialog_set_results (self, GRAPHS_CURVE_FITTING_ERROR_VALUE);
		_g_object_unref0 (widget);
		_g_object_unref0 (row);
		_g_object_unref0 (entry);
		return;
	}
	if (low >= high) {
		GraphsFittingParameterBox* _tmp40_;
		AdwEntryRow* _tmp41_;
		AdwEntryRow* _tmp42_;
		GraphsFittingParameterBox* _tmp43_;
		AdwEntryRow* _tmp44_;
		AdwEntryRow* _tmp45_;
		_tmp40_ = row;
		_tmp41_ = graphs_fitting_parameter_box_get_lower_bound (_tmp40_);
		_tmp42_ = _tmp41_;
		gtk_widget_add_css_class ((GtkWidget*) _tmp42_, "error");
		_tmp43_ = row;
		_tmp44_ = graphs_fitting_parameter_box_get_upper_bound (_tmp43_);
		_tmp45_ = _tmp44_;
		gtk_widget_add_css_class ((GtkWidget*) _tmp45_, "error");
		graphs_curve_fitting_dialog_set_results (self, GRAPHS_CURVE_FITTING_ERROR_BOUNDS);
		_g_object_unref0 (widget);
		_g_object_unref0 (row);
		_g_object_unref0 (entry);
		return;
	}
	_tmp46_ = init;
	if (!((low <= _tmp46_) && (_tmp46_ <= high))) {
		GraphsFittingParameterBox* _tmp47_;
		AdwEntryRow* _tmp48_;
		AdwEntryRow* _tmp49_;
		_tmp47_ = row;
		_tmp48_ = graphs_fitting_parameter_box_get_initial (_tmp47_);
		_tmp49_ = _tmp48_;
		gtk_widget_add_css_class ((GtkWidget*) _tmp49_, "error");
		graphs_curve_fitting_dialog_set_results (self, GRAPHS_CURVE_FITTING_ERROR_BOUNDS);
		_g_object_unref0 (widget);
		_g_object_unref0 (row);
		_g_object_unref0 (entry);
		return;
	}
	_tmp50_ = row;
	_tmp51_ = graphs_fitting_parameter_box_get_param (_tmp50_);
	_tmp52_ = _tmp51_;
	_tmp53_ = _g_object_ref0 (_tmp52_);
	param = _tmp53_;
	_tmp54_ = param;
	graphs_fitting_parameter_set_initial (_tmp54_, init);
	_tmp55_ = param;
	graphs_fitting_parameter_set_lower_bound (_tmp55_, low);
	_tmp56_ = param;
	graphs_fitting_parameter_set_upper_bound (_tmp56_, high);
	graphs_python_helper_run_method ((GObject*) self, "_fit_curve");
	_g_object_unref0 (param);
	_g_object_unref0 (widget);
	_g_object_unref0 (row);
	_g_object_unref0 (entry);
}

static void
graphs_curve_fitting_dialog_update_bounds_visibility (GraphsCurveFittingDialog* self)
{
	gboolean visible = FALSE;
	GSettings* _tmp0_;
	GraphsFittingParameterBox* entry = NULL;
	GtkBox* _tmp1_;
	GtkWidget* _tmp2_;
	GraphsFittingParameterBox* _tmp3_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_settings;
	visible = g_settings_get_enum (_tmp0_, "optimization") > 0;
	_tmp1_ = self->priv->_fitting_params_box;
	_tmp2_ = gtk_widget_get_first_child ((GtkWidget*) _tmp1_);
	_tmp3_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp2_, GRAPHS_TYPE_FITTING_PARAMETER_BOX, GraphsFittingParameterBox));
	entry = _tmp3_;
	while (TRUE) {
		GraphsFittingParameterBox* _tmp4_;
		GraphsFittingParameterBox* _tmp5_;
		GraphsFittingParameterBox* _tmp6_;
		GtkWidget* _tmp7_;
		GraphsFittingParameterBox* _tmp8_;
		_tmp4_ = entry;
		if (!(_tmp4_ != NULL)) {
			break;
		}
		_tmp5_ = entry;
		graphs_fitting_parameter_box_set_bounds_visible (_tmp5_, visible);
		_tmp6_ = entry;
		_tmp7_ = gtk_widget_get_next_sibling ((GtkWidget*) _tmp6_);
		_tmp8_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp7_, GRAPHS_TYPE_FITTING_PARAMETER_BOX, GraphsFittingParameterBox));
		_g_object_unref0 (entry);
		entry = _tmp8_;
	}
	_g_object_unref0 (entry);
}

static void
graphs_curve_fitting_dialog_on_custom_equation_text_changed (GraphsCurveFittingDialog* self)
{
	AdwComboRow* _tmp0_;
	AdwEntryRow* _tmp1_;
	const gchar* _tmp2_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_equation;
	if (adw_combo_row_get_selected (_tmp0_) != ((guint) 7)) {
		return;
	}
	_tmp1_ = self->priv->_custom_equation;
	_tmp2_ = gtk_editable_get_text ((GtkEditable*) _tmp1_);
	if (graphs_curve_fitting_dialog_handle_new_equation (self, _tmp2_)) {
		AdwEntryRow* _tmp3_;
		_tmp3_ = self->priv->_custom_equation;
		gtk_widget_remove_css_class ((GtkWidget*) _tmp3_, "error");
	} else {
		AdwEntryRow* _tmp4_;
		_tmp4_ = self->priv->_custom_equation;
		gtk_widget_add_css_class ((GtkWidget*) _tmp4_, "error");
	}
}

static const gchar*
string_to_string (const gchar* self)
{
	const gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	result = self;
	return result;
}

static void
graphs_curve_fitting_dialog_set_equation_from_selection (GraphsCurveFittingDialog* self)
{
	gint selected = 0;
	AdwComboRow* _tmp0_;
	gchar* new_equation = NULL;
	const gchar* _tmp14_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_equation;
	selected = (gint) adw_combo_row_get_selected (_tmp0_);
	if (selected != 7) {
		const gchar* _tmp1_;
		gchar* _tmp2_;
		AdwComboRow* _tmp3_;
		const gchar* _tmp4_;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		gchar* _tmp7_;
		AdwEntryRow* _tmp8_;
		_tmp1_ = GRAPHS_EQUATIONS[selected];
		_tmp2_ = g_strdup (_tmp1_);
		_g_free0 (new_equation);
		new_equation = _tmp2_;
		_tmp3_ = self->priv->_equation;
		_tmp4_ = new_equation;
		_tmp5_ = string_to_string (_tmp4_);
		_tmp6_ = g_strconcat ("Y=", _tmp5_, NULL);
		_tmp7_ = _tmp6_;
		adw_action_row_set_subtitle ((AdwActionRow*) _tmp3_, _tmp7_);
		_g_free0 (_tmp7_);
		_tmp8_ = self->priv->_custom_equation;
		gtk_widget_set_visible ((GtkWidget*) _tmp8_, FALSE);
	} else {
		AdwEntryRow* _tmp9_;
		const gchar* _tmp10_;
		gchar* _tmp11_;
		AdwComboRow* _tmp12_;
		AdwEntryRow* _tmp13_;
		_tmp9_ = self->priv->_custom_equation;
		_tmp10_ = gtk_editable_get_text ((GtkEditable*) _tmp9_);
		_tmp11_ = g_strdup (_tmp10_);
		_g_free0 (new_equation);
		new_equation = _tmp11_;
		_tmp12_ = self->priv->_equation;
		adw_action_row_set_subtitle ((AdwActionRow*) _tmp12_, "");
		_tmp13_ = self->priv->_custom_equation;
		gtk_widget_set_visible ((GtkWidget*) _tmp13_, TRUE);
	}
	_tmp14_ = new_equation;
	graphs_curve_fitting_dialog_handle_new_equation (self, _tmp14_);
	_g_free0 (new_equation);
}

static void
_graphs_curve_fitting_dialog_on_entry_change_g_object_notify (GObject* _sender,
                                                              GParamSpec* pspec,
                                                              gpointer self)
{
	graphs_curve_fitting_dialog_on_entry_change ((GraphsCurveFittingDialog*) self, _sender, pspec);
}

static gboolean
graphs_curve_fitting_dialog_handle_new_equation (GraphsCurveFittingDialog* self,
                                                 const gchar* equation)
{
	GtkWidget* widget = NULL;
	gboolean _tmp46_ = FALSE;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (equation != NULL, FALSE);
	while (TRUE) {
		GtkBox* _tmp0_;
		GtkWidget* _tmp1_;
		GtkWidget* _tmp2_;
		GtkWidget* _tmp3_;
		GtkBox* _tmp4_;
		GtkWidget* _tmp5_;
		_tmp0_ = self->priv->_fitting_params_box;
		_tmp1_ = gtk_widget_get_last_child ((GtkWidget*) _tmp0_);
		_tmp2_ = _g_object_ref0 (_tmp1_);
		_g_object_unref0 (widget);
		widget = _tmp2_;
		_tmp3_ = widget;
		if (!(_tmp3_ != NULL)) {
			break;
		}
		_tmp4_ = self->priv->_fitting_params_box;
		_tmp5_ = widget;
		gtk_box_remove (_tmp4_, _tmp5_);
	}
	{
		gchar* _tmp6_ = NULL;
		gchar* _tmp7_;
		gchar** _tmp9_ = NULL;
		const gchar* _tmp10_;
		gint _tmp11_ = 0;
		gchar** _tmp12_;
		gint _tmp9__length1;
		gint __tmp9__size_;
		gchar** _tmp14_;
		gint _tmp14__length1;
		gchar** _tmp15_;
		gint _tmp15__length1;
		GeeHashMap* new_map = NULL;
		GeeHashMap* _tmp16_;
		GraphsFittingParameter* param = NULL;
		gboolean use_bounds = FALSE;
		GSettings* _tmp17_;
		gchar** _tmp18_;
		gint _tmp18__length1;
		GeeHashMap* _tmp44_;
		GeeMap* _tmp45_;
		_tmp7_ = graphs_preprocess_equation (equation, &_inner_error0_);
		_tmp6_ = _tmp7_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp8_ = FALSE;
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				goto __catch0_graphs_math_error;
			}
			_g_object_unref0 (widget);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp8_;
		}
		graphs_curve_fitting_dialog_set_equation_string (self, _tmp6_);
		_tmp10_ = self->priv->_equation_string;
		_tmp12_ = graphs_math_tools_get_free_variables (_tmp10_, &_tmp11_, &_inner_error0_);
		_tmp9_ = _tmp12_;
		_tmp9__length1 = _tmp11_;
		__tmp9__size_ = _tmp9__length1;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			gboolean _tmp13_ = FALSE;
			_g_free0 (_tmp6_);
			if (_inner_error0_->domain == GRAPHS_MATH_ERROR) {
				goto __catch0_graphs_math_error;
			}
			_g_object_unref0 (widget);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
			g_clear_error (&_inner_error0_);
			return _tmp13_;
		}
		_tmp14_ = _tmp9_;
		_tmp14__length1 = _tmp9__length1;
		_tmp9_ = NULL;
		_tmp9__length1 = 0;
		self->priv->free_vars = (_vala_array_free (self->priv->free_vars, self->priv->free_vars_length1, (GDestroyNotify) g_free), NULL);
		self->priv->free_vars = _tmp14_;
		self->priv->free_vars_length1 = _tmp14__length1;
		self->priv->_free_vars_size_ = self->priv->free_vars_length1;
		_tmp15_ = self->priv->free_vars;
		_tmp15__length1 = self->priv->free_vars_length1;
		if (_tmp15__length1 == 0) {
			graphs_curve_fitting_dialog_set_results (self, GRAPHS_CURVE_FITTING_ERROR_EQUATION);
			result = FALSE;
			_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (GDestroyNotify) g_free), NULL);
			_g_free0 (_tmp6_);
			_g_object_unref0 (widget);
			return result;
		}
		_tmp16_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GRAPHS_TYPE_FITTING_PARAMETER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
		new_map = _tmp16_;
		_tmp17_ = self->priv->_settings;
		use_bounds = g_settings_get_enum (_tmp17_, "optimization") > 0;
		_tmp18_ = self->priv->free_vars;
		_tmp18__length1 = self->priv->free_vars_length1;
		{
			gchar** variable_collection = NULL;
			gint variable_collection_length1 = 0;
			gint _variable_collection_size_ = 0;
			gint variable_it = 0;
			variable_collection = _tmp18_;
			variable_collection_length1 = _tmp18__length1;
			for (variable_it = 0; variable_it < variable_collection_length1; variable_it = variable_it + 1) {
				gchar* _tmp19_;
				gchar* variable = NULL;
				_tmp19_ = g_strdup (variable_collection[variable_it]);
				variable = _tmp19_;
				{
					GeeMap* _tmp20_;
					const gchar* _tmp21_;
					GraphsFittingParameterBox* p_box = NULL;
					GraphsFittingParameter* _tmp27_;
					GraphsFittingParameterBox* _tmp28_;
					GraphsFittingParameterBox* _tmp29_;
					GraphsFittingParameterBox* _tmp30_;
					AdwEntryRow* _tmp31_;
					AdwEntryRow* _tmp32_;
					GraphsFittingParameterBox* _tmp33_;
					AdwEntryRow* _tmp34_;
					AdwEntryRow* _tmp35_;
					GraphsFittingParameterBox* _tmp36_;
					AdwEntryRow* _tmp37_;
					AdwEntryRow* _tmp38_;
					GtkBox* _tmp39_;
					GraphsFittingParameterBox* _tmp40_;
					GeeHashMap* _tmp41_;
					const gchar* _tmp42_;
					GraphsFittingParameter* _tmp43_;
					_tmp20_ = self->priv->fitting_parameters;
					_tmp21_ = variable;
					if (gee_map_has_key (_tmp20_, _tmp21_)) {
						GeeMap* _tmp22_;
						const gchar* _tmp23_;
						gpointer _tmp24_;
						_tmp22_ = self->priv->fitting_parameters;
						_tmp23_ = variable;
						_tmp24_ = gee_map_get (_tmp22_, _tmp23_);
						_g_object_unref0 (param);
						param = (GraphsFittingParameter*) _tmp24_;
					} else {
						const gchar* _tmp25_;
						GraphsFittingParameter* _tmp26_;
						_tmp25_ = variable;
						_tmp26_ = graphs_fitting_parameter_new (_tmp25_);
						_g_object_unref0 (param);
						param = _tmp26_;
					}
					_tmp27_ = param;
					_tmp28_ = graphs_fitting_parameter_box_new (_tmp27_);
					g_object_ref_sink (_tmp28_);
					p_box = _tmp28_;
					_tmp29_ = p_box;
					graphs_fitting_parameter_box_set_bounds_visible (_tmp29_, use_bounds);
					_tmp30_ = p_box;
					_tmp31_ = graphs_fitting_parameter_box_get_initial (_tmp30_);
					_tmp32_ = _tmp31_;
					g_signal_connect_object ((GObject*) _tmp32_, "notify::text", (GCallback) _graphs_curve_fitting_dialog_on_entry_change_g_object_notify, self, 0);
					_tmp33_ = p_box;
					_tmp34_ = graphs_fitting_parameter_box_get_upper_bound (_tmp33_);
					_tmp35_ = _tmp34_;
					g_signal_connect_object ((GObject*) _tmp35_, "notify::text", (GCallback) _graphs_curve_fitting_dialog_on_entry_change_g_object_notify, self, 0);
					_tmp36_ = p_box;
					_tmp37_ = graphs_fitting_parameter_box_get_lower_bound (_tmp36_);
					_tmp38_ = _tmp37_;
					g_signal_connect_object ((GObject*) _tmp38_, "notify::text", (GCallback) _graphs_curve_fitting_dialog_on_entry_change_g_object_notify, self, 0);
					_tmp39_ = self->priv->_fitting_params_box;
					_tmp40_ = p_box;
					gtk_box_append (_tmp39_, (GtkWidget*) _tmp40_);
					_tmp41_ = new_map;
					_tmp42_ = variable;
					_tmp43_ = param;
					gee_abstract_map_set ((GeeAbstractMap*) _tmp41_, _tmp42_, _tmp43_);
					_g_object_unref0 (p_box);
					_g_free0 (variable);
				}
			}
		}
		_tmp44_ = new_map;
		_tmp45_ = _g_object_ref0 ((GeeMap*) _tmp44_);
		_g_object_unref0 (self->priv->fitting_parameters);
		self->priv->fitting_parameters = _tmp45_;
		graphs_python_helper_run_method ((GObject*) self, "_fit_curve");
		result = TRUE;
		_g_object_unref0 (param);
		_g_object_unref0 (new_map);
		_tmp9_ = (_vala_array_free (_tmp9_, _tmp9__length1, (GDestroyNotify) g_free), NULL);
		_g_free0 (_tmp6_);
		_g_object_unref0 (widget);
		return result;
	}
	goto __finally0;
	__catch0_graphs_math_error:
	{
		g_clear_error (&_inner_error0_);
		graphs_curve_fitting_dialog_set_results (self, GRAPHS_CURVE_FITTING_ERROR_EQUATION);
		result = FALSE;
		_g_object_unref0 (widget);
		return result;
	}
	__finally0:
	_g_object_unref0 (widget);
	g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
	g_clear_error (&_inner_error0_);
	return _tmp46_;
}

static void
graphs_curve_fitting_dialog_on_accept (GraphsCurveFittingDialog* self)
{
	GSettings* _tmp0_;
	AdwComboRow* _tmp1_;
	GSettings* _tmp2_;
	AdwEntryRow* _tmp3_;
	const gchar* _tmp4_;
	GraphsItem* item = NULL;
	GraphsWindow* _tmp5_;
	GraphsData* _tmp6_;
	GraphsData* _tmp7_;
	const gchar* _tmp8_;
	GraphsEquationItem* _tmp9_;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	gchar* _tmp12_;
	GraphsItem** items = NULL;
	GraphsItem* _tmp13_;
	GraphsItem** _tmp14_;
	gint items_length1;
	gint _items_size_;
	GraphsWindow* _tmp15_;
	GraphsData* _tmp16_;
	GraphsData* _tmp17_;
	GraphsWindow* _tmp18_;
	GraphsData* _tmp19_;
	GraphsData* _tmp20_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_settings;
	_tmp1_ = self->priv->_equation;
	g_settings_set_enum (_tmp0_, "equation", (gint) adw_combo_row_get_selected (_tmp1_));
	_tmp2_ = self->priv->_settings;
	_tmp3_ = self->priv->_custom_equation;
	_tmp4_ = gtk_editable_get_text ((GtkEditable*) _tmp3_);
	g_settings_set_string (_tmp2_, "custom-equation", _tmp4_);
	_tmp5_ = self->priv->_window;
	_tmp6_ = graphs_window_get_data (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = self->priv->_fitted_equation_string;
	_tmp9_ = graphs_item_factory_new_equation_item (_tmp7_, _tmp8_);
	item = (GraphsItem*) _tmp9_;
	_tmp10_ = self->priv->_fitted_equation_string;
	_tmp11_ = g_strconcat ("Y = ", _tmp10_, NULL);
	_tmp12_ = _tmp11_;
	graphs_item_set_name (item, _tmp12_);
	_g_free0 (_tmp12_);
	_tmp13_ = _g_object_ref0 (item);
	_tmp14_ = g_new0 (GraphsItem*, 1 + 1);
	_tmp14_[0] = _tmp13_;
	items = _tmp14_;
	items_length1 = 1;
	_items_size_ = items_length1;
	_tmp15_ = self->priv->_window;
	_tmp16_ = graphs_window_get_data (_tmp15_);
	_tmp17_ = _tmp16_;
	graphs_data_add_items (_tmp17_, items, (gint) items_length1);
	_tmp18_ = self->priv->_window;
	_tmp19_ = graphs_window_get_data (_tmp18_);
	_tmp20_ = _tmp19_;
	graphs_data_optimize_limits (_tmp20_);
	adw_dialog_close ((AdwDialog*) self);
	items = (_vala_array_free (items, items_length1, (GDestroyNotify) g_object_unref), NULL);
	_g_object_unref0 (item);
}

static void
_graphs_curve_fitting_dialog_on_accept_gtk_button_clicked (GtkButton* _sender,
                                                           gpointer self)
{
	graphs_curve_fitting_dialog_on_accept ((GraphsCurveFittingDialog*) self);
}

GraphsCurveFittingDialog*
graphs_curve_fitting_dialog_construct (GType object_type)
{
	GraphsCurveFittingDialog * self = NULL;
	self = (GraphsCurveFittingDialog*) g_object_new (object_type, NULL);
	return self;
}

GraphsCurveFittingDialog*
graphs_curve_fitting_dialog_new (void)
{
	return graphs_curve_fitting_dialog_construct (GRAPHS_TYPE_CURVE_FITTING_DIALOG);
}

static AdwComboRow*
graphs_curve_fitting_dialog_get_equation (GraphsCurveFittingDialog* self)
{
	AdwComboRow* result;
	AdwComboRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_equation;
	result = _tmp0_;
	return result;
}

static GtkButton*
graphs_curve_fitting_dialog_get_confirm_button (GraphsCurveFittingDialog* self)
{
	GtkButton* result;
	GtkButton* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_confirm_button;
	result = _tmp0_;
	return result;
}

static AdwEntryRow*
graphs_curve_fitting_dialog_get_custom_equation (GraphsCurveFittingDialog* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_custom_equation;
	result = _tmp0_;
	return result;
}

static GtkBox*
graphs_curve_fitting_dialog_get_fitting_params_box (GraphsCurveFittingDialog* self)
{
	GtkBox* result;
	GtkBox* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_fitting_params_box;
	result = _tmp0_;
	return result;
}

static GtkTextView*
graphs_curve_fitting_dialog_get_text_view (GraphsCurveFittingDialog* self)
{
	GtkTextView* result;
	GtkTextView* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_text_view;
	result = _tmp0_;
	return result;
}

static AdwToastOverlay*
graphs_curve_fitting_dialog_get_toast_overlay (GraphsCurveFittingDialog* self)
{
	AdwToastOverlay* result;
	AdwToastOverlay* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_toast_overlay;
	result = _tmp0_;
	return result;
}

static AdwOverlaySplitView*
graphs_curve_fitting_dialog_get_split_view (GraphsCurveFittingDialog* self)
{
	AdwOverlaySplitView* result;
	AdwOverlaySplitView* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_split_view;
	result = _tmp0_;
	return result;
}

static AdwBin*
graphs_curve_fitting_dialog_get_canvas_container (GraphsCurveFittingDialog* self)
{
	AdwBin* result;
	AdwBin* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_canvas_container;
	result = _tmp0_;
	return result;
}

static AdwBin*
graphs_curve_fitting_dialog_get_residuals_container (GraphsCurveFittingDialog* self)
{
	AdwBin* result;
	AdwBin* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_residuals_container;
	result = _tmp0_;
	return result;
}

GraphsWindow*
graphs_curve_fitting_dialog_get_window (GraphsCurveFittingDialog* self)
{
	GraphsWindow* result;
	GraphsWindow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_window;
	result = _tmp0_;
	return result;
}

void
graphs_curve_fitting_dialog_set_window (GraphsCurveFittingDialog* self,
                                        GraphsWindow* value)
{
	GraphsWindow* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_curve_fitting_dialog_get_window (self);
	if (old_value != value) {
		GraphsWindow* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_window);
		self->priv->_window = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_WINDOW_PROPERTY]);
	}
}

GSettings*
graphs_curve_fitting_dialog_get_settings (GraphsCurveFittingDialog* self)
{
	GSettings* result;
	GSettings* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_settings;
	result = _tmp0_;
	return result;
}

void
graphs_curve_fitting_dialog_set_settings (GraphsCurveFittingDialog* self,
                                          GSettings* value)
{
	GSettings* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_curve_fitting_dialog_get_settings (self);
	if (old_value != value) {
		GSettings* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_settings);
		self->priv->_settings = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_SETTINGS_PROPERTY]);
	}
}

const gchar*
graphs_curve_fitting_dialog_get_equation_string (GraphsCurveFittingDialog* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_equation_string;
	result = _tmp0_;
	return result;
}

static void
graphs_curve_fitting_dialog_set_equation_string (GraphsCurveFittingDialog* self,
                                                 const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_curve_fitting_dialog_get_equation_string (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_equation_string);
		self->priv->_equation_string = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_EQUATION_STRING_PROPERTY]);
	}
}

const gchar*
graphs_curve_fitting_dialog_get_fitted_equation_string (GraphsCurveFittingDialog* self)
{
	const gchar* result;
	const gchar* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_fitted_equation_string;
	result = _tmp0_;
	return result;
}

void
graphs_curve_fitting_dialog_set_fitted_equation_string (GraphsCurveFittingDialog* self,
                                                        const gchar* value)
{
	gchar* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_curve_fitting_dialog_get_fitted_equation_string (self);
	if (g_strcmp0 (value, old_value) != 0) {
		gchar* _tmp0_;
		_tmp0_ = g_strdup (value);
		_g_free0 (self->priv->_fitted_equation_string);
		self->priv->_fitted_equation_string = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_FITTED_EQUATION_STRING_PROPERTY]);
	}
}

GraphsFitResult*
graphs_curve_fitting_dialog_get_fit_result (GraphsCurveFittingDialog* self)
{
	GraphsFitResult* result;
	GraphsFitResult* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_fit_result;
	result = _tmp0_;
	return result;
}

void
graphs_curve_fitting_dialog_set_fit_result (GraphsCurveFittingDialog* self,
                                            GraphsFitResult* value)
{
	GraphsFitResult* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_curve_fitting_dialog_get_fit_result (self);
	if (old_value != value) {
		GraphsFitResult* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_fit_result);
		self->priv->_fit_result = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_FIT_RESULT_PROPERTY]);
	}
}

GraphsCanvas*
graphs_curve_fitting_dialog_get_canvas (GraphsCurveFittingDialog* self)
{
	GraphsCanvas* result;
	AdwBin* _tmp0_;
	GtkWidget* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_canvas_container;
	_tmp1_ = adw_bin_get_child (_tmp0_);
	result = GRAPHS_IS_CANVAS (_tmp1_) ? ((GraphsCanvas*) _tmp1_) : NULL;
	return result;
}

void
graphs_curve_fitting_dialog_set_canvas (GraphsCurveFittingDialog* self,
                                        GraphsCanvas* value)
{
	AdwBin* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_canvas_container;
	adw_bin_set_child (_tmp0_, (GtkWidget*) value);
	g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_CANVAS_PROPERTY]);
}

GraphsCanvas*
graphs_curve_fitting_dialog_get_residuals_canvas (GraphsCurveFittingDialog* self)
{
	GraphsCanvas* result;
	AdwBin* _tmp0_;
	GtkWidget* _tmp1_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_residuals_container;
	_tmp1_ = adw_bin_get_child (_tmp0_);
	result = GRAPHS_IS_CANVAS (_tmp1_) ? ((GraphsCanvas*) _tmp1_) : NULL;
	return result;
}

void
graphs_curve_fitting_dialog_set_residuals_canvas (GraphsCurveFittingDialog* self,
                                                  GraphsCanvas* value)
{
	AdwBin* _tmp0_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_residuals_container;
	adw_bin_set_child (_tmp0_, (GtkWidget*) value);
	g_object_notify_by_pspec ((GObject *) self, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_RESIDUALS_CANVAS_PROPERTY]);
}

static void
_graphs_curve_fitting_dialog___lambda18_ (GraphsCurveFittingDialog* self)
{
	GraphsFitResult* _tmp0_;
	_tmp0_ = self->priv->_fit_result;
	if (_tmp0_ == NULL) {
		return;
	}
	graphs_python_helper_run_method ((GObject*) self, "_fit_curve");
}

static void
__graphs_curve_fitting_dialog___lambda18__g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	_graphs_curve_fitting_dialog___lambda18_ ((GraphsCurveFittingDialog*) self);
}

static void
_graphs_curve_fitting_dialog___lambda19_ (GraphsCurveFittingDialog* self)
{
	graphs_curve_fitting_dialog_update_bounds_visibility (self);
	graphs_python_helper_run_method ((GObject*) self, "_fit_curve");
}

static void
__graphs_curve_fitting_dialog___lambda19__g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	_graphs_curve_fitting_dialog___lambda19_ ((GraphsCurveFittingDialog*) self);
}

static void
_graphs_curve_fitting_dialog___lambda20_ (GraphsCurveFittingDialog* self)
{
	gboolean show_residuals = FALSE;
	GSettings* _tmp0_;
	gboolean _tmp1_ = FALSE;
	AdwBin* _tmp4_;
	_tmp0_ = self->priv->_settings;
	show_residuals = g_settings_get_boolean (_tmp0_, "show-residuals");
	if (show_residuals) {
		GraphsCanvas* _tmp2_;
		GraphsCanvas* _tmp3_;
		_tmp2_ = graphs_curve_fitting_dialog_get_residuals_canvas (self);
		_tmp3_ = _tmp2_;
		_tmp1_ = _tmp3_ != NULL;
	} else {
		_tmp1_ = FALSE;
	}
	_tmp4_ = self->priv->_residuals_container;
	gtk_widget_set_visible ((GtkWidget*) _tmp4_, _tmp1_);
}

static void
__graphs_curve_fitting_dialog___lambda20__g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	_graphs_curve_fitting_dialog___lambda20_ ((GraphsCurveFittingDialog*) self);
}

static void
_graphs_curve_fitting_dialog___lambda21_ (GraphsCurveFittingDialog* self)
{
	AdwOverlaySplitView* _tmp0_;
	AdwOverlaySplitView* _tmp1_;
	gboolean _tmp2_;
	gboolean _tmp3_;
	_tmp0_ = self->priv->_split_view;
	_tmp1_ = self->priv->_split_view;
	_tmp2_ = adw_overlay_split_view_get_show_sidebar (_tmp1_);
	_tmp3_ = _tmp2_;
	adw_overlay_split_view_set_show_sidebar (_tmp0_, !_tmp3_);
}

static void
__graphs_curve_fitting_dialog___lambda21__g_simple_action_activate (GSimpleAction* _sender,
                                                                    GVariant* parameter,
                                                                    gpointer self)
{
	_graphs_curve_fitting_dialog___lambda21_ ((GraphsCurveFittingDialog*) self);
}

static void
_graphs_curve_fitting_dialog_set_equation_from_selection_g_object_notify (GObject* _sender,
                                                                          GParamSpec* pspec,
                                                                          gpointer self)
{
	graphs_curve_fitting_dialog_set_equation_from_selection ((GraphsCurveFittingDialog*) self);
}

static void
_graphs_curve_fitting_dialog_on_custom_equation_text_changed_g_object_notify (GObject* _sender,
                                                                              GParamSpec* pspec,
                                                                              gpointer self)
{
	graphs_curve_fitting_dialog_on_custom_equation_text_changed ((GraphsCurveFittingDialog*) self);
}

static void
_graphs_curve_fitting_dialog___lambda22_ (GraphsCurveFittingDialog* self)
{
	graphs_python_helper_run_method ((GObject*) self, "_load_canvas");
}

static void
__graphs_curve_fitting_dialog___lambda22__g_object_notify (GObject* _sender,
                                                           GParamSpec* pspec,
                                                           gpointer self)
{
	_graphs_curve_fitting_dialog___lambda22_ ((GraphsCurveFittingDialog*) self);
}

static GObject *
graphs_curve_fitting_dialog_constructor (GType type,
                                         guint n_construct_properties,
                                         GObjectConstructParam * construct_properties)
{
	GObject * obj;
	GObjectClass * parent_class;
	GraphsCurveFittingDialog * self;
	GeeHashMap* _tmp0_;
	GSettings* _tmp1_;
	GSettings* _tmp2_;
	GSimpleActionGroup* action_map = NULL;
	GSimpleActionGroup* _tmp3_;
	GAction* confidence_action = NULL;
	GSettings* _tmp4_;
	GAction* _tmp5_;
	GAction* _tmp6_;
	GSimpleActionGroup* _tmp7_;
	GAction* _tmp8_;
	GAction* optimization_action = NULL;
	GSettings* _tmp9_;
	GAction* _tmp10_;
	GAction* _tmp11_;
	GSimpleActionGroup* _tmp12_;
	GAction* _tmp13_;
	GAction* res_action = NULL;
	GSettings* _tmp14_;
	GAction* _tmp15_;
	GAction* _tmp16_;
	GSimpleActionGroup* _tmp17_;
	GAction* _tmp18_;
	gboolean show_residuals = FALSE;
	GSettings* _tmp19_;
	gboolean _tmp20_ = FALSE;
	AdwBin* _tmp23_;
	GSimpleAction* toggle_sidebar_action = NULL;
	GSimpleAction* _tmp24_;
	GSimpleAction* _tmp25_;
	AdwOverlaySplitView* _tmp26_;
	GSimpleAction* _tmp27_;
	GSimpleActionGroup* _tmp28_;
	GSimpleAction* _tmp29_;
	GSimpleActionGroup* _tmp30_;
	AdwEntryRow* _tmp31_;
	GSettings* _tmp32_;
	gchar* _tmp33_;
	gchar* _tmp34_;
	AdwComboRow* _tmp35_;
	GSettings* _tmp36_;
	AdwComboRow* _tmp37_;
	AdwEntryRow* _tmp38_;
	AdwStyleManager* _tmp39_;
	parent_class = G_OBJECT_CLASS (graphs_curve_fitting_dialog_parent_class);
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_CURVE_FITTING_DIALOG, GraphsCurveFittingDialog);
	_tmp0_ = gee_hash_map_new (G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, GRAPHS_TYPE_FITTING_PARAMETER, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	_g_object_unref0 (self->priv->fitting_parameters);
	self->priv->fitting_parameters = (GeeMap*) _tmp0_;
	graphs_curve_fitting_dialog_set_fit_result (self, NULL);
	_tmp1_ = graphs_application_get_settings_child ("curve-fitting");
	_tmp2_ = _tmp1_;
	graphs_curve_fitting_dialog_set_settings (self, _tmp2_);
	_g_object_unref0 (_tmp2_);
	_tmp3_ = g_simple_action_group_new ();
	action_map = _tmp3_;
	_tmp4_ = self->priv->_settings;
	_tmp5_ = g_settings_create_action (_tmp4_, "confidence");
	confidence_action = _tmp5_;
	_tmp6_ = confidence_action;
	g_signal_connect_object ((GObject*) _tmp6_, "notify", (GCallback) __graphs_curve_fitting_dialog___lambda18__g_object_notify, self, 0);
	_tmp7_ = action_map;
	_tmp8_ = confidence_action;
	g_action_map_add_action ((GActionMap*) _tmp7_, _tmp8_);
	_tmp9_ = self->priv->_settings;
	_tmp10_ = g_settings_create_action (_tmp9_, "optimization");
	optimization_action = _tmp10_;
	_tmp11_ = optimization_action;
	g_signal_connect_object ((GObject*) _tmp11_, "notify", (GCallback) __graphs_curve_fitting_dialog___lambda19__g_object_notify, self, 0);
	_tmp12_ = action_map;
	_tmp13_ = optimization_action;
	g_action_map_add_action ((GActionMap*) _tmp12_, _tmp13_);
	_tmp14_ = self->priv->_settings;
	_tmp15_ = g_settings_create_action (_tmp14_, "show-residuals");
	res_action = _tmp15_;
	_tmp16_ = res_action;
	g_signal_connect_object ((GObject*) _tmp16_, "notify", (GCallback) __graphs_curve_fitting_dialog___lambda20__g_object_notify, self, 0);
	_tmp17_ = action_map;
	_tmp18_ = res_action;
	g_action_map_add_action ((GActionMap*) _tmp17_, _tmp18_);
	_tmp19_ = self->priv->_settings;
	show_residuals = g_settings_get_boolean (_tmp19_, "show-residuals");
	if (show_residuals) {
		GraphsCanvas* _tmp21_;
		GraphsCanvas* _tmp22_;
		_tmp21_ = graphs_curve_fitting_dialog_get_residuals_canvas (self);
		_tmp22_ = _tmp21_;
		_tmp20_ = _tmp22_ != NULL;
	} else {
		_tmp20_ = FALSE;
	}
	_tmp23_ = self->priv->_residuals_container;
	gtk_widget_set_visible ((GtkWidget*) _tmp23_, _tmp20_);
	_tmp24_ = g_simple_action_new ("toggle_sidebar", NULL);
	toggle_sidebar_action = _tmp24_;
	_tmp25_ = toggle_sidebar_action;
	g_signal_connect_object (_tmp25_, "activate", (GCallback) __graphs_curve_fitting_dialog___lambda21__g_simple_action_activate, self, 0);
	_tmp26_ = self->priv->_split_view;
	_tmp27_ = toggle_sidebar_action;
	g_object_bind_property_with_closures ((GObject*) _tmp26_, "collapsed", (GObject*) _tmp27_, "enabled", G_BINDING_SYNC_CREATE, (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)), (GClosure*) ((NULL == NULL) ? NULL : g_cclosure_new ((GCallback) NULL, NULL, (GClosureNotify) NULL)));
	_tmp28_ = action_map;
	_tmp29_ = toggle_sidebar_action;
	g_action_map_add_action ((GActionMap*) _tmp28_, (GAction*) _tmp29_);
	_tmp30_ = action_map;
	gtk_widget_insert_action_group ((GtkWidget*) self, "win", (GActionGroup*) _tmp30_);
	_tmp31_ = self->priv->_custom_equation;
	_tmp32_ = self->priv->_settings;
	_tmp33_ = g_settings_get_string (_tmp32_, "custom-equation");
	_tmp34_ = _tmp33_;
	gtk_editable_set_text ((GtkEditable*) _tmp31_, _tmp34_);
	_g_free0 (_tmp34_);
	_tmp35_ = self->priv->_equation;
	_tmp36_ = self->priv->_settings;
	adw_combo_row_set_selected (_tmp35_, (guint) g_settings_get_enum (_tmp36_, "equation"));
	_tmp37_ = self->priv->_equation;
	g_signal_connect_object ((GObject*) _tmp37_, "notify::selected", (GCallback) _graphs_curve_fitting_dialog_set_equation_from_selection_g_object_notify, self, 0);
	_tmp38_ = self->priv->_custom_equation;
	g_signal_connect_object ((GObject*) _tmp38_, "notify::text", (GCallback) _graphs_curve_fitting_dialog_on_custom_equation_text_changed_g_object_notify, self, 0);
	graphs_python_helper_run_method ((GObject*) self, "_load_canvas");
	_tmp39_ = adw_style_manager_get_default ();
	g_signal_connect_object ((GObject*) _tmp39_, "notify", (GCallback) __graphs_curve_fitting_dialog___lambda22__g_object_notify, self, 0);
	graphs_curve_fitting_dialog_set_equation_from_selection (self);
	_g_object_unref0 (toggle_sidebar_action);
	_g_object_unref0 (res_action);
	_g_object_unref0 (optimization_action);
	_g_object_unref0 (confidence_action);
	_g_object_unref0 (action_map);
	return obj;
}

static void
graphs_curve_fitting_dialog_class_init (GraphsCurveFittingDialogClass * klass,
                                        gpointer klass_data)
{
	graphs_curve_fitting_dialog_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsCurveFittingDialog_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_curve_fitting_dialog_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_graphs_curve_fitting_dialog_set_property;
	G_OBJECT_CLASS (klass)->constructor = graphs_curve_fitting_dialog_constructor;
	G_OBJECT_CLASS (klass)->finalize = graphs_curve_fitting_dialog_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_WINDOW_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_WINDOW_PROPERTY] = g_param_spec_object ("window", "window", "window", GRAPHS_TYPE_WINDOW, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_SETTINGS_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_SETTINGS_PROPERTY] = g_param_spec_object ("settings", "settings", "settings", g_settings_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_EQUATION_STRING_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_EQUATION_STRING_PROPERTY] = g_param_spec_string ("equation-string", "equation-string", "equation-string", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_FITTED_EQUATION_STRING_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_FITTED_EQUATION_STRING_PROPERTY] = g_param_spec_string ("fitted-equation-string", "fitted-equation-string", "fitted-equation-string", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_FIT_RESULT_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_FIT_RESULT_PROPERTY] = g_param_spec_object ("fit-result", "fit-result", "fit-result", GRAPHS_TYPE_FIT_RESULT, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_CANVAS_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_CANVAS_PROPERTY] = g_param_spec_object ("canvas", "canvas", "canvas", GRAPHS_TYPE_CANVAS, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_CURVE_FITTING_DIALOG_RESIDUALS_CANVAS_PROPERTY, graphs_curve_fitting_dialog_properties[GRAPHS_CURVE_FITTING_DIALOG_RESIDUALS_CANVAS_PROPERTY] = g_param_spec_object ("residuals-canvas", "residuals-canvas", "residuals-canvas", GRAPHS_TYPE_CANVAS, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/se/sjoerd/Graphs/ui/curve-fitting.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "equation", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _equation));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "confirm_button", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _confirm_button));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "custom_equation", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _custom_equation));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "fitting_params_box", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _fitting_params_box));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "text_view", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _text_view));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "toast_overlay", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _toast_overlay));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "split_view", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _split_view));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "canvas_container", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _canvas_container));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "residuals_container", FALSE, GraphsCurveFittingDialog_private_offset + G_STRUCT_OFFSET (GraphsCurveFittingDialogPrivate, _residuals_container));
	gtk_widget_class_bind_template_callback_full (GTK_WIDGET_CLASS (klass), "on_accept", G_CALLBACK(_graphs_curve_fitting_dialog_on_accept_gtk_button_clicked));
}

static void
graphs_curve_fitting_dialog_instance_init (GraphsCurveFittingDialog * self,
                                           gpointer klass)
{
	gchar** _tmp0_;
	self->priv = graphs_curve_fitting_dialog_get_instance_private (self);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->priv->free_vars = _tmp0_;
	self->priv->free_vars_length1 = 0;
	self->priv->_free_vars_size_ = self->priv->free_vars_length1;
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
graphs_curve_fitting_dialog_finalize (GObject * obj)
{
	GraphsCurveFittingDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_CURVE_FITTING_DIALOG, GraphsCurveFittingDialog);
	_g_object_unref0 (self->priv->_window);
	_g_object_unref0 (self->priv->_settings);
	_g_free0 (self->priv->_equation_string);
	_g_free0 (self->priv->_fitted_equation_string);
	_g_object_unref0 (self->priv->_fit_result);
	_g_object_unref0 (self->priv->fitting_parameters);
	self->priv->free_vars = (_vala_array_free (self->priv->free_vars, self->priv->free_vars_length1, (GDestroyNotify) g_free), NULL);
	G_OBJECT_CLASS (graphs_curve_fitting_dialog_parent_class)->finalize (obj);
}

/**
     * Curve fitting dialog.
     */
static GType
graphs_curve_fitting_dialog_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsCurveFittingDialogClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_curve_fitting_dialog_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsCurveFittingDialog), 0, (GInstanceInitFunc) graphs_curve_fitting_dialog_instance_init, NULL };
	GType graphs_curve_fitting_dialog_type_id;
	graphs_curve_fitting_dialog_type_id = g_type_register_static (adw_dialog_get_type (), "GraphsCurveFittingDialog", &g_define_type_info, 0);
	GraphsCurveFittingDialog_private_offset = g_type_add_instance_private (graphs_curve_fitting_dialog_type_id, sizeof (GraphsCurveFittingDialogPrivate));
	return graphs_curve_fitting_dialog_type_id;
}

GType
graphs_curve_fitting_dialog_get_type (void)
{
	static volatile gsize graphs_curve_fitting_dialog_type_id__once = 0;
	if (g_once_init_enter (&graphs_curve_fitting_dialog_type_id__once)) {
		GType graphs_curve_fitting_dialog_type_id;
		graphs_curve_fitting_dialog_type_id = graphs_curve_fitting_dialog_get_type_once ();
		g_once_init_leave (&graphs_curve_fitting_dialog_type_id__once, graphs_curve_fitting_dialog_type_id);
	}
	return graphs_curve_fitting_dialog_type_id__once;
}

static void
_vala_graphs_curve_fitting_dialog_get_property (GObject * object,
                                                guint property_id,
                                                GValue * value,
                                                GParamSpec * pspec)
{
	GraphsCurveFittingDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_CURVE_FITTING_DIALOG, GraphsCurveFittingDialog);
	switch (property_id) {
		case GRAPHS_CURVE_FITTING_DIALOG_WINDOW_PROPERTY:
		g_value_set_object (value, graphs_curve_fitting_dialog_get_window (self));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_SETTINGS_PROPERTY:
		g_value_set_object (value, graphs_curve_fitting_dialog_get_settings (self));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_EQUATION_STRING_PROPERTY:
		g_value_set_string (value, graphs_curve_fitting_dialog_get_equation_string (self));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_FITTED_EQUATION_STRING_PROPERTY:
		g_value_set_string (value, graphs_curve_fitting_dialog_get_fitted_equation_string (self));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_FIT_RESULT_PROPERTY:
		g_value_set_object (value, graphs_curve_fitting_dialog_get_fit_result (self));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_CANVAS_PROPERTY:
		g_value_set_object (value, graphs_curve_fitting_dialog_get_canvas (self));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_RESIDUALS_CANVAS_PROPERTY:
		g_value_set_object (value, graphs_curve_fitting_dialog_get_residuals_canvas (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_graphs_curve_fitting_dialog_set_property (GObject * object,
                                                guint property_id,
                                                const GValue * value,
                                                GParamSpec * pspec)
{
	GraphsCurveFittingDialog * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_CURVE_FITTING_DIALOG, GraphsCurveFittingDialog);
	switch (property_id) {
		case GRAPHS_CURVE_FITTING_DIALOG_WINDOW_PROPERTY:
		graphs_curve_fitting_dialog_set_window (self, g_value_get_object (value));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_SETTINGS_PROPERTY:
		graphs_curve_fitting_dialog_set_settings (self, g_value_get_object (value));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_EQUATION_STRING_PROPERTY:
		graphs_curve_fitting_dialog_set_equation_string (self, g_value_get_string (value));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_FITTED_EQUATION_STRING_PROPERTY:
		graphs_curve_fitting_dialog_set_fitted_equation_string (self, g_value_get_string (value));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_FIT_RESULT_PROPERTY:
		graphs_curve_fitting_dialog_set_fit_result (self, g_value_get_object (value));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_CANVAS_PROPERTY:
		graphs_curve_fitting_dialog_set_canvas (self, g_value_get_object (value));
		break;
		case GRAPHS_CURVE_FITTING_DIALOG_RESIDUALS_CANVAS_PROPERTY:
		graphs_curve_fitting_dialog_set_residuals_canvas (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
graphs_fitting_parameter_box_get_instance_private (GraphsFittingParameterBox* self)
{
	return G_STRUCT_MEMBER_P (self, GraphsFittingParameterBox_private_offset);
}

static gchar*
double_to_string (gdouble self)
{
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint _tmp1__length1;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* result;
	_tmp0_ = g_new0 (gchar, G_ASCII_DTOSTR_BUF_SIZE);
	_tmp1_ = _tmp0_;
	_tmp1__length1 = G_ASCII_DTOSTR_BUF_SIZE;
	_tmp2_ = g_ascii_dtostr (_tmp1_, (gint) G_ASCII_DTOSTR_BUF_SIZE, self);
	_tmp3_ = g_strdup (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp1_ = (g_free (_tmp1_), NULL);
	result = _tmp4_;
	return result;
}

GraphsFittingParameterBox*
graphs_fitting_parameter_box_construct (GType object_type,
                                        GraphsFittingParameter* param)
{
	GraphsFittingParameterBox * self = NULL;
	gchar* msg = NULL;
	const gchar* _tmp0_;
	const gchar* _tmp1_;
	gchar* _tmp2_;
	GtkLabel* _tmp3_;
	const gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* _tmp6_;
	AdwEntryRow* _tmp7_;
	gdouble _tmp8_;
	gdouble _tmp9_;
	gchar* _tmp10_;
	gchar* _tmp11_;
	g_return_val_if_fail (param != NULL, NULL);
	self = (GraphsFittingParameterBox*) g_object_new (object_type, NULL);
	graphs_fitting_parameter_box_set_param (self, param);
	_tmp0_ = graphs_fitting_parameter_get_name (param);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_strdup_printf (_ ("Fitting Parameters for %s"), _tmp1_);
	msg = _tmp2_;
	_tmp3_ = self->priv->_label;
	_tmp4_ = string_to_string (msg);
	_tmp5_ = g_strconcat ("<b> ", _tmp4_, ": </b>", NULL);
	_tmp6_ = _tmp5_;
	gtk_label_set_markup (_tmp3_, _tmp6_);
	_g_free0 (_tmp6_);
	_tmp7_ = self->priv->_initial;
	_tmp8_ = graphs_fitting_parameter_get_initial (param);
	_tmp9_ = _tmp8_;
	_tmp10_ = double_to_string (_tmp9_);
	_tmp11_ = _tmp10_;
	gtk_editable_set_text ((GtkEditable*) _tmp7_, _tmp11_);
	_g_free0 (_tmp11_);
	_g_free0 (msg);
	return self;
}

GraphsFittingParameterBox*
graphs_fitting_parameter_box_new (GraphsFittingParameter* param)
{
	return graphs_fitting_parameter_box_construct (GRAPHS_TYPE_FITTING_PARAMETER_BOX, param);
}

void
graphs_fitting_parameter_box_set_bounds_visible (GraphsFittingParameterBox* self,
                                                 gboolean visible)
{
	AdwEntryRow* _tmp0_;
	AdwEntryRow* _tmp1_;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->_upper_bound;
	gtk_widget_set_visible ((GtkWidget*) _tmp0_, visible);
	_tmp1_ = self->priv->_lower_bound;
	gtk_widget_set_visible ((GtkWidget*) _tmp1_, visible);
}

static GtkLabel*
graphs_fitting_parameter_box_get_label (GraphsFittingParameterBox* self)
{
	GtkLabel* result;
	GtkLabel* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_label;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_fitting_parameter_box_get_initial (GraphsFittingParameterBox* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_initial;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_fitting_parameter_box_get_upper_bound (GraphsFittingParameterBox* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_upper_bound;
	result = _tmp0_;
	return result;
}

AdwEntryRow*
graphs_fitting_parameter_box_get_lower_bound (GraphsFittingParameterBox* self)
{
	AdwEntryRow* result;
	AdwEntryRow* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_lower_bound;
	result = _tmp0_;
	return result;
}

GraphsFittingParameter*
graphs_fitting_parameter_box_get_param (GraphsFittingParameterBox* self)
{
	GraphsFittingParameter* result;
	GraphsFittingParameter* _tmp0_;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = self->priv->_param;
	result = _tmp0_;
	return result;
}

void
graphs_fitting_parameter_box_set_param (GraphsFittingParameterBox* self,
                                        GraphsFittingParameter* value)
{
	GraphsFittingParameter* old_value;
	g_return_if_fail (self != NULL);
	old_value = graphs_fitting_parameter_box_get_param (self);
	if (old_value != value) {
		GraphsFittingParameter* _tmp0_;
		_tmp0_ = _g_object_ref0 (value);
		_g_object_unref0 (self->priv->_param);
		self->priv->_param = _tmp0_;
		g_object_notify_by_pspec ((GObject *) self, graphs_fitting_parameter_box_properties[GRAPHS_FITTING_PARAMETER_BOX_PARAM_PROPERTY]);
	}
}

static void
graphs_fitting_parameter_box_class_init (GraphsFittingParameterBoxClass * klass,
                                         gpointer klass_data)
{
	graphs_fitting_parameter_box_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &GraphsFittingParameterBox_private_offset);
	G_OBJECT_CLASS (klass)->get_property = _vala_graphs_fitting_parameter_box_get_property;
	G_OBJECT_CLASS (klass)->set_property = _vala_graphs_fitting_parameter_box_set_property;
	G_OBJECT_CLASS (klass)->finalize = graphs_fitting_parameter_box_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_FITTING_PARAMETER_BOX_INITIAL_PROPERTY, graphs_fitting_parameter_box_properties[GRAPHS_FITTING_PARAMETER_BOX_INITIAL_PROPERTY] = g_param_spec_object ("initial", "initial", "initial", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_FITTING_PARAMETER_BOX_UPPER_BOUND_PROPERTY, graphs_fitting_parameter_box_properties[GRAPHS_FITTING_PARAMETER_BOX_UPPER_BOUND_PROPERTY] = g_param_spec_object ("upper-bound", "upper-bound", "upper-bound", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_FITTING_PARAMETER_BOX_LOWER_BOUND_PROPERTY, graphs_fitting_parameter_box_properties[GRAPHS_FITTING_PARAMETER_BOX_LOWER_BOUND_PROPERTY] = g_param_spec_object ("lower-bound", "lower-bound", "lower-bound", adw_entry_row_get_type (), G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), GRAPHS_FITTING_PARAMETER_BOX_PARAM_PROPERTY, graphs_fitting_parameter_box_properties[GRAPHS_FITTING_PARAMETER_BOX_PARAM_PROPERTY] = g_param_spec_object ("param", "param", "param", GRAPHS_TYPE_FITTING_PARAMETER, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
	gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass), "/se/sjoerd/Graphs/ui/fitting-parameters.ui");
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "label", FALSE, GraphsFittingParameterBox_private_offset + G_STRUCT_OFFSET (GraphsFittingParameterBoxPrivate, _label));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "initial", FALSE, GraphsFittingParameterBox_private_offset + G_STRUCT_OFFSET (GraphsFittingParameterBoxPrivate, _initial));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "upper_bound", FALSE, GraphsFittingParameterBox_private_offset + G_STRUCT_OFFSET (GraphsFittingParameterBoxPrivate, _upper_bound));
	gtk_widget_class_bind_template_child_full (GTK_WIDGET_CLASS (klass), "lower_bound", FALSE, GraphsFittingParameterBox_private_offset + G_STRUCT_OFFSET (GraphsFittingParameterBoxPrivate, _lower_bound));
}

static void
graphs_fitting_parameter_box_instance_init (GraphsFittingParameterBox * self,
                                            gpointer klass)
{
	self->priv = graphs_fitting_parameter_box_get_instance_private (self);
	gtk_widget_init_template (GTK_WIDGET (self));
}

static void
graphs_fitting_parameter_box_finalize (GObject * obj)
{
	GraphsFittingParameterBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, GRAPHS_TYPE_FITTING_PARAMETER_BOX, GraphsFittingParameterBox);
	_g_object_unref0 (self->priv->_param);
	G_OBJECT_CLASS (graphs_fitting_parameter_box_parent_class)->finalize (obj);
}

static GType
graphs_fitting_parameter_box_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (GraphsFittingParameterBoxClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) graphs_fitting_parameter_box_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (GraphsFittingParameterBox), 0, (GInstanceInitFunc) graphs_fitting_parameter_box_instance_init, NULL };
	GType graphs_fitting_parameter_box_type_id;
	graphs_fitting_parameter_box_type_id = g_type_register_static (gtk_box_get_type (), "GraphsFittingParameterBox", &g_define_type_info, 0);
	GraphsFittingParameterBox_private_offset = g_type_add_instance_private (graphs_fitting_parameter_box_type_id, sizeof (GraphsFittingParameterBoxPrivate));
	return graphs_fitting_parameter_box_type_id;
}

GType
graphs_fitting_parameter_box_get_type (void)
{
	static volatile gsize graphs_fitting_parameter_box_type_id__once = 0;
	if (g_once_init_enter (&graphs_fitting_parameter_box_type_id__once)) {
		GType graphs_fitting_parameter_box_type_id;
		graphs_fitting_parameter_box_type_id = graphs_fitting_parameter_box_get_type_once ();
		g_once_init_leave (&graphs_fitting_parameter_box_type_id__once, graphs_fitting_parameter_box_type_id);
	}
	return graphs_fitting_parameter_box_type_id__once;
}

static void
_vala_graphs_fitting_parameter_box_get_property (GObject * object,
                                                 guint property_id,
                                                 GValue * value,
                                                 GParamSpec * pspec)
{
	GraphsFittingParameterBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_FITTING_PARAMETER_BOX, GraphsFittingParameterBox);
	switch (property_id) {
		case GRAPHS_FITTING_PARAMETER_BOX_INITIAL_PROPERTY:
		g_value_set_object (value, graphs_fitting_parameter_box_get_initial (self));
		break;
		case GRAPHS_FITTING_PARAMETER_BOX_UPPER_BOUND_PROPERTY:
		g_value_set_object (value, graphs_fitting_parameter_box_get_upper_bound (self));
		break;
		case GRAPHS_FITTING_PARAMETER_BOX_LOWER_BOUND_PROPERTY:
		g_value_set_object (value, graphs_fitting_parameter_box_get_lower_bound (self));
		break;
		case GRAPHS_FITTING_PARAMETER_BOX_PARAM_PROPERTY:
		g_value_set_object (value, graphs_fitting_parameter_box_get_param (self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_graphs_fitting_parameter_box_set_property (GObject * object,
                                                 guint property_id,
                                                 const GValue * value,
                                                 GParamSpec * pspec)
{
	GraphsFittingParameterBox * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, GRAPHS_TYPE_FITTING_PARAMETER_BOX, GraphsFittingParameterBox);
	switch (property_id) {
		case GRAPHS_FITTING_PARAMETER_BOX_PARAM_PROPERTY:
		graphs_fitting_parameter_box_set_param (self, g_value_get_object (value));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

