Skip to content

Commit 1e46d54

Browse files
committed
better default thickness handling
1 parent 6db3a1b commit 1e46d54

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Vector/vector_display.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ struct vector_display {
9999

100100
double initial_decay;
101101
double thickness;
102+
int custom_thickness;
102103

103104
double offset_x, offset_y;
104105
double scale;
@@ -108,6 +109,15 @@ struct vector_display {
108109
#define VERTEX_COLOR_INDEX (1)
109110
#define VERTEX_TEXCOORD_INDEX (2)
110111

112+
static double effective_thickness(vector_display_t *self) {
113+
if (self->custom_thickness) {
114+
return self->thickness * self->scale / 2;
115+
} else {
116+
// this makes thickness=16 at 2048x1536
117+
return (0.01 * (self->width + self->height) / 2.0) * self->scale / 2;
118+
}
119+
}
120+
111121
static int vector_display_init(vector_display_t *self, double width, double height) {
112122
self->steps = VECTOR_DISPLAY_DEFAULT_DECAY_STEPS;
113123
self->buffers = (GLuint*)calloc(sizeof(GLuint), self->steps);
@@ -126,7 +136,6 @@ static int vector_display_init(vector_display_t *self, double width, double heig
126136
self->glow_width = width / 3.0;
127137
self->glow_height = height / 3.0;
128138
self->initial_decay = VECTOR_DISPLAY_DEFAULT_INITIAL_DECAY;
129-
self->thickness = VECTOR_DISPLAY_DEFAULT_THICKNESS;
130139

131140
self->offset_x = VECTOR_DISPLAY_DEFAULT_OFFSET_X;
132141
self->offset_y = VECTOR_DISPLAY_DEFAULT_OFFSET_Y;
@@ -302,10 +311,16 @@ int vector_display_set_initial_decay(vector_display_t *self, double initial_deca
302311

303312
int vector_display_set_thickness(vector_display_t *self, double thickness) {
304313
if (thickness <= 0) return -1;
314+
self->custom_thickness = 1;
305315
self->thickness = thickness;
306316
return 0;
307317
}
308318

319+
int vector_display_set_default_thickness(vector_display_t *self) {
320+
self->custom_thickness = 0;
321+
return 0;
322+
}
323+
309324
int vector_display_clear(vector_display_t *self) {
310325
self->npoints = 0;
311326
return 0;
@@ -448,7 +463,7 @@ void draw_fan(vector_display_t *self, float cx, float cy, float pa, float a, flo
448463

449464
static void draw_lines(vector_display_t *self, line_t *lines, int nlines) {
450465
int i;
451-
float t = self->thickness * self->scale / 2;
466+
float t = effective_thickness(self);
452467

453468
for (i = 0; i < nlines; i++) {
454469
line_t *line = &lines[i], *pline = &lines[(nlines+i-1)%nlines];
@@ -516,7 +531,7 @@ int vector_display_end_draw(vector_display_t *self) {
516531
return 0;
517532
}
518533

519-
float t = self->thickness * self->scale / 2;
534+
float t = effective_thickness(self);
520535
int i;
521536
int first_last_same = abs(self->pending_points[0].x - self->pending_points[self->pending_npoints-1].x) < 0.1 &&
522537
abs(self->pending_points[0].y - self->pending_points[self->pending_npoints-1].y) < 0.1;

Vector/vector_display.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#define VECTOR_DISPLAY_DEFAULT_DECAY_STEPS (5)
1414
#define VECTOR_DISPLAY_DEFAULT_DECAY (0.8)
1515
#define VECTOR_DISPLAY_DEFAULT_INITIAL_DECAY (0.04)
16-
#define VECTOR_DISPLAY_DEFAULT_THICKNESS (14.0f)
1716
#define VECTOR_DISPLAY_DEFAULT_OFFSET_X (0.0)
1817
#define VECTOR_DISPLAY_DEFAULT_OFFSET_Y (0.0)
1918
#define VECTOR_DISPLAY_DEFAULT_SCALE (1.0)
@@ -117,9 +116,12 @@ int vector_display_set_transform(vector_display_t *self, double offset_x, double
117116
// is significantly narrower, since brightness decays exponentially to zero within the
118117
// bounds of the line.
119118
//
119+
// Thickness, by default, is guessed based on width and height.
120+
//
120121
// This function clears the display.
121122
//
122123
int vector_display_set_thickness(vector_display_t *self, double thickness);
124+
int vector_display_set_default_thickness(vector_display_t *self);
123125

124126
//
125127
// Get the size from a vector display.

0 commit comments

Comments
 (0)