Skip to content

Commit ed2334c

Browse files
author
Gin
committed
fix box center distance
1 parent 9494465 commit ed2334c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

SerialPrograms/Source/CommonFramework/ImageTools/ImageBoxes.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,19 @@ size_t ImagePixelBox::distance_to_point_y(const size_t y) const{
108108
}
109109
// The distance from the box center to a point on x axis
110110
size_t ImagePixelBox::center_distance_to_point_x(const size_t x) const{
111-
size_t d = center_x() - x;
112-
return d > 0 ? d : -d;
111+
const size_t cx = center_x();
112+
if (cx >= x){
113+
return cx - x;
114+
}
115+
return x - cx;
113116
}
114117
// The distance from the box center to a point on y axis
115118
size_t ImagePixelBox::center_distance_to_point_y(const size_t y) const{
116-
size_t d = center_y() - y;
117-
return d > 0 ? d : -d;
119+
const size_t cy = center_y();
120+
if (cy >= y){
121+
return cy - y;
122+
}
123+
return y - cy;
118124
}
119125

120126

0 commit comments

Comments
 (0)