Changeset 1020 for cpp/frams/util/3d.cpp


Ignore:
Timestamp:
07/24/20 21:44:10 (5 years ago)
Author:
Maciej Komosinski
Message:

Added double Pt3D::minComponent() and maxComponent()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/3d.cpp

    r375 r1020  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    66#include <common/log.h>
    77#include "3d.h"
     8#include <algorithm> // std::min(), std::max()
    89
    910Pt3D operator+(const Pt3D &p1, const Pt3D &p2) { return Pt3D(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z); }
     
    1617double Pt3D::operator()() const
    1718{
    18         double q = x*x + y*y + z*z;
     19        double q = x * x + y * y + z * z;
    1920        if (q < 0) { if (report_errors) logPrintf("Pt3D", "operator()", LOG_ERROR, "sqrt(%g): domain error", q); return 0; }
    2021        return sqrt(q);
     
    3435        double dy = y - p.y;
    3536        double dz = z - p.z;
    36         return sqrt(dx*dx + dy*dy + dz*dz);
     37        return sqrt(dx * dx + dy * dy + dz * dz);
    3738}
    3839
     
    4849{
    4950        double s = sin(k), c = cos(k);
    50         double t = c*x - s*y;
    51         y = s*x + c*y;
     51        double t = c * x - s * y;
     52        y = s * x + c * y;
    5253        x = t;
    5354}
     
    5556void rotate2D(double s, double c, double &x, double &y)
    5657{
    57         double t = c*x - s*y;
    58         y = s*x + c*y;
     58        double t = c * x - s * y;
     59        y = s * x + c * y;
    5960        x = t;
    6061}
     
    105106}
    106107
     108double Pt3D::minComponent() const
     109{
     110        return std::min(x, std::min(y, z));
     111}
     112
     113double Pt3D::maxComponent() const
     114{
     115        return std::max(x, std::max(y, z));
     116}
     117
    107118void Pt3D::vectorProduct(const Pt3D& a, const Pt3D& b)
    108119{
    109         x = a.y*b.z - a.z*b.y;
    110         y = a.z*b.x - a.x*b.z;
    111         z = a.x*b.y - a.y*b.x;
     120        x = a.y * b.z - a.z * b.y;
     121        y = a.z * b.x - a.x * b.z;
     122        z = a.x * b.y - a.y * b.x;
    112123}
    113124
     
    146157double d2(double x, double y)
    147158{
    148         double q = x*x + y*y;
     159        double q = x * x + y * y;
    149160        if (q < 0) { if (Pt3D::report_errors) logPrintf("", "d2()", LOG_ERROR, "sqrt(%g): domain error", q); return 0; }
    150161        return sqrt(q);
     
    192203void Orient::transform(Pt3D& target, const Pt3D &s) const
    193204{
    194         target.x = s.x*x.x + s.y*y.x + s.z*z.x;
    195         target.y = s.x*x.y + s.y*y.y + s.z*z.y;
    196         target.z = s.x*x.z + s.y*y.z + s.z*z.z;
     205        target.x = s.x * x.x + s.y * y.x + s.z * z.x;
     206        target.y = s.x * x.y + s.y * y.y + s.z * z.y;
     207        target.z = s.x * x.z + s.y * y.z + s.z * z.z;
    197208}
    198209
    199210void Orient::revTransform(Pt3D& target, const Pt3D &s) const
    200211{
    201         target.x = s.x*x.x + s.y*x.y + s.z*x.z;
    202         target.y = s.x*y.x + s.y*y.y + s.z*y.z;
    203         target.z = s.x*z.x + s.y*z.y + s.z*z.z;
     212        target.x = s.x * x.x + s.y * x.y + s.z * x.z;
     213        target.y = s.x * y.x + s.y * y.y + s.z * y.z;
     214        target.z = s.x * z.x + s.y * z.y + s.z * z.z;
    204215}
    205216
Note: See TracChangeset for help on using the changeset viewer.