pmc/vector.cc
author Markus Bröker <mbroeker@largo.dyndns.tv>
Sun, 26 Jul 2009 18:21:25 +0200
changeset 103 be3fe4a4f097
parent 77 49e0babccb23
permissions -rw-r--r--
Function Pointer Demo simplified It makes more sense to show the basic usage of fps committer: Markus Bröker <mbroeker@largo.homelinux.org>

/**
 * pmc/vector.cc
 * Copyright (C) 2008 Markus Broeker
 */

#include <cmath>
#include <vector.hpp>

#include <cstdio>

using namespace algebra;

Vector::Vector (int xx, int yy)
{
    name = "Vector";
    x = xx;
    y = yy;
    mode = RAD;

    refCounter++;

#ifdef DEBUG
    fprintf (stderr, "New Vector: (%.3d, %.3d)\n", x, y);
#endif
}

Vector::Vector (const Vector & copy)
:x (copy.x), y (copy.y)
{
    fprintf (stderr, "Warning: Copy Constructor: ");
    vector ();
    fprintf (stderr, "\n");
    refCounter++;
}

Vector::~Vector ()
{
#ifdef DEBUG
    fprintf (stderr, "Bye, bye Vector: (%.3d, %.3d)\n", x, y);
#endif
}

int Vector::X ()
{
    return x;
}

int Vector::Y ()
{
    return y;
}

Vector Vector::operator+ (Vector & a)
{
    return Vector (x + a.X (), y + a.Y ());
}

Vector Vector::operator- (Vector & a)
{
    return Vector (x - a.X (), y - a.Y ());
}

double Vector::abs ()
{
    return (std::sqrt (x * x + y * y));
}

void Vector::vector ()
{
    fprintf (stderr, "(%.3d, %.3d)", x, y);
}

double Vector::angle (Vector & v)
{
    if (mode == DEG)
        return ((180.0 / M_PI) * std::acos ((v.X () * X () + v.Y () * Y ()) / (abs () * v.abs ())));

    return (std::acos ((v.X () * X () + v.Y () * Y ()) / (abs () * v.abs ())));
}

void Vector::setMode (Mode m)
{
    mode = m;
}