Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(361)

Side by Side Diff: third_party/agg23/agg_clip_liang_barsky.h

Issue 2226023002: Fixup various overflow conditions (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Review cleanup Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/agg23/README.pdfium ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 //---------------------------------------------------------------------------- 2 //----------------------------------------------------------------------------
3 // Anti-Grain Geometry - Version 2.3 3 // Anti-Grain Geometry - Version 2.3
4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com) 4 // Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
5 // 5 //
6 // Permission to copy, use, modify, sell and distribute this software 6 // Permission to copy, use, modify, sell and distribute this software
7 // is granted provided this copyright notice appears in all copies. 7 // is granted provided this copyright notice appears in all copies.
8 // This software is provided "as is" without express or implied 8 // This software is provided "as is" without express or implied
9 // warranty, and with no claim as to its suitability for any purpose. 9 // warranty, and with no claim as to its suitability for any purpose.
10 // 10 //
11 //---------------------------------------------------------------------------- 11 //----------------------------------------------------------------------------
12 // Contact: mcseem@antigrain.com 12 // Contact: mcseem@antigrain.com
13 // mcseemagg@yahoo.com 13 // mcseemagg@yahoo.com
14 // http://www.antigrain.com 14 // http://www.antigrain.com
15 //---------------------------------------------------------------------------- 15 //----------------------------------------------------------------------------
16 // 16 //
17 // Liang-Barsky clipping 17 // Liang-Barsky clipping
18 // 18 //
19 //---------------------------------------------------------------------------- 19 //----------------------------------------------------------------------------
20 #ifndef AGG_CLIP_LIANG_BARSKY_INCLUDED 20 #ifndef AGG_CLIP_LIANG_BARSKY_INCLUDED
21 #define AGG_CLIP_LIANG_BARSKY_INCLUDED 21 #define AGG_CLIP_LIANG_BARSKY_INCLUDED
22 #include "agg_basics.h" 22 #include "agg_basics.h"
23 #include "third_party/base/numerics/safe_math.h"
23 namespace agg 24 namespace agg
24 { 25 {
25 template<class T> 26 template<class T>
26 inline unsigned clipping_flags(T x, T y, const rect_base<T>& clip_box) 27 inline unsigned clipping_flags(T x, T y, const rect_base<T>& clip_box)
27 { 28 {
28 return (x > clip_box.x2) | 29 return (x > clip_box.x2) |
29 ((y > clip_box.y2) << 1) | 30 ((y > clip_box.y2) << 1) |
30 ((x < clip_box.x1) << 2) | 31 ((x < clip_box.x1) << 2) |
31 ((y < clip_box.y1) << 3); 32 ((y < clip_box.y1) << 3);
32 } 33 }
33 template<class T> 34 template<class T>
34 inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2, 35 inline unsigned clip_liang_barsky(T x1, T y1, T x2, T y2,
35 const rect_base<T>& clip_box, 36 const rect_base<T>& clip_box,
36 T* x, T* y) 37 T* x, T* y)
37 { 38 {
38 const FX_FLOAT nearzero = 1e-30f; 39 const FX_FLOAT nearzero = 1e-30f;
39 FX_FLOAT deltax = (FX_FLOAT)(x2 - x1); 40
40 FX_FLOAT deltay = (FX_FLOAT)(y2 - y1); 41 pdfium::base::CheckedNumeric<FX_FLOAT> width = x2;
42 width -= x1;
43 if (!width.IsValid())
44 return 0;
45 pdfium::base::CheckedNumeric<FX_FLOAT> height = y2;
46 height -= y1;
47 if (!height.IsValid())
48 return 0;
49
50 FX_FLOAT deltax = width.ValueOrDefault(0);
51 FX_FLOAT deltay = height.ValueOrDefault(0);
41 unsigned np = 0; 52 unsigned np = 0;
42 if(deltax == 0) { 53 if(deltax == 0) {
43 deltax = (x1 > clip_box.x1) ? -nearzero : nearzero; 54 deltax = (x1 > clip_box.x1) ? -nearzero : nearzero;
44 } 55 }
45 FX_FLOAT xin, xout; 56 FX_FLOAT xin, xout;
46 if(deltax > 0) { 57 if(deltax > 0) {
47 xin = (FX_FLOAT)clip_box.x1; 58 xin = (FX_FLOAT)clip_box.x1;
48 xout = (FX_FLOAT)clip_box.x2; 59 xout = (FX_FLOAT)clip_box.x2;
49 } else { 60 } else {
50 xin = (FX_FLOAT)clip_box.x2; 61 xin = (FX_FLOAT)clip_box.x2;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 127 }
117 ++np; 128 ++np;
118 } 129 }
119 } 130 }
120 } 131 }
121 } 132 }
122 return np; 133 return np;
123 } 134 }
124 } 135 }
125 #endif 136 #endif
OLDNEW
« no previous file with comments | « third_party/agg23/README.pdfium ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698