<commit_before>/* ENESIM - Direct Rendering Library
 * Copyright (C) 2007-2011 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "enesim_private.h"

#include "enesim_main.h"
#include "enesim_eina.h"
#include "enesim_path.h"
#include "enesim_path_normalizer_private.h"

typedef struct _Enesim_Path_Normalizer_State
{
	double last_x;
	double last_y;
	double last_ctrl_x;
	double last_ctrl_y;
} Enesim_Path_Normalizer_State;

typedef void (*Enesim_Path_Normalizer_Move_To_Cb)(Enesim_Path_Command_Move_To *move_to,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Line_To_Cb)(Enesim_Path_Command_Line_To *line_to,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Cubic_To_Cb)(Enesim_Path_Command_Cubic_To *cubic_to,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Close_Cb)(Enesim_Path_Command_Close *close,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Free_Cb)(void *data);

typedef struct _Enesim_Path_Normalizer_Descriptor
{
	Enesim_Path_Normalizer_Move_To_Cb move_to;
	Enesim_Path_Normalizer_Line_To_Cb line_to;
	Enesim_Path_Normalizer_Cubic_To_Cb cubic_to;
	Enesim_Path_Normalizer_Close_Cb close;
	Enesim_Path_Normalizer_Free_Cb free;
} Enesim_Path_Normalizer_Descriptor;

struct _Enesim_Path_Normalizer
{
	Enesim_Path_Normalizer_Descriptor *descriptor;
	Enesim_Path_Normalizer_State state;
	void *data;
};

typedef struct _Enesim_Path_Normalizer_Figure
{
	Enesim_Path_Normalizer_Figure_Descriptor *descriptor;
	void *data;
} Enesim_Path_Normalizer_Figure;

typedef struct _Enesim_Path_Normalizer_Path
{
	Enesim_Path_Normalizer_Path_Descriptor *descriptor;
	void *data;
} Enesim_Path_Normalizer_Path;
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
#if 0
/* these subdiv approximations need to be done more carefully */
void enesim_curve_quadratic_to(Enesim_Curve_State *state,
		double ctrl_x, double ctrl_y,
		double x, double y)
{
	_curve_quadratic_to(state, ctrl_x, ctrl_y, x, y);
	state->last_x = x;
	state->last_y = y;
	state->last_ctrl_x = ctrl_x;
	state->last_ctrl_y = ctrl_y;
}

void enesim_curve_squadratic_to(Enesim_Curve_State *state,
		double x, double y)
{
	double x0, y0, cx0, cy0;

	x0 = state->last_x;
	y0 = state->last_y;
	cx0 = state->last_ctrl_x;
	cy0 = state->last_ctrl_y;
	cx0 = (2 * x0) - cx0;
	cy0 = (2 * y0) - cy0;

	enesim_curve_quadratic_to(state, cx0, cy0, x, y);
	state->last_x = x;
	state->last_y = y;
	state->last_ctrl_x = cx0;
	state->last_ctrl_y = cy0;
}

void enesim_curve_cubic_to(Enesim_Curve_State *state,
		double ctrl_x0, double ctrl_y0,
		double ctrl_x, double ctrl_y,
		double x, double y)
{
	/* force one initial subdivision */
	double x01 = (state->last_x + ctrl_x0) / 2;
	double y01 = (state->last_y + ctrl_y0) / 2;
	double xc = (ctrl_x0 + ctrl_x) / 2;
	double yc = (ctrl_y0 + ctrl_y) / 2;
	double x23 = (x + ctrl_x) / 2;
	double y23 = (y + ctrl_y) / 2;
	double xa = (x01 + xc) / 2;
	double ya = (y01 + yc) / 2;
	double xb = (x23 + xc) / 2;
	double yb = (y23 + yc) / 2;

	xc = (xa + xb) / 2;
	yc = (ya + yb) / 2;
	_curve_cubic_to(state, x01, y01, xa, ya, xc, yc);
	state->last_x = xc;
	state->last_y = yc;
	state->last_ctrl_x = xa;
	state->last_ctrl_y = ya;

	_curve_cubic_to(state, xb, yb, x23, y23, x, y);
	state->last_x = x;
	state->last_y = y;
	state->last_ctrl_x = x23;
	state->last_ctrl_y = y23;
}

#endif
/*----------------------------------------------------------------------------*
 *                            Figure normalizer                               *
 *----------------------------------------------------------------------------*/
