GDS-Render v1.2.1
cell-geometrics.c
Go to the documentation of this file.
1/*
2 * GDSII-Converter
3 * Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
4 *
5 * This file is part of GDSII-Converter.
6 *
7 * GDSII-Converter is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * GDSII-Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
18 */
19
26#include <math.h>
27
29
35static void convert_gds_point_to_2d_vector(struct gds_point *pt, struct vector_2d *vector)
36{
37 vector->x = pt->x;
38 vector->y = pt->y;
39}
40
46static void update_box_with_gfx(union bounding_box *box, struct gds_graphics *gfx)
47{
48 union bounding_box current_box;
49
50 bounding_box_prepare_empty(&current_box);
51
52 switch (gfx->gfx_type) {
53 case GRAPHIC_BOX:
54 /* Expected fallthrough */
55 case GRAPHIC_POLYGON:
58 &current_box);
59 break;
60 case GRAPHIC_PATH:
61 /*
62 * This is not implemented correctly.
63 * Please be aware if paths are the outmost elements of your cell.
64 * You might end up with a completely wrong calculated cell size.
65 */
68 &current_box);
69 break;
70 default:
71 /* Unknown graphics object. */
72 /* Print error? Nah.. */
73 break;
74 }
75
76 /* Update box with results */
77 bounding_box_update_with_box(box, &current_box);
78}
79
81{
82 GList *gfx_list;
83 struct gds_graphics *gfx;
84 GList *sub_cell_list;
85 struct gds_cell_instance *sub_cell;
86 union bounding_box temp_box;
87
88 if (!box || !cell)
89 return;
90
91 /* Update box with graphic elements */
92 for (gfx_list = cell->graphic_objs; gfx_list != NULL; gfx_list = gfx_list->next) {
93 gfx = (struct gds_graphics *)gfx_list->data;
94 update_box_with_gfx(box, gfx);
95 }
96
97 /* Update bounding box with boxes of subcells */
98 for (sub_cell_list = cell->child_cells; sub_cell_list != NULL;
99 sub_cell_list = sub_cell_list->next) {
100 sub_cell = (struct gds_cell_instance *)sub_cell_list->data;
102 /* Recursion Woohoo!! This dies if your GDS is faulty and contains a reference loop */
103 calculate_cell_bounding_box(&temp_box, sub_cell->cell_ref);
104
105 /* Apply transformations */
106 bounding_box_apply_transform(ABS(sub_cell->magnification), sub_cell->angle,
107 sub_cell->flipped, &temp_box);
108
109 /* Move bounding box to origin */
110 temp_box.vectors.lower_left.x += sub_cell->origin.x;
111 temp_box.vectors.upper_right.x += sub_cell->origin.x;
112 temp_box.vectors.lower_left.y += sub_cell->origin.y;
113 temp_box.vectors.upper_right.y += sub_cell->origin.y;
114
115 /* update the parent's box */
116 bounding_box_update_with_box(box, &temp_box);
117 }
118}
119
Calculation of gds_cell geometrics.
@ GRAPHIC_POLYGON
An arbitrary polygon.
Definition: gds-types.h:51
@ GRAPHIC_PATH
Path. Esentially a line.
Definition: gds-types.h:50
@ GRAPHIC_BOX
A rectangle.
Definition: gds-types.h:52
void calculate_cell_bounding_box(union bounding_box *box, struct gds_cell *cell)
Calculate bounding box of a gds cell.
void bounding_box_prepare_empty(union bounding_box *box)
Prepare an empty bounding box.
Definition: bounding-box.c:86
void bounding_box_update_with_path(GList *vertices, double thickness, conv_generic_to_vector_2d_t conv_func, union bounding_box *box)
Calculate the bounding box of a path and update the given bounding box.
Definition: bounding-box.c:148
static void update_box_with_gfx(union bounding_box *box, struct gds_graphics *gfx)
Update the given bounding box with the bounding box of a graphics element.
void(* conv_generic_to_vector_2d_t)(void *, struct vector_2d *)
Definition: bounding-box.h:76
void bounding_box_apply_transform(double scale, double rotation_deg, bool flip_at_x, union bounding_box *box)
Apply transformations onto bounding box.
Definition: bounding-box.c:207
void bounding_box_calculate_from_polygon(GList *vertices, conv_generic_to_vector_2d_t conv_func, union bounding_box *box)
Calculate bounding box of polygon.
Definition: bounding-box.c:40
static void convert_gds_point_to_2d_vector(struct gds_point *pt, struct vector_2d *vector)
void bounding_box_update_with_box(union bounding_box *destination, union bounding_box *update)
Update an exisitng bounding box with another one.
Definition: bounding-box.c:71
struct vector_2d upper_right
Upper right point of the bounding box.
Definition: bounding-box.h:64
struct vector_2d lower_left
Lower left point of the bounding box.
Definition: bounding-box.h:62
This represents an instanc of a cell inside another cell.
Definition: gds-types.h:110
int flipped
Mirrored on x-axis before rotation.
Definition: gds-types.h:114
double angle
Angle of rotation (counter clockwise) in degrees.
Definition: gds-types.h:115
double magnification
magnification
Definition: gds-types.h:116
struct gds_cell * cell_ref
Referenced gds_cell structure.
Definition: gds-types.h:112
struct gds_point origin
Origin.
Definition: gds-types.h:113
A Cell inside a gds_library.
Definition: gds-types.h:122
GList * child_cells
List of gds_cell_instance elements.
Definition: gds-types.h:126
GList * graphic_objs
List of gds_graphics.
Definition: gds-types.h:127
A GDS graphics object.
Definition: gds-types.h:98
enum graphics_type gfx_type
Type of graphic.
Definition: gds-types.h:99
int width_absolute
Width. Not used for objects other than paths.
Definition: gds-types.h:102
GList * vertices
List of gds_point.
Definition: gds-types.h:100
A point in the 2D plane. Sometimes referred to as vertex.
Definition: gds-types.h:63
Union describing a bounding box.
Definition: bounding-box.h:55
struct bounding_box::_vectors vectors