Skip to content

Commit

Permalink
ICOORD: Fix old type casts
Browse files Browse the repository at this point in the history
This fixes compiler warnings and avoids unnecessary conversions
between float and double.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Mar 2, 2019
1 parent fb0f1bc commit eb14726
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/ccstruct/points.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* File: points.h (Formerly coords.h)
* Description: Coordinate class definitions.
* Author: Ray Smith
* Created: Fri Mar 15 08:32:45 GMT 1991
*
* (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -72,12 +71,12 @@ class ICOORD

///find sq length
float sqlength() const {
return (float) (xcoord * xcoord + ycoord * ycoord);
return xcoord * xcoord + ycoord * ycoord;
}

///find length
float length() const {
return (float) sqrt (sqlength ());
return std::sqrt(sqlength());
}

///sq dist between pts
Expand All @@ -91,12 +90,12 @@ class ICOORD

///Distance between pts
float pt_to_pt_dist(const ICOORD &pt) const {
return (float) sqrt (pt_to_pt_sqdist (pt));
return std::sqrt(pt_to_pt_sqdist(pt));
}

///find angle
float angle() const {
return (float) atan2 ((double) ycoord, (double) xcoord);
return std::atan2(ycoord, xcoord);
}

///test equality
Expand Down Expand Up @@ -227,7 +226,7 @@ class DLLSYM FCOORD

///find length
float length() const {
return (float) sqrt (sqlength ());
return std::sqrt(sqlength());
}

///sq dist between pts
Expand All @@ -241,12 +240,12 @@ class DLLSYM FCOORD

///Distance between pts
float pt_to_pt_dist(const FCOORD &pt) const {
return (float) sqrt (pt_to_pt_sqdist (pt));
return std::sqrt(pt_to_pt_sqdist(pt));
}

///find angle
float angle() const {
return (float) atan2 (ycoord, xcoord);
return std::atan2(ycoord, xcoord);
}
// Returns the standard feature direction corresponding to this.
// See binary_angle_plus_pi below for a description of the direction.
Expand Down Expand Up @@ -536,10 +535,10 @@ int16_t scale) {

inline void ICOORD::rotate( //rotate by vector
const FCOORD& vec) {
int16_t tmp;

tmp = (int16_t) floor (xcoord * vec.x () - ycoord * vec.y () + 0.5);
ycoord = (int16_t) floor (ycoord * vec.x () + xcoord * vec.y () + 0.5);
int16_t tmp = static_cast<int16_t>(std::floor(xcoord * vec.x() -
ycoord * vec.y() + 0.5f));
ycoord = static_cast<int16_t>(std::floor(ycoord * vec.x() +
xcoord * vec.y() + 0.5f));
xcoord = tmp;
}

Expand Down

0 comments on commit eb14726

Please sign in to comment.