static void _figure_move_to(Enesim_Path_Command_Move_To *move_to,
		Enesim_Path_Normalizer_State *state, void *data)
{

}

static void _figure_line_to(Enesim_Path_Command_Line_To *line_to,
		Enesim_Path_Normalizer_State *state, void *data)
{

}

static void _figure_cubic_to(Enesim_Path_Command_Cubic_To *cubic_to,
		Enesim_Path_Normalizer_State *state, void *data)
{

}

static void _figure_close(Enesim_Path_Command_Close *close,
		Enesim_Path_Normalizer_State *state, void *data)
{

}

static void _figure_free(void *data)
{
	free(data);
}

static Enesim_Path_Normalizer_Descriptor _figure_descriptor = {
	/* .move_to = 	*/ _figure_move_to,
	/* .line_to = 	*/ _figure_line_to,
	/* .cubic_to = 	*/ _figure_cubic_to,
	/* .close = 	*/ _figure_close,
	/* .free = 	*/ _figure_free,
};
/*----------------------------------------------------------------------------*
 *                             Path normalizer                                *
 *----------------------------------------------------------------------------*/
static void _path_move_to(Enesim_Path_Command_Move_To *move_to,
		Enesim_Path_Normalizer_State *state, void *data)
{
	Enesim_Path_Normalizer_Path *thiz = data;
	thiz->descriptor->move_to(move_to, thiz->data);
}

static void _path_line_to(Enesim_Path_Command_Line_To *line_to,
		Enesim_Path_Normalizer_State *state, void *data)<commit_msg>Implement the basic functions of the figure normalizer<commit_after>/* ENESIM - Direct Rendering Library
 * Copyright (C) 2007-2011 <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
#include "enesim_private.h"

#include "enesim_main.h"
#include "enesim_eina.h"
#include "enesim_path.h"
#include "enesim_path_normalizer_private.h"

typedef struct _Enesim_Path_Normalizer_State
{
	double last_x;
	double last_y;
	double last_ctrl_x;
	double last_ctrl_y;
} Enesim_Path_Normalizer_State;

typedef void (*Enesim_Path_Normalizer_Move_To_Cb)(Enesim_Path_Command_Move_To *move_to,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Line_To_Cb)(Enesim_Path_Command_Line_To *line_to,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Cubic_To_Cb)(Enesim_Path_Command_Cubic_To *cubic_to,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Close_Cb)(Enesim_Path_Command_Close *close,
		Enesim_Path_Normalizer_State *state, void *data);
typedef void (*Enesim_Path_Normalizer_Free_Cb)(void *data);

typedef struct _Enesim_Path_Normalizer_Descriptor
{
	Enesim_Path_Normalizer_Move_To_Cb move_to;
	Enesim_Path_Normalizer_Line_To_Cb line_to;
	Enesim_Path_Normalizer_Cubic_To_Cb cubic_to;
	Enesim_Path_Normalizer_Close_Cb close;
	Enesim_Path_Normalizer_Free_Cb free;
} Enesim_Path_Normalizer_Descriptor;

struct _Enesim_Path_Normalizer
{
	Enesim_Path_Normalizer_Descriptor *descriptor;
	Enesim_Path_Normalizer_State state;
	void *data;
};

typedef struct _Enesim_Path_Normalizer_Figure
{
	Enesim_Path_Normalizer_Figure_Descriptor *descriptor;
	void *data;
} Enesim_Path_Normalizer_Figure;

typedef struct _Enesim_Path_Normalizer_Path
{
	Enesim_Path_Normalizer_Path_Descriptor *descriptor;
	void *data;
} Enesim_Path_Normalizer_Path;
/*============================================================================*
 *                                  Local                                     *
 *============================================================================*/
#if 0
/* these subdiv approximations need to be done more carefully */
void enesim_curve_quadratic_to(Enesim_Curve_State *state,
		double ctrl_x, double ctrl_y,
		double x, double y)
{
	_curve_quadratic_to(state, ctrl_x, ctrl_y, x, y);
	state->last_x = x;
	state->last_y = y;
	state->last_ctrl_x = ctrl_x;
	state->last_ctrl_y = ctrl_y;
}

void enesim_curve_squadratic_to(Enesim_Curve_State *state,
		double x, double y)
{
	double x0, y0, cx0, cy0;

	x0 = state->last_x;
	y0 = state->last_y;
	cx0 = state->last_ctrl_x;
	cy0 = state->last_ctrl_y;
	cx0 = (2 * x0) - cx0;
	cy0 = (2 * y0) - cy0;

	enesim_curve_quadratic_to(state, cx0, cy0, x, y);
	state->last_x = x;
	state->last_y = y;
	state->last_ctrl_x = cx0;
	state->last_ctrl_y = cy0;
}

void enesim_curve_cubic_to(Enesim_Curve_State *state,
		double ctrl_x0, double ctrl_y0,
		double ctrl_x, double ctrl_y,
		double x, double y)
{
	/* force one initial subdivision */
	double x01 = (state->last_x + ctrl_x0) / 2;
	double y01 = (state->last_y + ctrl_y0) / 2;
	double xc = (ctrl_x0 + ctrl_x) / 2;
	double yc = (ctrl_y0 + ctrl_y) / 2;
	double x23 = (x + ctrl_x) / 2;
	double y23 = (y + ctrl_y) / 2;
	double xa = (x01 + xc) / 2;
	double ya = (y01 + yc) / 2;
	double xb = (x23 + xc) / 2;
	double yb = (y23 + yc) / 2;

	xc = (xa + xb) / 2;
	yc = (ya + yb) / 2;
	_curve_cubic_to(state, x01, y01, xa, ya, xc, yc);
	state->last_x = xc;
	state->last_y = yc;
	state->last_ctrl_x = xa;
	state->last_ctrl_y = ya;

	_curve_cubic_to(state, xb, yb, x23, y23, x, y);
	state->last_x = x;
	state->last_y = y;
	state->last_ctrl_x = x23;
	state->last_ctrl_y = y23;
}

#endif
/*----------------------------------------------------------------------------*
 *                            Figure normalizer                               *
 *----------------------------------------------------------------------------*/
static void _figure_move_to(Enesim_Path_Command_Move_To *move_to,
		Enesim_Path_Normalizer_State *state, void *data)
{
	Enesim_Path_Normalizer_Figure *thiz = data;
	double x, y;

	enesim_path_command_move_to_values_to(move_to, &x, &y);
	thiz->descriptor->polygon_add(thiz->data);
	thiz->descriptor->vertex_add(x, y, thiz->data);
}

static void _figure_line_to(Enesim_Path_Command_Line_To *line_to,
		Enesim_Path_Normalizer_State *state, void *data)
{
	Enesim_Path_Normalizer_Figure *thiz = data;
	double x, y;

	enesim_path_command_line_to_values_to(line_to, &x, &y);
	thiz->descriptor->vertex_add(x, y, thiz->data);
}

static void _figure_cubic_to(Enesim_Path_Command_Cubic_To *cubic_to,
		Enesim_Path_Normalizer_State *state, void *data)
{
	/* normalize the cubic command */
}

static void _figure_close(Enesim_Path_Command_Close *close,
		Enesim_Path_Normalizer_State *state, void *data)
{
	Enesim_Path_Normalizer_Figure *thiz = data;
	thiz->descriptor->polygon_close(close->close, thiz->data);
}

static void _figure_free(void *data)
{
	free(data);
}

static Enesim_Path_Normalizer_Descriptor _figure_descriptor = {
	/* .move_to = 	*/ _figure_move_to,
	/* .line_to = 	*/ _figure_line_to,
	/* .cubic_to = 	*/ _figure_cubic_to,
	/* .close = 	*/ _figure_close,
	/* .free = 	*/ _figure_free,
};
/*----------------------------------------------------------------------------*
 *                             Path normalizer                                *
 *----------------------------------------------------------------------------*/
static void _path_move_to(Enesim_Path_Command_Move_To *move_to,
		Enesim_Path_Normalizer_State *state, void *data)
{
	Enesim_Path_Normalizer_Path *thiz = data;
	thiz->descriptor->move_to(move_to, thiz->data);
}

static void _path_line_to(Enesim_Path_Command_Line_To *line_to,
		Enesim_Path_Normalizer_State *state, void *data)
{'fraction_non_alphanumeric': 0.1676841676841677, 'fraction_numerical': 0.012535612535612535, 'mean_word_length': 3.4937820043891734, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4995956', 'n_tokens_mistral': 4665, 'n_tokens_neox': 4470, 'n_words': 974}