Here is a start on an API for a "geometry" layer. Right now, the API includes polygons, hatching and some support functions. I'd like to get comments on the API including if any additional functions are required. If acceptable, I'd like to continue with implementation to add support for the new path code.

Cheers,
Ed

From 3d0a22461c6708b06adf77adfee62044fb08df88 Mon Sep 17 00:00:00 2001
Date: Fri, 26 Sep 2008 21:45:36 -0700
Subject: [PATCH] An API specification for a "geometry" layer.

---
 libgeda/include/struct.h |   21 ++++
 libgeda/src/Makefile.am  |    3 +-
 libgeda/src/m_basic.c    |    5 -
 libgeda/src/m_geometry.c |  246 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 269 insertions(+), 6 deletions(-)
 create mode 100644 libgeda/src/m_geometry.c

diff --git a/libgeda/include/struct.h b/libgeda/include/struct.h
index 3636802..b9e6686 100644
--- a/libgeda/include/struct.h
+++ b/libgeda/include/struct.h
@@ -36,6 +36,8 @@ typedef struct st_arc ARC;
 typedef struct st_box BOX;
 typedef struct st_picture PICTURE;
 typedef struct st_text TEXT;
+typedef struct st_bezier BEZIER;
+typedef struct st_point POINT;
 
 typedef struct st_object OBJECT;
 typedef struct st_page PAGE;
@@ -43,10 +45,13 @@ typedef struct st_toplevel TOPLEVEL;
 typedef struct st_color COLOR;
 typedef struct st_undo UNDO;
 typedef struct st_tile TILE;
+typedef struct st_bounds BOUNDS;
 
 typedef struct st_conn CONN;
 typedef struct st_bus_ripper BUS_RIPPER;
 
+typedef struct st_transform TRANSFORM;
+
 /* Used when you move objects and you want the nets/pins to stretch */
 typedef struct st_stretch STRETCH;
 
