File: float_point_3d.cc

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (73 lines) | stat: -rw-r--r-- 2,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org>
                  2004, 2005 Rob Buis <buis@kde.org>
                  2005 Eric Seidel <eric@webkit.org>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    aint with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include "third_party/blink/renderer/platform/geometry/float_point_3d.h"

#include <math.h>

#include "third_party/blink/renderer/platform/wtf/math_extras.h"
#include "third_party/blink/renderer/platform/wtf/text/text_stream.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "ui/gfx/geometry/point3_f.h"

namespace blink {

void FloatPoint3D::Normalize() {
  float temp_length = length();

  if (temp_length) {
    x_ /= temp_length;
    y_ /= temp_length;
    z_ /= temp_length;
  }
}

float FloatPoint3D::AngleBetween(const FloatPoint3D& y) const {
  float x_length = this->length();
  float y_length = y.length();

  if (x_length && y_length) {
    float cos_angle = this->Dot(y) / (x_length * y_length);
    // Due to round-off |cosAngle| can have a magnitude greater than 1.  Clamp
    // the value to [-1, 1] before computing the angle.
    return acos(clampTo(cos_angle, -1.0, 1.0));
  }
  return 0;
}

FloatPoint3D::operator gfx::Point3F() const {
  return gfx::Point3F(x_, y_, z_);
}

std::ostream& operator<<(std::ostream& ostream, const FloatPoint3D& point) {
  return ostream << point.ToString();
}

String FloatPoint3D::ToString() const {
  return String::Format("%lg,%lg,%lg", X(), Y(), Z());
}

WTF::TextStream& operator<<(WTF::TextStream& ts, const FloatPoint3D& p) {
  ts << "x=" << p.X() << " y=" << p.Y() << " z=" << p.Z();
  return ts;
}

}  // namespace blink