blob: 7f89eef58d28cba31b3f0f8a785223942d2a8fb0 [file] [log] [blame]
Marius Renn65953da2012-03-27 10:44:45 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17#ifndef ANDROID_FILTERFW_CORE_GEOMETRY_H
18#define ANDROID_FILTERFW_CORE_GEOMETRY_H
19
20#include <vector>
21
22namespace android {
23namespace filterfw {
24
25// This is an initial implementation of some geometrical structures. This is
26// likely to grow and become more sophisticated in the future.
27
28class Point {
29 public:
30 Point() : x_(0.0f), y_(0.0f) {}
31 Point(float x, float y) : x_(x), y_(y) {}
32
33 float x() const { return x_; }
34 float y() const { return y_; }
35
36 float Length() const;
37 bool ScaleTo(float new_length);
38 static float Distance(const Point& p0, const Point& p1);
39
40 // Add more of these as needed:
41 Point operator+(const Point& other) const;
42 Point operator-(const Point& other) const;
43 Point operator*(float factor) const;
44
45 void Rotate90Clockwise();
46
47 private:
48 float x_, y_;
49};
50
51class Quad {
52 public:
53 Quad() : points_(4) {}
54 virtual ~Quad() {}
55
56 Quad(const Point& p0, const Point& p1, const Point& p2, const Point& p3)
57 : points_(4) {
58 points_[0] = p0;
59 points_[1] = p1;
60 points_[2] = p2;
61 points_[3] = p3;
62 }
63
64 const std::vector<Point>& points() const { return points_; }
65 const Point& point(int ix) const;
66
67 protected:
68 std::vector<Point> points_;
69};
70
71struct Rect {
72 float x, y, width, height;
73
74 Rect() {
75 x = y = 0.0f;
76 width = height = 1.0f;
77 }
78
79 Rect(float x, float y, float width, float height) {
80 this->x = x;
81 this->y = y;
82 this->width = width;
83 this->height = height;
84 }
85
86 bool ExpandToAspectRatio(float ratio);
87 bool ExpandToMinLength(float length);
88 bool ScaleWithLengthLimit(float factor, float max_length);
89};
90
91} // namespace filterfw
92} // namespace android
93
94#endif // ANDROID_FILTERFW_CORE_GEOMETRY_H