EFM32 Happy Gecko Software Documentation  efm32hg-doc-5.1.2
glib_line.c File Reference

Detailed Description

Silicon Labs Graphics Library: Line Drawing Routines.

License

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"

Go to the source code of this file.

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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

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
pContextPointer to the GLIB_Context_t which holds the clipping region
pX1Pointer to the start x-coordinate
pY1Pointer to the start y-coordinate
pX2Pointer to the end-x coordinate
pY2Pointer 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 217 of file glib_line.c.

References __GLIB_Context_t::clippingRegion, GLIB_getClipCode(), __GLIB_Rectangle_t::xMax, __GLIB_Rectangle_t::xMin, __GLIB_Rectangle_t::yMax, and __GLIB_Rectangle_t::yMin.

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
pContextPointer to the GLIB_Context_t which holds the clipping region
xStart x-coordinate
yStart y-coordinate
Returns
Returns the 4-bit clip code

Definition at line 175 of file glib_line.c.

References __GLIB_Context_t::clippingRegion, __GLIB_Rectangle_t::xMax, and __GLIB_Rectangle_t::yMax.

Referenced by GLIB_clipLine().