Displays distance to start location on OLED screen.

Dependencies:   mbed

Committer:
iforce2d
Date:
Wed Mar 07 12:49:14 2018 +0000
Revision:
0:972874f31c98
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iforce2d 0:972874f31c98 1 /*
iforce2d 0:972874f31c98 2
iforce2d 0:972874f31c98 3 u8g_clip.c
iforce2d 0:972874f31c98 4
iforce2d 0:972874f31c98 5 procedures for clipping
iforce2d 0:972874f31c98 6 taken over from procs in u8g_pb.c
iforce2d 0:972874f31c98 7
iforce2d 0:972874f31c98 8 Universal 8bit Graphics Library
iforce2d 0:972874f31c98 9
iforce2d 0:972874f31c98 10 Copyright (c) 2012, olikraus@gmail.com
iforce2d 0:972874f31c98 11 All rights reserved.
iforce2d 0:972874f31c98 12
iforce2d 0:972874f31c98 13 Redistribution and use in source and binary forms, with or without modification,
iforce2d 0:972874f31c98 14 are permitted provided that the following conditions are met:
iforce2d 0:972874f31c98 15
iforce2d 0:972874f31c98 16 * Redistributions of source code must retain the above copyright notice, this list
iforce2d 0:972874f31c98 17 of conditions and the following disclaimer.
iforce2d 0:972874f31c98 18
iforce2d 0:972874f31c98 19 * Redistributions in binary form must reproduce the above copyright notice, this
iforce2d 0:972874f31c98 20 list of conditions and the following disclaimer in the documentation and/or other
iforce2d 0:972874f31c98 21 materials provided with the distribution.
iforce2d 0:972874f31c98 22
iforce2d 0:972874f31c98 23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
iforce2d 0:972874f31c98 24 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
iforce2d 0:972874f31c98 25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iforce2d 0:972874f31c98 26 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
iforce2d 0:972874f31c98 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
iforce2d 0:972874f31c98 28 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
iforce2d 0:972874f31c98 29 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
iforce2d 0:972874f31c98 30 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
iforce2d 0:972874f31c98 31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
iforce2d 0:972874f31c98 32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
iforce2d 0:972874f31c98 33 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
iforce2d 0:972874f31c98 34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
iforce2d 0:972874f31c98 35 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
iforce2d 0:972874f31c98 36
iforce2d 0:972874f31c98 37 Notes
iforce2d 0:972874f31c98 38
iforce2d 0:972874f31c98 39 This is one of the most critical parts of u8glib. It must be fast, but still reliable.
iforce2d 0:972874f31c98 40 Based on the intersection program (see tools folder), there is minimized version of
iforce2d 0:972874f31c98 41 the condition for the intersaction test:
iforce2d 0:972874f31c98 42 minimized version
iforce2d 0:972874f31c98 43 ---1----0 1 b1 <= a2 && b1 > b2
iforce2d 0:972874f31c98 44 -----1--0 1 b2 >= a1 && b1 > b2
iforce2d 0:972874f31c98 45 ---1-1--- 1 b1 <= a2 && b2 >= a1
iforce2d 0:972874f31c98 46 It includes the assumption, that a1 <= a2 is always true (correct, because
iforce2d 0:972874f31c98 47 a1, a2 are the page dimensions.
iforce2d 0:972874f31c98 48
iforce2d 0:972874f31c98 49 The direct implementation of the above result is done in:
iforce2d 0:972874f31c98 50 uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 51 However, this is slower than a decision tree version:
iforce2d 0:972874f31c98 52 static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 53 Also suprising is, that the macro implementation is slower than the inlined version.
iforce2d 0:972874f31c98 54
iforce2d 0:972874f31c98 55 The decision tree is based on the expansion of the truth table.
iforce2d 0:972874f31c98 56
iforce2d 0:972874f31c98 57 */
iforce2d 0:972874f31c98 58
iforce2d 0:972874f31c98 59 #include "u8g.h"
iforce2d 0:972874f31c98 60
iforce2d 0:972874f31c98 61 #ifdef __GNUC__
iforce2d 0:972874f31c98 62 #define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline))
iforce2d 0:972874f31c98 63 #else
iforce2d 0:972874f31c98 64 #define U8G_ALWAYS_INLINE
iforce2d 0:972874f31c98 65 #endif
iforce2d 0:972874f31c98 66
iforce2d 0:972874f31c98 67 /*
iforce2d 0:972874f31c98 68 intersection assumptions:
iforce2d 0:972874f31c98 69 a1 <= a2 is always true
iforce2d 0:972874f31c98 70
iforce2d 0:972874f31c98 71 minimized version
iforce2d 0:972874f31c98 72 ---1----0 1 b1 <= a2 && b1 > b2
iforce2d 0:972874f31c98 73 -----1--0 1 b2 >= a1 && b1 > b2
iforce2d 0:972874f31c98 74 ---1-1--- 1 b1 <= a2 && b2 >= a1
iforce2d 0:972874f31c98 75 */
iforce2d 0:972874f31c98 76
iforce2d 0:972874f31c98 77 #ifdef OLD_CODE_WHICH_IS_TOO_SLOW
iforce2d 0:972874f31c98 78 static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 79 {
iforce2d 0:972874f31c98 80 uint8_t c1, c2, c3, tmp;
iforce2d 0:972874f31c98 81 c1 = v0 <= a1;
iforce2d 0:972874f31c98 82 c2 = v1 >= a0;
iforce2d 0:972874f31c98 83 c3 = v0 > v1;
iforce2d 0:972874f31c98 84
iforce2d 0:972874f31c98 85 tmp = c1;
iforce2d 0:972874f31c98 86 c1 &= c2;
iforce2d 0:972874f31c98 87 c2 &= c3;
iforce2d 0:972874f31c98 88 c3 &= tmp;
iforce2d 0:972874f31c98 89 c1 |= c2;
iforce2d 0:972874f31c98 90 c1 |= c3;
iforce2d 0:972874f31c98 91 return c1 & 1;
iforce2d 0:972874f31c98 92 }
iforce2d 0:972874f31c98 93 #endif
iforce2d 0:972874f31c98 94
iforce2d 0:972874f31c98 95 #define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) ))
iforce2d 0:972874f31c98 96
iforce2d 0:972874f31c98 97 //static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE;
iforce2d 0:972874f31c98 98 static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 99 {
iforce2d 0:972874f31c98 100 /* surprisingly the macro leads to larger code */
iforce2d 0:972874f31c98 101 /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */
iforce2d 0:972874f31c98 102 if ( v0 <= a1 )
iforce2d 0:972874f31c98 103 {
iforce2d 0:972874f31c98 104 if ( v1 >= a0 )
iforce2d 0:972874f31c98 105 {
iforce2d 0:972874f31c98 106 return 1;
iforce2d 0:972874f31c98 107 }
iforce2d 0:972874f31c98 108 else
iforce2d 0:972874f31c98 109 {
iforce2d 0:972874f31c98 110 if ( v0 > v1 )
iforce2d 0:972874f31c98 111 {
iforce2d 0:972874f31c98 112 return 1;
iforce2d 0:972874f31c98 113 }
iforce2d 0:972874f31c98 114 else
iforce2d 0:972874f31c98 115 {
iforce2d 0:972874f31c98 116 return 0;
iforce2d 0:972874f31c98 117 }
iforce2d 0:972874f31c98 118 }
iforce2d 0:972874f31c98 119 }
iforce2d 0:972874f31c98 120 else
iforce2d 0:972874f31c98 121 {
iforce2d 0:972874f31c98 122 if ( v1 >= a0 )
iforce2d 0:972874f31c98 123 {
iforce2d 0:972874f31c98 124 if ( v0 > v1 )
iforce2d 0:972874f31c98 125 {
iforce2d 0:972874f31c98 126 return 1;
iforce2d 0:972874f31c98 127 }
iforce2d 0:972874f31c98 128 else
iforce2d 0:972874f31c98 129 {
iforce2d 0:972874f31c98 130 return 0;
iforce2d 0:972874f31c98 131 }
iforce2d 0:972874f31c98 132 }
iforce2d 0:972874f31c98 133 else
iforce2d 0:972874f31c98 134 {
iforce2d 0:972874f31c98 135 return 0;
iforce2d 0:972874f31c98 136 }
iforce2d 0:972874f31c98 137 }
iforce2d 0:972874f31c98 138 }
iforce2d 0:972874f31c98 139
iforce2d 0:972874f31c98 140
iforce2d 0:972874f31c98 141 uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
iforce2d 0:972874f31c98 142 {
iforce2d 0:972874f31c98 143 register u8g_uint_t tmp;
iforce2d 0:972874f31c98 144 tmp = y;
iforce2d 0:972874f31c98 145 tmp += h;
iforce2d 0:972874f31c98 146 tmp--;
iforce2d 0:972874f31c98 147 if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 )
iforce2d 0:972874f31c98 148 return 0;
iforce2d 0:972874f31c98 149
iforce2d 0:972874f31c98 150 tmp = x;
iforce2d 0:972874f31c98 151 tmp += w;
iforce2d 0:972874f31c98 152 tmp--;
iforce2d 0:972874f31c98 153 return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp);
iforce2d 0:972874f31c98 154 }
iforce2d 0:972874f31c98 155
iforce2d 0:972874f31c98 156
iforce2d 0:972874f31c98 157