2 * Copyright (C) 2010 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef ANDROID_HWUI_VECTOR_H
18 #define ANDROID_HWUI_VECTOR_H
21 #include <utils/Log.h>
24 namespace uirenderer {
26 ///////////////////////////////////////////////////////////////////////////////
28 ///////////////////////////////////////////////////////////////////////////////
30 // MUST BE A POD - this means no ctor or dtor!
35 float lengthSquared() const {
39 float length() const {
40 return sqrt(x * x + y * y);
43 void operator+=(const Vector2& v) {
48 void operator-=(const Vector2& v) {
53 void operator+=(const float v) {
58 void operator-=(const float v) {
63 void operator/=(float s) {
68 void operator*=(float s) {
73 Vector2 operator+(const Vector2& v) const {
74 return (Vector2){x + v.x, y + v.y};
77 Vector2 operator-(const Vector2& v) const {
78 return (Vector2){x - v.x, y - v.y};
81 Vector2 operator/(float s) const {
82 return (Vector2){x / s, y / s};
85 Vector2 operator*(float s) const {
86 return (Vector2){x * s, y * s};
90 float s = 1.0f / length();
95 Vector2 copyNormalized() const {
101 float dot(const Vector2& v) const {
102 return x * v.x + y * v.y;
105 float cross(const Vector2& v) const {
106 return x * v.y - y * v.x;
110 ALOGD("Vector2[%.2f, %.2f]", x, y);
114 // MUST BE A POD - this means no ctor or dtor!
121 Vector3 operator+(const Vector3& v) const {
122 return (Vector3){x + v.x, y + v.y, z + v.z};
125 Vector3 operator-(const Vector3& v) const {
126 return (Vector3){x - v.x, y - v.y, z - v.z};
129 Vector3 operator/(float s) const {
130 return (Vector3){x / s, y / s, z / s};
133 Vector3 operator*(float s) const {
134 return (Vector3){x * s, y * s, z * s};
138 void dump(const char* label = "Vector3") const {
139 ALOGD("%s[%.2f, %.2f, %.2f]", label, x, y, z);
143 }; // namespace uirenderer
144 }; // namespace android
146 #endif // ANDROID_HWUI_VECTOR_H