Skip to content

Commit

Permalink
Return ErrorCode::EmptyPath when path has too few points
Browse files Browse the repository at this point in the history
  • Loading branch information
jatoben committed Nov 23, 2024
1 parent 9822a51 commit 698bf15
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/gdstk/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum struct ErrorCode {
NoError = 0,
// Warnings
BooleanError,
EmptyPath,
IntersectionNotFound,
MissingReference,
UnsupportedRecord,
Expand Down
3 changes: 3 additions & 0 deletions python/gdstk_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ static int return_error(ErrorCode error_code) {
case ErrorCode::NoError:
return 0;
// Warnings
case ErrorCode::EmptyPath:
if (PyErr_WarnEx(PyExc_RuntimeWarning, "Empty path.", 1) != 0) return -1;
return 0;
case ErrorCode::MissingReference:
if (PyErr_WarnEx(PyExc_RuntimeWarning, "Missing reference.", 1) != 0) return -1;
return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/flexpath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void FlexPath::remove_overlapping_points() {

ErrorCode FlexPath::to_polygons(bool filter, Tag tag, Array<Polygon*>& result) {
remove_overlapping_points();
if (spine.point_array.count < 2) return ErrorCode::NoError;
if (spine.point_array.count < 2) return ErrorCode::EmptyPath;

const Array<Vec2> spine_points = spine.point_array;
uint64_t curve_size_guess = spine_points.count * 2 + 4;
Expand Down Expand Up @@ -774,7 +774,7 @@ ErrorCode FlexPath::to_gds(FILE* out, double scaling) {

remove_overlapping_points();

if (spine.point_array.count < 2) return error_code;
if (spine.point_array.count < 2) return ErrorCode::EmptyPath;

uint16_t buffer_end[] = {4, 0x1100};
big_endian_swap16(buffer_end, COUNT(buffer_end));
Expand Down Expand Up @@ -918,7 +918,7 @@ ErrorCode FlexPath::to_oas(OasisStream& out, OasisState& state) {

remove_overlapping_points();

if (spine.point_array.count < 2) return error_code;
if (spine.point_array.count < 2) return ErrorCode::EmptyPath;

bool has_repetition = repetition.get_count() > 1;

Expand Down

0 comments on commit 698bf15

Please sign in to comment.