@@ -87,6 +92,10 @@ typedef enum {TYPE_SOLID, TYPE_DOTTED, TYPE_DASHED, 
TYPE_CENTER, TYPE_PHANTOM, T
 typedef enum {FILLING_HOLLOW, FILLING_FILL, FILLING_MESH, FILLING_HATCH, 
FILLING_VOID} OBJECT_FILLING;
 /* PB : change end */
 
+struct st_point {
+  int x;
+  int y;
+};
 
 struct st_line {
   int x[2];
@@ -137,6 +146,18 @@ struct st_arc {
 #define ARC_START_ANGLE 2
 #define ARC_END_ANGLE 3
 
+struct st_bezier {
+  int x[4];
+  int y[4];
+};
+
+struct st_bounds {
+  int xmin;
+  int ymin;
+  int xmax;
+  int ymax;
+};
+
 struct st_box {
   /* upper is considered the origin */
   int upper_x, upper_y; /* world */    
diff --git a/libgeda/src/Makefile.am b/libgeda/src/Makefile.am
index bcae051..f6dd9e9 100644
--- a/libgeda/src/Makefile.am
+++ b/libgeda/src/Makefile.am
@@ -60,7 +60,8 @@ libgeda_la_SOURCES = \
        s_tile.c \
        s_toplevel.c \
        s_undo.c \
-       u_basic.c
+       u_basic.c \
+        m_geometry.c
 
 INCLUDES = -I$(top_srcdir)/include @LIBGEDA_CFLAGS@
 DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
diff --git a/libgeda/src/m_basic.c b/libgeda/src/m_basic.c
index b0b5ea9..c8cc63f 100644
--- a/libgeda/src/m_basic.c
+++ b/libgeda/src/m_basic.c
@@ -372,11 +372,6 @@ struct st_halfspace {
   int bottom; 
 };
 
-/*! \brief */
-struct st_point {
-       int x, y;
-};
-
 /* \note 
  * encode_halfspace and clip are part of the cohen-sutherland clipping
  * algorithm.  They are used to determine if an object is visible or not 
diff --git a/libgeda/src/m_geometry.c b/libgeda/src/m_geometry.c
new file mode 100644
index 0000000..eb54f59
--- /dev/null
+++ b/libgeda/src/m_geometry.c
@@ -0,0 +1,246 @@
+/* gEDA - GPL Electronic Design Automation
+ * libgeda - gEDA's library
+ * Copyright (C) 1998-2008 Ales Hvezda
+ * Copyright (C) 1998-2008 gEDA Contributors (see ChangeLog for details)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
+ */
+#include <config.h>
+#include <libgeda_priv.h>
+
+/** \brief A structure to store a 2D affine transform.
+ *
+ *  The st_transform struct remains opaque outside this module.  The transforms
+ *  get stored in a 3x3 matrix. Code assumes the bottom row to remain constant
+ *  at [0 0 1].
+ */
+struct st_transform {
+  gdouble m[2][3];    /* m[row][column] */
+};
+
+/** \brief Subdivides an arc into line segments
+ *
+ *  To implement path subdivision, this function only appends new points to
+ *  the GArray of POINT.  The function ensures duplicate points do not get
+ *  appended.  (Zero length line segments)
+ *
+ *  \param arc [in] The arc to subdivide.
+ *  \param segments [in] The number of segments to subdivide the arc into.
+ *  \param points [inout] A GArray of POINT to contain the segment endpoints.
+ *  This function appends new points to the GArray and leaves existing GArray
+ *  contents unchanged.
+ */
+void m_geometry_arc_subdivide(ARC *arc, gint segments, GArray *points)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Subdivides a Bezier curve into line segments
+ *
+ *  To implement path subdivision, this function only appends new points to
+ *  the GArray of POINT.  The function ensures duplicate points do not get
+ *  appended.  (Zero length line segments)
+ *
+ *  \param bezier [in] The Bezier curve to subdivide.
+ *  \param segments [in] The number of segments to subdivide the Bezier curve 
into.
+ *  \param points [inout] A GArray of POINT to contain the segment endpoints.
+ *  This function appends new points to the GArray and leaves existing GArray
+ *  contents unchanged.
+ */
+void m_geometry_bezier_subdivide(BEZIER *bezier, gint segments, GArray *points)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Calculates the union of two bounds.
+ *
+ *  \param result [inout] The resulting bounds.  This parameter must not be 
NULL.
+ *  \param bounds0 [in] First operand.
+ *  \param bounds1 [in] Second operand.
+ */
+BOUNDS *m_geometry_bounds_union(BOUNDS *result, BOUNDS *bounds0, BOUNDS 
*bounds1)
+{
+  return NULL;    /* TODO: Implement */
+}
+
+/** \brief Calculates line segments to hatch a box shape
+ *
+ *  This function appends new line segments to the lines GArray.  For creating
+ *  a hatch pattern, the GArray must be cleared before calling this function.
+ *  For creating cross hatch patterns, this function can be called multiple
+ *  times with a different angle or pitch while passing the same lines GArray.
+ *
+ *  \param box [in] The box shape to hatch.
+ *  \param angle [in] The angle of the hatch lines with respect to the x axis.
+ *  \param pitch [in] The distance between hatch lines
+ *  \param lines [inout] A GArray of LINE to contain the new hatch line
+ *  segments.  This function appends new line segments to the GArray and leaves
+ *  existing GArray contents unchanged.
+ */
+void m_geometry_box_hatch(BOX *box, gint angle, gint pitch, GArray *lines)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Calculates line segments to hatch a circle.
+ *
+ *  This function appends new line segments to the lines GArray.  For creating
+ *  a hatch pattern, the GArray must be cleared before calling this function.
+ *  For creating cross hatch patterns, this function can be called multiple
+ *  times with a different angle or pitch while passing the same lines GArray.
+ *
+ *  \param circle [in] The circle shape to hatch.
+ *  \param angle [in] The angle of the hatch lines with respect to the x axis.
+ *  \param pitch [in] The distance between hatch lines
+ *  \param lines [inout] A GArray of LINE to contain the new hatch line
+ *  segments.  This function appends new line segments to the GArray and leaves
+ *  existing GArray contents unchanged.
+ */
+void m_geometry_circle_hatch(CIRCLE *circle, gint angle, gint pitch, GArray 
*lines)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Transforms a line segment
+ *
+ *  \param line [inout] The line to transform.
+ *  \param transform [in] The transform function.
+ */
+void m_geometry_line_transform(LINE *line, TRANSFORM *transform)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Transforms multiple line segments
+ *
+ *  \param line [inout] The GArray of LINE to transform.
+ *  \param transform [in] The transform function.
+ */
+void m_geometry_lines_transform(GArray *lines, TRANSFORM *transform)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Transforms a point
+ *
+ *  \param x [inout] The x coordinate to transform.
+ *  \param y [inout] The y coordinate to transform.
+ *  \param transform [in] The transform function.
+ */
+void m_geometry_point_transform(gint *x, gint *y, TRANSFORM *transform)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Calculates the bounds of a polyline or polygon
+ *
+ *  \param points [in] The GArray of POINT to calculate the bounds of.
+ *  \param bounds [out] The resulting bounds.
+ */
+BOUNDS *m_geometry_points_bounds(GArray *points, BOUNDS *bounds)
+{
+  return NULL;    /* TODO: Implement */
+}
+
+/** \brief Transforms a polyline or polygon
+ *
+ *  \param line [inout] The GArray of POINT to transform.
+ *  \param transform [in] The transform function.
+ */
+void m_geometry_points_transform(GArray *points, TRANSFORM *transform)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Calculates line segments to hatch an arbitrary polygon.
+ *
+ *  This function appends new line segments to the lines GArray.  For creating
+ *  a hatch pattern, the GArray must be cleared before calling this function.
+ *  For creating cross hatch patterns, this function can be called multiple
+ *  times with a different angle or pitch while passing the same lines GArray.
+ *
+ *  \param points [in] The endpoints of the arbitrary closed polygon to hatch.
+ *  \param angle [in] The angle of the hatch lines with respect to the x axis.
+ *  \param pitch [in] The distance between hatch lines
+ *  \param lines [inout] A GArray of LINE to contain the new hatch line
+ *  segments.  This function appends new line segments to the GArray and leaves
+ *  existing GArray contents unchanged.
+ */
+void m_geometry_polygon_hatch(GArray *points, gint angle, gint pitch, GArray 
*lines)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Combines two transformations into one
+ *
+ *  \param result [out] The resulting transformation.
+ *  \param transform0 [in] The first operand.
+ *  \param transform1 [in] The second operand.
+ */
+void m_geometry_transform_combine(TRANSFORM *result, TRANSFORM *transform0, 
TRANSFORM transform1 )
+{
+  /* TODO: Implement */
+}
+
+/** \brief Initialize a transform with the identity matrix.
+ *
+ *  \param transform [out] The transform to initialize with the identity 
matrix.
+ */
+void m_geometry_transform_init(TRANSFORM *transform)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Calculates the inverse transform
+ *
+ *  \param transform [in] The given matrix
+ *  \param inverse [out] The inverse of the given matrix.
+ */
+void m_geometry_transform_invert(TRANSFORM *transform, TRANSFORM *inverse)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Adds a rotation to the transformation
+ *
+ *  \param transform [inout] The given matrix
+ *  \param angle [in] The angle to rotate
+ */
+void m_geometry_transform_rotate(TRANSFORM *transform, gdouble angle)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Adds a scaling to the transformation
+ *
+ *  \param transform [inout] The given matrix
+ *  \param factor [in] The amount to scale the transform
+ */
+void m_geometry_transform_scale(TRANSFORM *transform, gdouble factor)
+{
+  /* TODO: Implement */
+}
+
+/** \brief Adds a translation to the transformation
+ *
+ *  \param transform [inout] The given matrix.
+ *  \param dx [in] The amount to translate on the x axis.
+ *  \param dy [in] The amount to translate on the y axis.
+ */
+void m_geometry_transform_translate(TRANSFORM *transform, gdouble dx, gdouble 
dy)
+{
+  /* TODO: Implement */
+}
+
-- 
1.5.4.3


_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev

Reply via email to