#ifndef PLOC_GEN_PATTERN_PATTERN_H #define PLOC_GEN_PATTERN_PATTERN_H #include struct coord { int x; int y; }; struct pattern_type { int width; int height; int min_length; int max_length; }; struct pattern { struct pattern_type type; struct coord *path; int length; }; /* * Creates a pattern_type. * If max has an invalid value the max_length is set to the * maximum possible length. */ struct pattern_type gen_pattern_type(int side_len, int min, int max); /* * Returns 0 if a equals b. */ int coord_cmp(const void *a, const void *b); /* * If the point happend to be on the line that connects start and end, * the result is true, otherwise is false. */ bool is_in_line(struct coord a, struct coord c, struct coord b); /* * Returns the index of coord in pattern->path. * The return value is negative if coord not found in pattern->path. */ int find_in_pattern(struct pattern *pattern, struct coord *coord); /* * Gives back the points in arr, that are between from and to. */ int inbetween(int width, int height, struct coord *from, struct coord *to, struct coord *arr); /* * Returns true if there's no unvisited point between * the last point of path and next. */ bool nothing_inbetween(struct pattern *pattern, struct coord *next); /* * Inline functions. */ inline bool len_is_max(struct pattern *pattern) { return pattern->length >= pattern->type.max_length; } inline bool len_is_min(struct pattern *pattern) { return pattern->length <= pattern->type.min_length; } inline int coord_to_index(int width, struct coord point) { return (point.y * width) + point.x; } inline struct coord index_to_coord(int width, int index) { struct coord result; result.y = index / width; result.x = index % width; return result; } inline int pattern_point_to_index(struct pattern *pattern, int index) { return coord_to_index(pattern->type.width, pattern->path[index]); } #endif