Skip to content
Browse files

[droid] utils: add CVector utility class

  • Loading branch information...
1 parent 0185fcc commit b8e83947e4e7965fa33a579162b932373a422494 @Montellese Montellese committed with Cory Fields Jul 22, 2012
Showing with 119 additions and 2 deletions.
  1. +3 −2 xbmc/utils/Makefile
  2. +75 −0 xbmc/utils/Vector.cpp
  3. +41 −0 xbmc/utils/Vector.h
View
5 xbmc/utils/Makefile
@@ -3,7 +3,7 @@ SRCS=AlarmClock.cpp \
Archive.cpp \
AsyncFileCopy.cpp \
AutoPtrHandle.cpp \
- Base64.cpp \
+ Base64.cpp \
BitstreamStats.cpp \
CharsetConverter.cpp \
CPUInfo.cpp \
@@ -25,7 +25,7 @@ SRCS=AlarmClock.cpp \
HTMLUtil.cpp \
HttpHeader.cpp \
HttpParser.cpp \
- HttpResponse.cpp \
+ HttpResponse.cpp \
InfoLoader.cpp \
JobManager.cpp \
JSONVariantParser.cpp \
@@ -59,6 +59,7 @@ SRCS=AlarmClock.cpp \
TuxBoxUtil.cpp \
URIUtils.cpp \
Variant.cpp \
+ Vector.cpp \
Weather.cpp \
XBMCTinyXML.cpp \
XMLUtils.cpp \
View
75 xbmc/utils/Vector.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <math.h>
+
+#include "Vector.h"
+
+CVector::CVector()
+{
+ reset();
+}
+
+CVector::CVector(float xCoord, float yCoord)
+ : x(xCoord),
+ y(yCoord)
+{ }
+
+void CVector::reset()
+{
+ x = 0.0f;
+ y = 0.0f;
+}
+
+const CVector CVector::operator+(const CVector &other) const
+{
+ return CVector(x + other.x, y + other.y);
+}
+
+const CVector CVector::operator-(const CVector &other) const
+{
+ return CVector(x - other.x, y - other.y);
+}
+
+CVector& CVector::operator+=(const CVector &other)
+{
+ x += other.x;
+ y += other.y;
+
+ return *this;
+}
+
+CVector& CVector::operator-=(const CVector &other)
+{
+ x -= other.x;
+ y -= other.y;
+
+ return *this;
+}
+
+float CVector::scalar(const CVector &other) const
+{
+ return x * other.x + y * other.y;
+}
+
+float CVector::length() const
+{
+ return sqrt(pow(x, 2) + pow(y, 2));
+}
View
41 xbmc/utils/Vector.h
@@ -0,0 +1,41 @@
+#pragma once
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+class CVector
+{
+public:
+ CVector();
+ CVector(float xCoord, float yCoord);
+ virtual ~CVector() { }
+
+ virtual void reset();
+
+ const CVector operator+(const CVector &other) const;
+ const CVector operator-(const CVector &other) const;
+ CVector& operator+=(const CVector &other);
+ CVector& operator-=(const CVector &other);
+
+ float scalar(const CVector &other) const;
+ float length() const;
+
+ float x;
+ float y;
+};

0 comments on commit b8e8394

Please sign in to comment.
Something went wrong with that request. Please try again.