blob: eddab878a49d47093f0f5dab5563413d627d5cd7 [file] [log] [blame]
Chris Craik261725f2016-02-29 12:52:33 -08001/*
2 * Copyright (C) 2016 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#include <gtest/gtest.h>
18
19#include "Matrix.h"
20#include "Rect.h"
21
22using namespace android::uirenderer;
23
Chris Craik034a10b2016-03-09 16:03:21 -080024TEST(Matrix, mapRect_emptyScaleSkew) {
Chris Craik261725f2016-02-29 12:52:33 -080025 // Skew, so we don't hit identity/translate/simple fast paths
Chris Craik034a10b2016-03-09 16:03:21 -080026 Matrix4 scaleMatrix;
27 scaleMatrix.loadScale(10, 10, 1);
28 scaleMatrix.skew(0.1f, 0.1f);
Chris Craik261725f2016-02-29 12:52:33 -080029
30 // non-zero empty rect, so sorting x/y would make rect non-empty
Chris Craik034a10b2016-03-09 16:03:21 -080031 Rect empty(15, 20, 15, 100);
Chris Craik261725f2016-02-29 12:52:33 -080032 ASSERT_TRUE(empty.isEmpty());
Chris Craik034a10b2016-03-09 16:03:21 -080033 scaleMatrix.mapRect(empty);
34 EXPECT_EQ(Rect(170, 215, 250, 1015), empty);
35 EXPECT_FALSE(empty.isEmpty())
36 << "Empty 'line' rect doesn't remain empty when skewed.";
37}
38
39TEST(Matrix, mapRect_emptyRotate) {
40 // Skew, so we don't hit identity/translate/simple fast paths
41 Matrix4 skewMatrix;
42 skewMatrix.loadRotate(45);
43
44 // non-zero empty rect, so sorting x/y would make rect non-empty
45 Rect lineRect(0, 100);
46 ASSERT_TRUE(lineRect.isEmpty());
47 skewMatrix.mapRect(lineRect);
48 EXPECT_FALSE(lineRect.isEmpty())
49 << "Empty 'line' rect doesn't remain empty when rotated.";
Chris Craik261725f2016-02-29 12:52:33 -080050}