comparison layer/Layer.cpp @ 904:e0f08e108064 cxx11

Move to using double rather than float for floating-point calculations (float only for storage); more build fixes
author Chris Cannam
date Mon, 09 Mar 2015 12:02:10 +0000
parents 4c8ca536b54f
children b66fb15de477
comparison
equal deleted inserted replaced
903:1757933ce5a7 904:e0f08e108064
137 setLayerDormant(view, !show); 137 setLayerDormant(view, !show);
138 emit layerParametersChanged(); 138 emit layerParametersChanged();
139 } 139 }
140 140
141 bool 141 bool
142 Layer::getXScaleValue(const View *v, int x, float &value, QString &unit) const 142 Layer::getXScaleValue(const View *v, int x, double &value, QString &unit) const
143 { 143 {
144 if (!hasTimeXAxis()) return false; 144 if (!hasTimeXAxis()) return false;
145 145
146 const Model *m = getModel(); 146 const Model *m = getModel();
147 if (!m) return false; 147 if (!m) return false;
148 148
149 value = float(v->getFrameForX(x)) / m->getSampleRate(); 149 value = double(v->getFrameForX(x)) / m->getSampleRate();
150 unit = "s"; 150 unit = "s";
151 return true; 151 return true;
152 } 152 }
153 153
154 bool 154 bool
155 Layer::getYScaleDifference(const View *v, int y0, int y1, 155 Layer::getYScaleDifference(const View *v, int y0, int y1,
156 float &diff, QString &unit) const 156 double &diff, QString &unit) const
157 { 157 {
158 float v0, v1; 158 double v0, v1;
159 if (!getYScaleValue(v, y0, v0, unit) || 159 if (!getYScaleValue(v, y0, v0, unit) ||
160 !getYScaleValue(v, y1, v1, unit)) { 160 !getYScaleValue(v, y1, v1, unit)) {
161 diff = 0.f; 161 diff = 0.f;
162 return false; 162 return false;
163 } 163 }
164 diff = fabsf(v1 - v0); 164 diff = fabs(v1 - v0);
165 return true; 165 return true;
166 } 166 }
167 167
168 int 168 sv_frame_t
169 Layer::alignToReference(View *v, int frame) const 169 Layer::alignToReference(View *v, sv_frame_t frame) const
170 { 170 {
171 const Model *m = getModel(); 171 const Model *m = getModel();
172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; 172 SVDEBUG << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl;
173 if (m && m->getAlignmentReference()) { 173 if (m && m->getAlignmentReference()) {
174 return m->alignToReference(frame); 174 return m->alignToReference(frame);
175 } else { 175 } else {
176 return v->alignToReference(frame); 176 return v->alignToReference(frame);
177 } 177 }
178 } 178 }
179 179
180 int 180 sv_frame_t
181 Layer::alignFromReference(View *v, int frame) const 181 Layer::alignFromReference(View *v, sv_frame_t frame) const
182 { 182 {
183 const Model *m = getModel(); 183 const Model *m = getModel();
184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl; 184 SVDEBUG << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << endl;
185 if (m && m->getAlignmentReference()) { 185 if (m && m->getAlignmentReference()) {
186 return m->alignFromReference(frame); 186 return m->alignFromReference(frame);
539 } 539 }
540 540
541 Layer::MeasureRectSet::const_iterator 541 Layer::MeasureRectSet::const_iterator
542 Layer::findFocusedMeasureRect(QPoint focusPoint) const 542 Layer::findFocusedMeasureRect(QPoint focusPoint) const
543 { 543 {
544 float frDist = 0; 544 double frDist = 0;
545 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end(); 545 MeasureRectSet::const_iterator focusRectItr = m_measureRects.end();
546 546
547 for (MeasureRectSet::const_iterator i = m_measureRects.begin(); 547 for (MeasureRectSet::const_iterator i = m_measureRects.begin();
548 i != m_measureRects.end(); ++i) { 548 i != m_measureRects.end(); ++i) {
549 549
552 int cx = i->pixrect.x() + i->pixrect.width()/2; 552 int cx = i->pixrect.x() + i->pixrect.width()/2;
553 int cy = i->pixrect.y() + i->pixrect.height()/2; 553 int cy = i->pixrect.y() + i->pixrect.height()/2;
554 int xd = focusPoint.x() - cx; 554 int xd = focusPoint.x() - cx;
555 int yd = focusPoint.y() - cy; 555 int yd = focusPoint.y() - cy;
556 556
557 float d = sqrt(float(xd * xd + yd * yd)); 557 double d = sqrt(double(xd * xd + yd * yd));
558 558
559 if (focusRectItr == m_measureRects.end() || d < frDist) { 559 if (focusRectItr == m_measureRects.end() || d < frDist) {
560 focusRectItr = i; 560 focusRectItr = i;
561 frDist = d; 561 frDist = d;
562 } 562 }