From e2ce0eecf7b1d35b97442c190b7635c4a080dcc4 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 12 Jul 2012 16:21:59 -0300 Subject: [PATCH] inst.c: zero-sized pads and holes now cause instantiation to fail Before, they were silently ignored but still included in output. This produced invalid Postscript (attempts to fit the pad name into the zero-sized pad failed) and may also have produced artefacts that could confuse KiCad. --- inst.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inst.c b/inst.c index d615c05..c17c701 100644 --- a/inst.c +++ b/inst.c @@ -16,6 +16,7 @@ #include #include "util.h" +#include "error.h" #include "coord.h" #include "expr.h" #include "layer.h" @@ -592,6 +593,25 @@ static void grow_bbox_by_width(struct bbox *bbox, unit_type width) } +static int zero_sized(struct coord a, struct coord b, const char *fmt, + const char *arg) +{ + if (a.x == b.x && a.y == b.y) { + fail(fmt, "zero-sized", arg); + return 1; + } + if (a.x == b.x) { + fail(fmt, "zero-width", arg); + return 1; + } + if (a.y == b.y) { + fail(fmt, "zero-height", arg); + return 1; + } + return 0; +} + + static struct inst *add_inst(const struct inst_ops *ops, enum inst_prio prio, struct coord base) { @@ -896,6 +916,8 @@ int inst_pad(struct obj *obj, const char *name, struct coord a, struct coord b) { struct inst *inst; + if (zero_sized(a, b, "%s pad \"%s\"", name)) + return 0; inst = add_inst(obj->u.pad.rounded ? &rpad_ops : &pad_ops, obj->u.pad.type == pt_normal || obj->u.pad.type == pt_bare || obj->u.pad.type == pt_trace ? @@ -932,6 +954,8 @@ int inst_hole(struct obj *obj, struct coord a, struct coord b) { struct inst *inst; + if (zero_sized(a, b, "%s hole", NULL)) + return 0; inst = add_inst(&hole_ops, ip_hole, a); inst->obj = obj; inst->u.hole.other = b;