Changeset 1130 for cpp/common/2d.h


Ignore:
Timestamp:
04/16/21 15:55:34 (3 years ago)
Author:
Maciej Komosinski
Message:

Used std::min(), std::max() explicitly to avoid compiler confusion. Used std::size() explicitly instead of the equivalent macro

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/2d.h

    r1028 r1130  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2021  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#define _2D_H_
    77
    8 #include "nonstd_stl.h"
    98#include <math.h>
     9#include <algorithm>
    1010
    1111//unification of old GUIXY and Pt2D
     
    5858template<> inline bool XY<int>::operator==(const XY<int> &p) const { return (x == p.x) && (y == p.y); }
    5959
    60 template <typename T> XY<T> xymin(const XY<T> &a, const XY<T> &b) { return XY<T>(min(a.x, b.x), min(a.y, b.y)); }
    61 template <typename T> XY<T> xymax(const XY<T> &a, const XY<T> &b) { return XY<T>(max(a.x, b.x), max(a.y, b.y)); }
     60template <typename T> XY<T> xymin(const XY<T> &a, const XY<T> &b) { return XY<T>(std::min(a.x, b.x), std::min(a.y, b.y)); }
     61template <typename T> XY<T> xymax(const XY<T> &a, const XY<T> &b) { return XY<T>(std::max(a.x, b.x), std::max(a.y, b.y)); }
    6262
    6363template <typename T>
     
    7474        T vertical() const { return top + bottom; }
    7575        bool operator==(const XYMargin &other) const { return left == other.left && top == other.top && right == other.right && bottom == other.bottom; }
    76         XYMargin normalized() const { return XYMargin(max(left, T(0)), max(top, T(0)), max(right, T(0)), max(bottom, T(0))); }
     76        XYMargin normalized() const { return XYMargin(std::max(left, T(0)), std::max(top, T(0)), std::max(right, T(0)), std::max(bottom, T(0))); }
    7777};
    7878
     
    162162        }
    163163
    164         XYRect fitAspect(float aspect) ///< place a new rectangle having 'aspect' inside the rectangle
     164        XYRect fitAspect(float aspect) const ///< place a new rectangle having 'aspect' inside the rectangle
    165165        {
    166166                XYRect r;
     
    179179                XY<T> p2 = p + size;
    180180                XY<T> rp2 = r.p + r.size;
    181                 i.p.x = max(p.x, r.p.x);
    182                 i.p.y = max(p.y, r.p.y);
    183                 i.size.x = min(p2.x, rp2.x) - i.p.x;
    184                 i.size.y = min(p2.y, rp2.y) - i.p.y;
     181                i.p.x = std::max(p.x, r.p.x);
     182                i.p.y = std::max(p.y, r.p.y);
     183                i.size.x = std::min(p2.x, rp2.x) - i.p.x;
     184                i.size.y = std::min(p2.y, rp2.y) - i.p.y;
    185185                return i;
    186186        }
Note: See TracChangeset for help on using the changeset viewer.