Skip to content

Commit

Permalink
[software_renderer] Fix build.
Browse files Browse the repository at this point in the history
Missing std includes resulted in build problems on some systems
as reported here: #11976
  • Loading branch information
mpimenov authored and bykoianko committed May 27, 2020
1 parent e8eb98a commit 12cc524
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
22 changes: 12 additions & 10 deletions software_renderer/point.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#ifndef __IA__POINT__
#define __IA__POINT__

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
#include <ostream>
#include <vector>

namespace ml
{
Expand Down Expand Up @@ -34,13 +36,13 @@ struct point_base
T x;
T y;

inline point_base()
point_base()
: x(std::numeric_limits<T>::quiet_NaN()), y(std::numeric_limits<T>::quiet_NaN())
{
}
inline point_base(T ix, T iy) : x(ix), y(iy) {}
point_base(T ix, T iy) : x(ix), y(iy) {}

inline operator bool() const { return (!std::isnan(x) && !std::isnan(y)); }
operator bool() const { return (!std::isnan(x) && !std::isnan(y)); }

T lon() const { return x; }
T lon(T l) { return (x = l); }
Expand All @@ -51,35 +53,35 @@ struct point_base
bool operator==(point_base const & p) const { return (x == p.x) && (y == p.y); }
bool operator!=(point_base const & p) const { return (x != p.x) || (y != p.y); }

inline bool in_range(point_base const & a, point_base const & b) const
bool in_range(point_base const & a, point_base const & b) const
{
return (std::min(a.x, b.x) <= x && x <= std::max(a.x, b.x)) &&
(std::min(a.y, b.y) <= y && y <= std::max(a.y, b.y));
}

bool operator<(point_base const & p) const { return (y == p.y) ? (x < p.x) : (y < p.y); }

double length() const { return sqrt(x * x + y * y); }
double length() const { return std::sqrt(x * x + y * y); }

double length2() const { return x * x + y * y; }

double angle(point_base const & pt) const // return angle in radians
{
double dx = pt.x - x;
double dy = pt.y - y;
return ((dx == 0) ? (3.1415 / 2 * (dy > 0 ? 1 : -1)) : atan(dy / dx)) - (dx < 0 ? 3.1415 : 0);
return ((dx == 0) ? (3.1415 / 2 * (dy > 0 ? 1 : -1)) : std::atan(dy / dx)) - (dx < 0 ? 3.1415 : 0);
}

double norm_angle(point_base const & pt) const // return angle in radians
{
double dx = pt.x - x;
double dy = pt.y - y;
return atan(-dy / dx) + ((dx < 0) ? 3.1415926536 : (dy < 0 ? 0 : 3.1415926536 * 2));
return std::atan(-dy / dx) + ((dx < 0) ? 3.1415926536 : (dy < 0 ? 0 : 3.1415926536 * 2));
}

point_base<T> vector(double length, double angle) const
{
return point_base<T>(x + length * cos(angle), y + length * sin(angle));
return point_base<T>(x + length * std::cos(angle), y + length * std::sin(angle));
}

int classify(point_base const & p0, point_base const & p1) const
Expand Down Expand Up @@ -134,7 +136,7 @@ inline double distance(point_base<T> const & p1, point_base<T> const & p2)
{
double dx = (p1.x - p2.x);
double dy = (p1.y - p2.y);
return sqrt(dx * dx + dy * dy);
return std::sqrt(dx * dx + dy * dy);
}

template <typename T>
Expand Down
9 changes: 6 additions & 3 deletions software_renderer/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

#include "software_renderer/point.h"

#include <algorithm>
#include <cmath>
#include <iostream>
#include <climits>
#include <limits>
#include <vector>

namespace ml
{
Expand Down Expand Up @@ -134,9 +137,9 @@ struct rect_base
return *this;
}

inline double height() const { return fabs(max.y - min.y); }
inline double height() const { return std::fabs(max.y - min.y); }

inline double width() const { return fabs(max.x - min.x); }
inline double width() const { return std::fabs(max.x - min.x); }

inline point center() const { return point((max.x + min.x) / 2, (max.y + min.y) / 2); }

Expand Down

0 comments on commit 12cc524

Please sign in to comment.