From d4517aa493f1f75af3048180a0d141a05805c6d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Fri, 27 Jul 2018 21:00:30 +0200 Subject: [PATCH] add trigonometric sub library, add function to calculate bounding box of polygon --- CMakeLists.txt | 2 ++ gds-parser/gds-types.h | 4 +-- trigonometric/bounding-box.c | 58 +++++++++++++++++++++++++++++++ trigonometric/bounding-box.h | 43 +++++++++++++++++++++++ trigonometric/vector-operations.c | 26 ++++++++++++++ trigonometric/vector-operations.h | 34 ++++++++++++++++++ 6 files changed, 165 insertions(+), 2 deletions(-) create mode 100644 trigonometric/bounding-box.c create mode 100644 trigonometric/bounding-box.h create mode 100644 trigonometric/vector-operations.c create mode 100644 trigonometric/vector-operations.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2162afe..adc5b10 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ aux_source_directory("tree-renderer" RENDERER_SOURCES) aux_source_directory("gds-parser" PARSER_SOURCES) aux_source_directory("latex-output" LATEX_SOURCES) aux_source_directory("cairo-output" CAIRO_SOURCES) +aux_source_directory("trigonometric" TRIG_SOURCES) set(SOURCE "main.c" "layer-selector.c" "mapping-parser.c" "command-line.c" "main-window.c") set(SOURCE @@ -27,6 +28,7 @@ set(SOURCE ${PARSER_SOURCES} ${LATEX_SOURCES} ${CAIRO_SOURCES} + ${TRIG_SOURCES} ) add_compile_options(-Wall) diff --git a/gds-parser/gds-types.h b/gds-parser/gds-types.h index 8f34501..88cad12 100644 --- a/gds-parser/gds-types.h +++ b/gds-parser/gds-types.h @@ -35,8 +35,8 @@ #include #define CELL_NAME_MAX (100) /**< @brief Maximum length of a gds_cell::name or a gds_library::name */ -#define MIN(a,b) (((a) < (b)) ? (a) : (b)) /**< @brief Find return smaller number */ -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) /**< @brief Find return bigger number */ +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) /**< @brief Return smaller number */ +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) /**< @brief Return bigger number */ /** @brief Types of graphic objects */ enum graphics_type diff --git a/trigonometric/bounding-box.c b/trigonometric/bounding-box.c new file mode 100644 index 0000000..f97b7c5 --- /dev/null +++ b/trigonometric/bounding-box.c @@ -0,0 +1,58 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter 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 GDSII-Converter. If not, see . + */ + +/** + * @file bounding-box.c + * @brief Calculation of bounding boxes + * @author Mario Hüttel + */ + +#include +#include "bounding-box.h" + +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) /**< @brief Return smaller number */ +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) /**< @brief Return bigger number */ + +void bounding_box_calculate_polygon(GList *vertices, conv_generic_to_vector_2d_t conv_func, union bounding_box *box) +{ + double xmin = DBL_MAX, xmax = DBL_MIN, ymin = DBL_MAX, ymax = DBL_MIN; + struct vector_2d temp_vec; + GList *list_item; + + /* Check for errors */ + if (!conv_func || !box || !vertices) + return; + + for (list_item = vertices; list_item != NULL; list_item = g_list_next(list_item)) { + /* Convert generic vertex to vector_2d */ + conv_func((void *)list_item->data, &temp_vec); + + /* Update bounding coordinates with vertex */ + xmin = MIN(xmin, temp_vec.x); + xmax = MAX(xmax, temp_vec.x); + ymin = MIN(ymin, temp_vec.y); + ymax = MAX(ymax, temp_vec.y); + } + + /* Fill bounding box with results */ + box->vectors.lower_left.x = xmin; + box->vectors.lower_left.y = ymin; + box->vectors.upper_right.x = xmax; + box->vectors.upper_right.y = ymax; +} diff --git a/trigonometric/bounding-box.h b/trigonometric/bounding-box.h new file mode 100644 index 0000000..7712cd5 --- /dev/null +++ b/trigonometric/bounding-box.h @@ -0,0 +1,43 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter 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 GDSII-Converter. If not, see . + */ + +/** + * @file bounding-box.h + * @brief Header for calculation of bounding boxes + * @author Mario Hüttel + */ + +#ifndef _BOUNDING_BOX_H_ +#define _BOUNDING_BOX_H_ +#include +#include "vector-operations.h" + +union bounding_box { + struct _vectors { + struct vector_2d lower_left; + struct vector_2d upper_right; + } vectors; + struct vector_2d vector_array[2]; +}; + +typedef void (*conv_generic_to_vector_2d_t)(void *, struct vector_2d *); + +void bounding_box_calculate_polygon(GList *vertices, conv_generic_to_vector_2d_t conv_func, union bounding_box *box); + +#endif /* _BOUNDING_BOX_H_ */ diff --git a/trigonometric/vector-operations.c b/trigonometric/vector-operations.c new file mode 100644 index 0000000..b164471 --- /dev/null +++ b/trigonometric/vector-operations.c @@ -0,0 +1,26 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter 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 GDSII-Converter. If not, see . + */ + +/** + * @file vector-operations.c + * @brief 2D Vector operations + * @author Mario Hüttel + */ + +#include "vector-operations.h" diff --git a/trigonometric/vector-operations.h b/trigonometric/vector-operations.h new file mode 100644 index 0000000..a89bc4f --- /dev/null +++ b/trigonometric/vector-operations.h @@ -0,0 +1,34 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * This file is part of GDSII-Converter. + * + * GDSII-Converter is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * GDSII-Converter 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 GDSII-Converter. If not, see . + */ + +/** + * @file vector-operations.h + * @brief Header for 2D Vector operations + * @author Mario Hüttel + */ + +#ifndef _VECTOR_OPERATIONS_H_ +#define _VECTOR_OPERATIONS_H_ + +struct vector_2d { + double x; + double y; +}; + +#endif /* _VECTOR_OPERATIONS_H_ */