glib_line.c File Reference

Silicon Labs Graphics Library: Line Drawing Routines.

Copyright 2015 Silicon Labs, http://www.silabs.com

This file is licensensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.

Definition in file ``` glib_line.c ``` .

``` #include <stdint.h> ```
``` #include <stdbool.h> ```
``` #include "em_types.h" ```
``` #include " glib.h " ```

Functions

static bool GLIB_clipLine ( GLIB_Context_t *pContext, int32_t *pX1, int32_t *pY1, int32_t *pX2, int32_t *pY2)
Clips the line if necessary, using the Cohen-Sutherland algorithm for clipping lines. See Wikipedia for algorithm.
EMSTATUS GLIB_drawLine ( GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t x2, int32_t y2)
Draws a line from x1,y1 to x2, y2.
EMSTATUS GLIB_drawLineH ( GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t x2)
Draws a horizontal line from x1, y1 to x2, y2.
EMSTATUS GLIB_drawLineV ( GLIB_Context_t *pContext, int32_t x1, int32_t y1, int32_t y2)
Draws a vertical line from x1, y1 to x1, y2.
static uint8_t GLIB_getClipCode ( GLIB_Context_t *pContext, int32_t x, int32_t y)
Gets the clip code for the point that is used by Cohen-Sutherland algorithm.

Function Documentation

 static bool GLIB_clipLine ( GLIB_Context_t * ``` pContext, ``` int32_t * ``` pX1, ``` int32_t * ``` pY1, ``` int32_t * ``` pX2, ``` int32_t * ``` pY2 ``` )
static

Clips the line if necessary, using the Cohen-Sutherland algorithm for clipping lines. See Wikipedia for algorithm.

The points are moved using the linear equations: y=y0+slope*(x-x0),x=x0+(1/slope)*(y-y0)

Parameters
 ``` pContext ``` Pointer to the GLIB_Context_t which holds the clipping region ``` pX1 ``` Pointer to the start x-coordinate ``` pY1 ``` Pointer to the start y-coordinate ``` pX2 ``` Pointer to the end-x coordinate ``` pY2 ``` Pointer to the end-y coordinate
Returns
Returns true if the line is inside, or crosses into, the clipping region, otherwise return false

Definition at line ``` 244 ``` of file ``` glib_line.c ``` .

Referenced by GLIB_drawLine() .

 static uint8_t GLIB_getClipCode ( GLIB_Context_t * ``` pContext, ``` int32_t ``` x, ``` int32_t ``` y ``` )
static

Gets the clip code for the point that is used by Cohen-Sutherland algorithm.

Parameters
 ``` pContext ``` Pointer to the GLIB_Context_t which holds the clipping region ``` x ``` Start x-coordinate ``` y ``` Start y-coordinate
Returns
Returns the 4-bit clip code

Definition at line ``` 194 ``` of file ``` glib_line.c ``` .

Referenced by GLIB_clipLine() .