From e1e1d38ee919e49e8fe3ab30314565008d9fcbd0 Mon Sep 17 00:00:00 2001 From: Nicola Fontana Date: Thu, 8 Jan 2009 00:29:53 +0100 Subject: [PATCH] [AdgPoint] Initial implementation --- adg/Makefile.am | 2 ++ adg/adg-point.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ adg/adg-point.h | 49 +++++++++++++++++++++++++++++++ docs/adg-docs.xml | 1 + docs/adg-sections.txt | 14 +++++++-- 5 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 adg/adg-point.c create mode 100644 adg/adg-point.h diff --git a/adg/Makefile.am b/adg/Makefile.am index 29ef2ad8..a97efae5 100644 --- a/adg/Makefile.am +++ b/adg/Makefile.am @@ -22,6 +22,7 @@ adg_h_sources= adg.h \ adg-pair.h \ adg-path.h \ adg-pattern.h \ + adg-point.h \ adg-style.h \ adg-util.h adg_built_h_sources= adg-type-builtins.h @@ -59,6 +60,7 @@ adg_c_sources= adg-adim.c \ adg-pair.c \ adg-path.c \ adg-pattern.c \ + adg-point.c \ adg-style.c \ adg-util.c adg_built_c_sources= adg-type-builtins.c diff --git a/adg/adg-point.c b/adg/adg-point.c new file mode 100644 index 00000000..d0625bbc --- /dev/null +++ b/adg/adg-point.c @@ -0,0 +1,80 @@ +/* ADG - Automatic Drawing Generation + * Copyright (C) 2007-2008, Nicola Fontana + * + * 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 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, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/** + * SECTION:point + * @title: AdgPoint + * @short_description: A generic point with model and paper space components + * + * The AdgPoint is quite different from what usually expected: to get the + * common (x, y) struct take a look to the #AdgPair object. + * + * In ADG, points have usually two components, being the component an usual + * (x, y) struct (an AdgPair object in this implementation). The model + * matrix is applied only to the model component while the paper matrix + * affects only the paper component. + **/ + +#include "adg-point.h" + +#include + + +GType +adg_point_get_type(void) +{ + static int point_type = 0; + + if (G_UNLIKELY(point_type == 0)) + point_type = g_boxed_type_register_static("AdgPoint", + (GBoxedCopyFunc) adg_point_dup, + g_free); + + return point_type; +} + +/** + * adg_point_dup: + * @point: an #AdgPoint structure + * + * Duplicates @point. + * + * Return value: the duplicate of @point: must be freed with g_free() + * when no longer needed. + **/ +AdgPoint * +adg_point_dup(const AdgPoint *point) +{ + return g_memdup(point, sizeof(AdgPoint)); +} + +/** + * adg_point_set: + * @point: an #AdgPoint structure + * @model: the model component + * @paper: the paper component + * + * Fills the component of @point using the provided ones. + **/ +void +adg_point_set(AdgPoint *point, const AdgPair *model, const AdgPair *paper) +{ + memcpy(&point->model, model, sizeof(AdgPair)); + memcpy(&point->paper, paper, sizeof(AdgPair)); +} diff --git a/adg/adg-point.h b/adg/adg-point.h new file mode 100644 index 00000000..30fd317d --- /dev/null +++ b/adg/adg-point.h @@ -0,0 +1,49 @@ +/* ADG - Automatic Drawing Generation + * Copyright (C) 2007-2008, Nicola Fontana + * + * 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 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, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + + +#ifndef __ADG_POINT_H__ +#define __ADG_POINT_H__ + +#include + + +G_BEGIN_DECLS + +#define ADG_TYPE_POINT (adg_point_get_type()) + + +typedef struct _AdgPoint AdgPoint; + +struct _AdgPoint { + AdgPair model; + AdgPair paper; +}; + + +GType adg_point_get_type (void) G_GNUC_CONST; +AdgPoint * adg_point_dup (const AdgPoint *point); +void adg_point_set (AdgPoint *point, + const AdgPair *model, + const AdgPair *paper); + +G_END_DECLS + + +#endif /* __ADG_POINT_H__ */ diff --git a/docs/adg-docs.xml b/docs/adg-docs.xml index 6753e924..71e601cb 100644 --- a/docs/adg-docs.xml +++ b/docs/adg-docs.xml @@ -64,6 +64,7 @@ ADG core reference + diff --git a/docs/adg-sections.txt b/docs/adg-sections.txt index 21bc8b07..ff42c0a6 100644 --- a/docs/adg-sections.txt +++ b/docs/adg-sections.txt @@ -10,6 +10,18 @@ adg_pair_get_type
+point +adg/adg.h +AdgPoint + +adg_point_dup +adg_point_set + +ADG_TYPE_POINT +adg_point_get_type +
+ +
matrix adg/adg.h AdgMatrix @@ -304,8 +316,6 @@ ADG_TYPE_ENTITY ADG_ENTITY_CLASS ADG_IS_ENTITY_CLASS ADG_ENTITY_GET_CLASS -adg_entity_flags_get_type -ADG_TYPE_ENTITY_FLAGS
-- 2.11.4.GIT