Skip to content

Commit 24bc946

Browse files
authored
Merge pull request #67 from saxbophone/develop
Version 0.12.1
2 parents 02fd493 + 21ee9ee commit 24bc946

File tree

12 files changed

+191
-85
lines changed

12 files changed

+191
-85
lines changed

CMakeLists.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# begin basic metadata
22
cmake_minimum_required(VERSION 3.0)
3-
enable_language(C CXX)
43

5-
project(saxbospiral VERSION 0.12.0 LANGUAGES C)
4+
project(saxbospiral VERSION 0.12.1 LANGUAGES C)
65
set(CMAKE_C_STANDARD 99)
76
set(CMAKE_C_STANDARD_REQUIRED ON)
87
set(
@@ -18,9 +17,9 @@ add_definitions(-DSAXBOSPIRAL_VERSION_MINOR=${PROJECT_VERSION_MINOR})
1817
add_definitions(-DSAXBOSPIRAL_VERSION_PATCH=${PROJECT_VERSION_PATCH})
1918
add_definitions(-DSAXBOSPIRAL_VERSION_STRING=${SAXBOSPIRAL_ESCAPED_VERSION_STRING})
2019

20+
# used for enabling additional compiler options if supported
2121
include(CheckCCompilerFlag)
2222

23-
# used for enabling additional compiler options if supported
2423
function(enable_c_compiler_flag_if_supported flag)
2524
string(FIND "${CMAKE_C_FLAGS}" "${flag}" flag_already_set)
2625
if(flag_already_set EQUAL -1)
@@ -32,7 +31,14 @@ function(enable_c_compiler_flag_if_supported flag)
3231
endfunction()
3332

3433
# enable extra flags (warnings) if we're not in release mode
35-
if(NOT CMAKE_BUILD_TYPE EQUAL CMAKE_C_FLAGS_RELEASE)
34+
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
35+
# enable all warnings about 'questionable constructs'
36+
enable_c_compiler_flag_if_supported("-Wall")
37+
# issue 'pedantic' warnings for strict ISO compliance
38+
enable_c_compiler_flag_if_supported("-Wpedantic")
39+
# enable 'extra' strict warnings
40+
enable_c_compiler_flag_if_supported("-Wextra")
41+
# convert all warnings into errors
3642
enable_c_compiler_flag_if_supported("-Werror")
3743
endif()
3844

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Experimental generation of 2D spiralling lines based on input binary data
88

99
For the library, you will need:
1010

11-
- A compiler that can compile C99 code
11+
- A compiler that can compile ISO C99 code
1212
- [Cmake](https://cmake.org/) - v3.0 or newer
1313
- [libpng](http://www.libpng.org/pub/png/libpng.html) - (this often comes preinstalled with many modern unix-like systems)
1414

@@ -18,11 +18,11 @@ For the included CLI program, you will also need:
1818

1919
- [Argtable 2](http://argtable.sourceforge.net/) - must use v2, v1 and v3 will not work
2020

21-
### Note:
21+
> ### Note:
2222
23-
These commands are for unix-like systems, without an IDE or other build system besides CMake. If building for a different system, or within an IDE or other environment, consult your IDE/System documentation on how to build CMake projects.
23+
> These commands are for unix-like systems, without an IDE or other build system besides CMake. If building for a different system, or within an IDE or other environment, consult your IDE/System documentation on how to build CMake projects.
2424
25-
Additionally, it is of worth noting that this library has only been thoroughly tested and developed on Ubuntu GNU/Linux, although every effort has been made to make it as cross-platform as possible. It should compile under any POSIX-compliant system with the correct additional dependencies listed. **v0.8** is known to successfully cross-compile from Ubuntu to Windows (via [cygwin](https://www.cygwin.com/)) and Max OSX (using a locally-built compiler toolchain provided via [OSXCross](https://github.com/tpoechtrager/osxcross). It is highly likely that all other versions cross-compile as well (but I haven't yet verified this).
25+
> Additionally, it is of worth noting that this library has only been thoroughly tested and developed on **Ubuntu GNU/Linux** with **GCC v5.4.0**, although every effort has been made to make it as cross-platform as possible (including reasonably strict **ISO C 99** compliance). It should compile under any POSIX-compliant system with the correct additional dependencies listed. **v0.8** is known to successfully cross-compile from Ubuntu to Windows (via [cygwin](https://www.cygwin.com/)) and Max OSX (using a locally-built compiler toolchain provided via [OSXCross](https://github.com/tpoechtrager/osxcross). It is highly likely that all other versions cross-compile as well (but I haven't yet verified this).
2626
2727
## Basic Build
2828

build_logo.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88
#
99
echo "Generating logo";
1010
echo -n "$3" > temp.hex && \
11-
./"$1" -pgr -i temp.hex -o "$2";
11+
./"$1" -pgr -i temp.hex -o "$2" && \
12+
rm temp.hex;

saxbospiral.png

1 Byte
Loading

saxbospiral/plot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ spiral_points(
3535
size_t start, size_t end
3636
) {
3737
// prepare result status
38-
status_t result = {};
38+
status_t result = {0};
3939
// the amount of space needed is the sum of all line lengths + 1 for end
4040
size_t size = sum_lines(spiral, start, end) + 1;
4141
// allocate memory
@@ -82,7 +82,7 @@ spiral_points(
8282
status_t
8383
cache_spiral_points(spiral_t * spiral, size_t limit) {
8484
// prepare result status
85-
status_t result = {};
85+
status_t result = {0};
8686
// the amount of space needed is the sum of all line lengths + 1 for end
8787
size_t size = sum_lines(*spiral, 0, limit) + 1;
8888
// allocate / reallocate memory
@@ -126,7 +126,7 @@ cache_spiral_points(spiral_t * spiral, size_t limit) {
126126
spiral->co_ord_cache.co_ords.items[0] = current;
127127
}
128128
// calculate the missing co-ords
129-
co_ord_array_t missing= {};
129+
co_ord_array_t missing= {0};
130130
status_t calculate_result = spiral_points(
131131
*spiral, &missing, current, smallest, limit
132132
);

saxbospiral/render.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,18 @@ get_bounds(spiral_t spiral, co_ord_t * bounds) {
5858
status_t
5959
render_spiral(spiral_t spiral, bitmap_t * image) {
6060
// create result status struct
61-
status_t result = {};
61+
status_t result = {0};
6262
// plot co-ords of spiral into it's cache
6363
cache_spiral_points(&spiral, spiral.size);
6464
// get the min and max bounds of the spiral's co-ords
65-
co_ord_t bounds[2] = {};
65+
co_ord_t bounds[2] = {0};
6666
get_bounds(spiral, bounds);
6767
// get the normalisation vector needed to make all values unsigned
6868
tuple_t normalisation_vector = {
6969
.x = -bounds[0].x,
7070
.y = -bounds[0].y,
7171
};
72-
// get co-ords of top left and bottom right corners, as unsigned
73-
co_ord_t top_left = {
74-
.x = 0,
75-
.y = 0,
76-
};
72+
// get co-ords of bottom right corner, as unsigned
7773
co_ord_t bottom_right = {
7874
.x = bounds[1].x + normalisation_vector.x,
7975
.y = bounds[1].y + normalisation_vector.y,
@@ -112,7 +108,7 @@ render_spiral(spiral_t spiral, bitmap_t * image) {
112108
// get current direction
113109
vector_t direction = VECTOR_DIRECTIONS[spiral.lines[i].direction];
114110
// make as many jumps in this direction as this lines length
115-
for(uint64_t j = 0; j < (spiral.lines[i].length * 2) + 1; j++) {
111+
for(uint64_t j = 0; j < (spiral.lines[i].length * 2U) + 1U; j++) {
116112
// get output co-ords
117113
tuple_item_t x_pos = current.x + (normalisation_vector.x * 2) + 1;
118114
tuple_item_t y_pos = current.y + (normalisation_vector.y * 2) + 1;
@@ -121,7 +117,7 @@ render_spiral(spiral_t spiral, bitmap_t * image) {
121117
// flip the y-axis otherwise they appear vertically mirrored
122118
image->pixels[x_pos][image->height - 1 - y_pos] = true;
123119
}
124-
if(j != (spiral.lines[i].length * 2)) {
120+
if(j != (spiral.lines[i].length * 2U)) {
125121
// if we're not on the last line, advance the marker along
126122
current.x += direction.x;
127123
current.y += direction.y;

saxbospiral/render_backends/png_backend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@ buffer_write_data(png_structp png_ptr, png_bytep data, png_size_t length) {
3434
p->size += length;
3535
}
3636

37+
// disable GCC warning about the unused parameter, as this is a dummy function
38+
#pragma GCC diagnostic push
39+
#pragma GCC diagnostic ignored "-Wunused-parameter"
3740
// dummy function for unecessary flush function
3841
void dummy_png_flush(png_structp png_ptr) {}
42+
// re-enable all warnings
43+
#pragma GCC diagnostic pop
3944

4045
// simple libpng cleanup function - used mainly for freeing memory
4146
void

saxbospiral/saxbospiral.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ typedef struct co_ord_cache_t {
110110
} co_ord_cache_t;
111111

112112
typedef struct spiral_t {
113+
// TODO: Change type of this to int64_t
114+
// Then, remove typecast in solve.c, in function spiral_collides()
113115
size_t size;
114116
line_t * lines;
115117
co_ord_cache_t co_ord_cache;

saxbospiral/serialise.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ load_spiral(buffer_t buffer, spiral_t * spiral) {
9595
* bit mask and shift 3 bytes to left
9696
*/
9797
spiral->lines[i].length = (
98-
buffer.bytes[FILE_HEADER_SIZE + (i * LINE_T_PACK_SIZE)] & 0b00111111
98+
buffer.bytes[FILE_HEADER_SIZE + (i * LINE_T_PACK_SIZE)]
99+
& 0x3f // <= binary value is 0b00111111
99100
) << 24;
100101
// handle remaining 3 bytes in loop
101102
for(uint8_t j = 0; j < 3; j++) {

saxbospiral/solve.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ spiral_collides(spiral_t spiral, size_t index) {
4040
int64_t ttl = spiral.lines[line_count].length + 1; // ttl of line
4141
size_t last_co_ord = spiral.co_ord_cache.co_ords.size;
4242
line_t last_line = spiral.lines[index];
43-
size_t start_of_last_line = (last_co_ord - last_line.length) - 1;
43+
int64_t start_of_last_line = (last_co_ord - last_line.length) - 1;
4444
// check the co-ords of the last line segment against all the others
4545
for(int64_t i = 0; i < start_of_last_line; i++) {
4646
for(size_t j = start_of_last_line; j < last_co_ord; j++) {
@@ -69,7 +69,7 @@ spiral_collides(spiral_t spiral, size_t index) {
6969
* before the last one (these two lines can never collide with the
7070
* last and can be safely ignored, for a small performance increase)
7171
*/
72-
if(line_count == (spiral.size - 2 - 1)) { // -1 for zero-index
72+
if(line_count == ((int64_t)spiral.size - 2 - 1)) { // -1 for zero-index
7373
break;
7474
}
7575
}
@@ -122,15 +122,14 @@ suggest_resize(spiral_t spiral, size_t index, int perfection_threshold) {
122122
return spiral.lines[index - 1].length + 1;
123123
}
124124
// create variables to store the start and end co-ords of these lines
125-
co_ord_t pa, pb, ra, rb;
125+
co_ord_t pa, ra, rb;
126126
/*
127127
* We need to grab the start and end co-ords of the line previous to the
128128
* colliding line, and the rigid line that it collided with.
129129
*/
130130
size_t p_index = sum_lines(spiral, 0, index - 1);
131131
size_t r_index = sum_lines(spiral, 0, spiral.collides);
132132
pa = spiral.co_ord_cache.co_ords.items[p_index];
133-
pb = spiral.co_ord_cache.co_ords.items[p_index + p.length];
134133
ra = spiral.co_ord_cache.co_ords.items[r_index];
135134
rb = spiral.co_ord_cache.co_ords.items[r_index + r.length];
136135
/*
@@ -185,7 +184,7 @@ resize_spiral(
185184
* state of which line is being resized, and what size it should be.
186185
*/
187186
// set result status
188-
status_t result = {};
187+
status_t result = {0};
189188
size_t current_index = index;
190189
length_t current_length = length;
191190
while(true) {
@@ -245,7 +244,7 @@ resize_spiral(
245244
status_t
246245
plot_spiral(spiral_t * spiral, int perfection_threshold) {
247246
// set up result status
248-
status_t result = {};
247+
status_t result = {0};
249248
// calculate the length of each line
250249
for(size_t i = 0; i < spiral->size; i++) {
251250
result = resize_spiral(spiral, i, 1, perfection_threshold);

0 commit comments

Comments
 (0)