OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 RTC_DCHECK_GT(array_geometry.size(), 1u); | 61 RTC_DCHECK_GT(array_geometry.size(), 1u); |
62 const Point first_pair_direction = | 62 const Point first_pair_direction = |
63 PairDirection(array_geometry[0], array_geometry[1]); | 63 PairDirection(array_geometry[0], array_geometry[1]); |
64 for (size_t i = 2u; i < array_geometry.size(); ++i) { | 64 for (size_t i = 2u; i < array_geometry.size(); ++i) { |
65 const Point pair_direction = | 65 const Point pair_direction = |
66 PairDirection(array_geometry[i - 1], array_geometry[i]); | 66 PairDirection(array_geometry[i - 1], array_geometry[i]); |
67 if (!AreParallel(first_pair_direction, pair_direction)) { | 67 if (!AreParallel(first_pair_direction, pair_direction)) { |
68 return rtc::Maybe<Point>(); | 68 return rtc::Maybe<Point>(); |
69 } | 69 } |
70 } | 70 } |
71 return first_pair_direction; | 71 return rtc::Maybe<Point>(first_pair_direction); |
72 } | 72 } |
73 | 73 |
74 rtc::Maybe<Point> GetNormalIfPlanar(const std::vector<Point>& array_geometry) { | 74 rtc::Maybe<Point> GetNormalIfPlanar(const std::vector<Point>& array_geometry) { |
75 RTC_DCHECK_GT(array_geometry.size(), 1u); | 75 RTC_DCHECK_GT(array_geometry.size(), 1u); |
76 const Point first_pair_direction = | 76 const Point first_pair_direction = |
77 PairDirection(array_geometry[0], array_geometry[1]); | 77 PairDirection(array_geometry[0], array_geometry[1]); |
78 Point pair_direction(0.f, 0.f, 0.f); | 78 Point pair_direction(0.f, 0.f, 0.f); |
79 size_t i = 2u; | 79 size_t i = 2u; |
80 bool is_linear = true; | 80 bool is_linear = true; |
81 for (; i < array_geometry.size() && is_linear; ++i) { | 81 for (; i < array_geometry.size() && is_linear; ++i) { |
82 pair_direction = PairDirection(array_geometry[i - 1], array_geometry[i]); | 82 pair_direction = PairDirection(array_geometry[i - 1], array_geometry[i]); |
83 if (!AreParallel(first_pair_direction, pair_direction)) { | 83 if (!AreParallel(first_pair_direction, pair_direction)) { |
84 is_linear = false; | 84 is_linear = false; |
85 } | 85 } |
86 } | 86 } |
87 if (is_linear) { | 87 if (is_linear) { |
88 return rtc::Maybe<Point>(); | 88 return rtc::Maybe<Point>(); |
89 } | 89 } |
90 const Point normal_direction = | 90 const Point normal_direction = |
91 CrossProduct(first_pair_direction, pair_direction); | 91 CrossProduct(first_pair_direction, pair_direction); |
92 for (; i < array_geometry.size(); ++i) { | 92 for (; i < array_geometry.size(); ++i) { |
93 pair_direction = PairDirection(array_geometry[i - 1], array_geometry[i]); | 93 pair_direction = PairDirection(array_geometry[i - 1], array_geometry[i]); |
94 if (!ArePerpendicular(normal_direction, pair_direction)) { | 94 if (!ArePerpendicular(normal_direction, pair_direction)) { |
95 return rtc::Maybe<Point>(); | 95 return rtc::Maybe<Point>(); |
96 } | 96 } |
97 } | 97 } |
98 return normal_direction; | 98 return rtc::Maybe<Point>(normal_direction); |
99 } | 99 } |
100 | 100 |
101 rtc::Maybe<Point> GetArrayNormalIfExists( | 101 rtc::Maybe<Point> GetArrayNormalIfExists( |
102 const std::vector<Point>& array_geometry) { | 102 const std::vector<Point>& array_geometry) { |
103 const rtc::Maybe<Point> direction = GetDirectionIfLinear(array_geometry); | 103 const rtc::Maybe<Point> direction = GetDirectionIfLinear(array_geometry); |
104 if (direction) { | 104 if (direction) { |
105 return Point(direction->y(), -direction->x(), 0.f); | 105 return rtc::Maybe<Point>(Point(direction->y(), -direction->x(), 0.f)); |
106 } | 106 } |
107 const rtc::Maybe<Point> normal = GetNormalIfPlanar(array_geometry); | 107 const rtc::Maybe<Point> normal = GetNormalIfPlanar(array_geometry); |
108 if (normal && normal->z() < kMaxDotProduct) { | 108 if (normal && normal->z() < kMaxDotProduct) { |
109 return normal; | 109 return normal; |
110 } | 110 } |
111 return rtc::Maybe<Point>(); | 111 return rtc::Maybe<Point>(); |
112 } | 112 } |
113 | 113 |
114 Point AzimuthToPoint(float azimuth) { | 114 Point AzimuthToPoint(float azimuth) { |
115 return Point(std::cos(azimuth), std::sin(azimuth), 0.f); | 115 return Point(std::cos(azimuth), std::sin(azimuth), 0.f); |
116 } | 116 } |
117 | 117 |
118 } // namespace webrtc | 118 } // namespace webrtc |
OLD | NEW |