fixed intersection calculation
This commit is contained in:
parent
69316e46c6
commit
eaacd12c0e
12
csrc/u8g2.h
12
csrc/u8g2.h
|
@ -256,10 +256,12 @@ struct u8g2_struct
|
|||
u8g2_uint_t height;
|
||||
|
||||
/* ths is the clip box for the user to check if a specific box has an intersection */
|
||||
/* use u8g2_IsIntersection from u8g2_intersection.c to test against this intersection */
|
||||
/* boundary values are part of the box so that they can be used with u8g2_IsIntersection */
|
||||
u8g2_uint_t user_x0; /* left corner of the buffer */
|
||||
u8g2_uint_t user_x1; /* right corner of the buffer (excluded) */
|
||||
u8g2_uint_t user_y0;
|
||||
u8g2_uint_t user_y1;
|
||||
u8g2_uint_t user_x1; /* right corner of the buffer (included) */
|
||||
u8g2_uint_t user_y0; /* upper edge of the buffer */
|
||||
u8g2_uint_t user_y1; /* lower edge of the buffer (included) */
|
||||
|
||||
/* information about the current font */
|
||||
const uint8_t *font; /* current font for all text procedures */
|
||||
|
@ -393,7 +395,11 @@ void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_
|
|||
|
||||
/*==========================================*/
|
||||
/* u8g2_hvline.c */
|
||||
|
||||
/* u8g2_DrawHVLine does not use u8g2_IsIntersection */
|
||||
void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);
|
||||
|
||||
/* the following three function will do an intersection test of this is enabled with U8G2_WITH_INTERSECTION */
|
||||
void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len);
|
||||
void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len);
|
||||
void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y);
|
||||
|
|
|
@ -202,16 +202,34 @@ void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len
|
|||
|
||||
void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len-1, y) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, len, 0);
|
||||
}
|
||||
|
||||
void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x, y+len-1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, len, 1);
|
||||
}
|
||||
|
||||
void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( x < u8g2->user_x0 )
|
||||
return;
|
||||
if ( x > u8g2->user_x1 )
|
||||
return;
|
||||
if ( y < u8g2->user_y0 )
|
||||
return;
|
||||
if ( y > u8g2->user_y1 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
/*
|
||||
calculate the intersection between a0/a1 and v0/v1
|
||||
The intersection check returns one if the range of a0/a1 has an intersection with v0/v1.
|
||||
The intersection check includes the boundary values a0 and a1.
|
||||
The intersection check includes the boundary values v1 and a1.
|
||||
|
||||
The following asserts will succeed:
|
||||
assert( u8g2_is_intersection_decision_tree(4, 6, 7, 9) == 0 );
|
||||
|
|
|
@ -63,7 +63,7 @@ void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_
|
|||
update dimension:
|
||||
calculate the following variables:
|
||||
u8g2_uint_t buf_x0; left corner of the buffer
|
||||
u8g2_uint_t buf_x1; right corner of the buffer (excluded)
|
||||
u8g2_uint_t buf_x1; right corner of the buffer (included)
|
||||
u8g2_uint_t buf_y0;
|
||||
u8g2_uint_t buf_y1;
|
||||
*/
|
||||
|
@ -108,6 +108,9 @@ void u8g2_update_dimension_r0(u8g2_t *u8g2)
|
|||
u8g2->user_y0 = u8g2->buf_y0;
|
||||
u8g2->user_y1 = u8g2->buf_y1;
|
||||
|
||||
u8g2->user_x1--;
|
||||
u8g2->user_y1--;
|
||||
|
||||
// printf("x0=%d x1=%d y0=%d y1=%d\n",
|
||||
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
|
||||
}
|
||||
|
@ -125,6 +128,9 @@ void u8g2_update_dimension_r1(u8g2_t *u8g2)
|
|||
u8g2->user_y0 = 0;
|
||||
u8g2->user_y1 = u8g2->pixel_buf_width;
|
||||
|
||||
u8g2->user_x1--;
|
||||
u8g2->user_y1--;
|
||||
|
||||
// printf("x0=%d x1=%d y0=%d y1=%d\n",
|
||||
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
|
||||
}
|
||||
|
@ -139,6 +145,9 @@ void u8g2_update_dimension_r2(u8g2_t *u8g2)
|
|||
u8g2->user_y0 = u8g2->height - u8g2->buf_y1;
|
||||
u8g2->user_y1 = u8g2->height - u8g2->buf_y0;
|
||||
|
||||
u8g2->user_x1--;
|
||||
u8g2->user_y1--;
|
||||
|
||||
// printf("x0=%d x1=%d y0=%d y1=%d\n",
|
||||
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
|
||||
}
|
||||
|
@ -156,6 +165,9 @@ void u8g2_update_dimension_r3(u8g2_t *u8g2)
|
|||
u8g2->user_y0 = 0;
|
||||
u8g2->user_y1 = u8g2->pixel_buf_width;
|
||||
|
||||
u8g2->user_x1--;
|
||||
u8g2->user_y1--;
|
||||
|
||||
// printf("x0=%d x1=%d y0=%d y1=%d\n",
|
||||
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
|
||||
}
|
||||
|
|
|
@ -82,13 +82,13 @@ void chgr_show(void)
|
|||
unsigned x, y;
|
||||
for( y = 0; y < CHGR_HEIGHT/2; y++)
|
||||
{
|
||||
printf("%02d ", y*2);
|
||||
printf("%02d|", y*2);
|
||||
for( x = 0; x < CHGR_WIDTH/2; x++)
|
||||
{
|
||||
//printf("%x", chgr_bitmap[y][x]);
|
||||
printf("%s", chgr_to_str(chgr_bitmap[y][x]));
|
||||
}
|
||||
printf("\n");
|
||||
printf("|\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
CC = gcc
|
||||
|
||||
CFLAGS = -g -Wall -I../../../csrc/.
|
||||
|
||||
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) main.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
u8g2_utf8: $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJ) -o u8g2_utf8
|
||||
|
||||
clean:
|
||||
-rm $(OBJ) u8g2_utf8
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
#include "u8g2.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
u8g2_t u8g2;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int y;
|
||||
|
||||
u8g2_SetupBuffer_Utf8(&u8g2, &u8g2_cb_r0);
|
||||
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
|
||||
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
|
||||
|
||||
u8g2_SetFont(&u8g2, u8g2_font_5x7_tr);
|
||||
u8g2_SetFontDirection(&u8g2, 0);
|
||||
|
||||
|
||||
#ifdef U8G2_WITH_HVLINE_COUNT
|
||||
u8g2.hv_cnt = 0UL;
|
||||
#endif /* U8G2_WITH_HVLINE_COUNT */
|
||||
|
||||
|
||||
u8g2_FirstPage(&u8g2);
|
||||
do
|
||||
{
|
||||
for( y = 3; y < 21; y++ )
|
||||
{
|
||||
u8g2_DrawHLine(&u8g2, 3, y, 11);
|
||||
}
|
||||
|
||||
u8g2_DrawStr(&u8g2, 17, 8, "Test Inter-");
|
||||
u8g2_DrawStr(&u8g2, 17, 16, "section:");
|
||||
u8g2_DrawStr(&u8g2, 17, 24, "One Block");
|
||||
|
||||
|
||||
} while( u8g2_NextPage(&u8g2) );
|
||||
#ifdef U8G2_WITH_HVLINE_COUNT
|
||||
printf("hv cnt: %ld\n", u8g2.hv_cnt);
|
||||
#endif /* U8G2_WITH_HVLINE_COUNT */
|
||||
|
||||
utf8_show();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue