glib_line.c File Reference
Silicon Labs Graphics Library: Line Drawing Routines.
License
Copyright 2018 Silicon Laboratories Inc. www.silabs.com
The licensor of this software is Silicon Laboratories Inc. Your use of this software is governed by the terms of Silicon Labs Master Software License Agreement (MSLA) available at www.silabs.com/about-us/legal/master-software-license-agreement. This software is distributed to you in Source Code format and is governed by the sections of the MSLA applicable to Source Code.
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 |
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
247
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 |
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
197
of file
glib_line.c
.
References __GLIB_Context_t::clippingRegion , __GLIB_Rectangle_t::xMax , and __GLIB_Rectangle_t::yMax .
Referenced by GLIB_clipLine() .