| 1 | /*****************************************************************************/ |
| 2 | // Copyright 2006 Adobe Systems Incorporated |
| 3 | // All Rights Reserved. |
| 4 | // |
| 5 | // NOTICE: Adobe permits you to use, modify, and distribute this file in |
| 6 | // accordance with the terms of the Adobe license agreement accompanying it. |
| 7 | /*****************************************************************************/ |
| 8 | |
| 9 | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_point.h#1 $ */ |
| 10 | /* $DateTime: 2012/05/30 13:28:51 $ */ |
| 11 | /* $Change: 832332 $ */ |
| 12 | /* $Author: tknoll $ */ |
| 13 | |
| 14 | /*****************************************************************************/ |
| 15 | |
| 16 | #ifndef __dng_point__ |
| 17 | #define __dng_point__ |
| 18 | |
| 19 | /*****************************************************************************/ |
| 20 | |
| 21 | #include "dng_safe_arithmetic.h" |
| 22 | #include "dng_types.h" |
| 23 | #include "dng_utils.h" |
| 24 | |
| 25 | /*****************************************************************************/ |
| 26 | |
| 27 | class dng_point |
| 28 | { |
| 29 | |
| 30 | public: |
| 31 | |
| 32 | int32 v; |
| 33 | int32 h; |
| 34 | |
| 35 | public: |
| 36 | |
| 37 | dng_point () |
| 38 | : v (0) |
| 39 | , h (0) |
| 40 | { |
| 41 | } |
| 42 | |
| 43 | dng_point (int32 vv, int32 hh) |
| 44 | : v (vv) |
| 45 | , h (hh) |
| 46 | { |
| 47 | } |
| 48 | |
| 49 | bool operator== (const dng_point &pt) const |
| 50 | { |
| 51 | return (v == pt.v) && |
| 52 | (h == pt.h); |
| 53 | } |
| 54 | |
| 55 | bool operator!= (const dng_point &pt) const |
| 56 | { |
| 57 | return !(*this == pt); |
| 58 | } |
| 59 | |
| 60 | }; |
| 61 | |
| 62 | /*****************************************************************************/ |
| 63 | |
| 64 | class dng_point_real64 |
| 65 | { |
| 66 | |
| 67 | public: |
| 68 | |
| 69 | real64 v; |
| 70 | real64 h; |
| 71 | |
| 72 | public: |
| 73 | |
| 74 | dng_point_real64 () |
| 75 | : v (0.0) |
| 76 | , h (0.0) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | dng_point_real64 (real64 vv, real64 hh) |
| 81 | : v (vv) |
| 82 | , h (hh) |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | dng_point_real64 (const dng_point &pt) |
| 87 | : v ((real64) pt.v) |
| 88 | , h ((real64) pt.h) |
| 89 | { |
| 90 | } |
| 91 | |
| 92 | bool operator== (const dng_point_real64 &pt) const |
| 93 | { |
| 94 | return (v == pt.v) && |
| 95 | (h == pt.h); |
| 96 | } |
| 97 | |
| 98 | bool operator!= (const dng_point_real64 &pt) const |
| 99 | { |
| 100 | return !(*this == pt); |
| 101 | } |
| 102 | |
| 103 | dng_point Round () const |
| 104 | { |
| 105 | return dng_point (Round_int32 (v), |
| 106 | Round_int32 (h)); |
| 107 | } |
| 108 | |
| 109 | }; |
| 110 | |
| 111 | /*****************************************************************************/ |
| 112 | |
| 113 | inline dng_point operator+ (const dng_point &a, |
| 114 | const dng_point &b) |
| 115 | |
| 116 | |
| 117 | { |
| 118 | |
| 119 | return dng_point (SafeInt32Add(a.v, b.v), |
| 120 | SafeInt32Add(a.h, b.h)); |
| 121 | |
| 122 | } |
| 123 | |
| 124 | /*****************************************************************************/ |
| 125 | |
| 126 | inline dng_point_real64 operator+ (const dng_point_real64 &a, |
| 127 | const dng_point_real64 &b) |
| 128 | |
| 129 | |
| 130 | { |
| 131 | |
| 132 | return dng_point_real64 (a.v + b.v, |
| 133 | a.h + b.h); |
| 134 | |
| 135 | } |
| 136 | |
| 137 | /*****************************************************************************/ |
| 138 | |
| 139 | inline dng_point operator- (const dng_point &a, |
| 140 | const dng_point &b) |
| 141 | |
| 142 | |
| 143 | { |
| 144 | |
| 145 | return dng_point (SafeInt32Sub(a.v, b.v), |
| 146 | SafeInt32Sub(a.h, b.h)); |
| 147 | |
| 148 | } |
| 149 | |
| 150 | /*****************************************************************************/ |
| 151 | |
| 152 | inline dng_point_real64 operator- (const dng_point_real64 &a, |
| 153 | const dng_point_real64 &b) |
| 154 | |
| 155 | |
| 156 | { |
| 157 | |
| 158 | return dng_point_real64 (a.v - b.v, |
| 159 | a.h - b.h); |
| 160 | |
| 161 | } |
| 162 | |
| 163 | /*****************************************************************************/ |
| 164 | |
| 165 | inline real64 DistanceSquared (const dng_point_real64 &a, |
| 166 | const dng_point_real64 &b) |
| 167 | |
| 168 | |
| 169 | { |
| 170 | |
| 171 | dng_point_real64 diff = a - b; |
| 172 | |
| 173 | return (diff.v * diff.v) + (diff.h * diff.h); |
| 174 | |
| 175 | } |
| 176 | |
| 177 | /*****************************************************************************/ |
| 178 | |
| 179 | inline dng_point Transpose (const dng_point &a) |
| 180 | { |
| 181 | |
| 182 | return dng_point (a.h, a.v); |
| 183 | |
| 184 | } |
| 185 | |
| 186 | /*****************************************************************************/ |
| 187 | |
| 188 | inline dng_point_real64 Transpose (const dng_point_real64 &a) |
| 189 | { |
| 190 | |
| 191 | return dng_point_real64 (a.h, a.v); |
| 192 | |
| 193 | } |
| 194 | |
| 195 | /*****************************************************************************/ |
| 196 | |
| 197 | #endif |
| 198 | |
| 199 | /*****************************************************************************/ |
| 200 | |