Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) QVector2DExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppQVector2DExample1/CppQVector2DExample1.pro

 

include(../../ConsoleApplication.pri) #Or use the code below
# QT += core
# QT += gui
# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# CONFIG   += console
# CONFIG   -= app_bundle
# TEMPLATE = app
# CONFIG(release, debug|release) {
#   DEFINES += NDEBUG NTRACE_BILDERBIKKEL
# }
# QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
# unix {
#   QMAKE_CXXFLAGS += -Werror
# }

include(../../Libraries/Boost.pri) #Or use the code below
# win32 {
#   INCLUDEPATH += \
#     ../../Libraries/boost_1_54_0
# }

SOURCES += main.cpp

 

 

 

 

 

./CppQVector2DExample1/main.cpp

 

#include <cassert>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-variable"
#include "QVector2D"
#pragma GCC diagnostic pop

int main()
{
  {
    //Basics
    QVector2D p;
    p.setX(1.0);
    p.setY(2.0);
    assert(p.x() == 1.0);
    assert(p.y() == 2.0);
  }
  {
    //distanceToPoint
    const QVector2D a(3.0,4.0);
    assert(qFuzzyCompare(static_cast<float>(5.0),a.distanceToPoint(QVector2D(0.0,0.0))));
  }
  {
    //dotProduct
    //From https://en.wikipedia.org/wiki/Dotproduct
    //'In particular, if A and B are orthogonal, then [...] A dot b = 0'
    const QVector2D a(1.0,0.0);
    const QVector2D b(0.0,1.0);
    const double p { QVector2D::dotProduct(a,b) };
    const double q { QVector2D::dotProduct(b,a) };
    const double expected { 0.0 };
    assert(qFuzzyCompare(p,expected));
    assert(qFuzzyCompare(q,expected));
  }

}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml