blob: 16a396e00790e2e93c46d94eb2c40fb0640b8f47 [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);
John Reck1bcacfd2017-11-03 10:12:19 -070035 EXPECT_FALSE(empty.isEmpty()) << "Empty 'line' rect doesn't remain empty when skewed.";
Chris Craik034a10b2016-03-09 16:03:21 -080036}
37
38TEST(Matrix, mapRect_emptyRotate) {
39 // Skew, so we don't hit identity/translate/simple fast paths
40 Matrix4 skewMatrix;
41 skewMatrix.loadRotate(45);
42
43 // non-zero empty rect, so sorting x/y would make rect non-empty
44 Rect lineRect(0, 100);
45 ASSERT_TRUE(lineRect.isEmpty());
46 skewMatrix.mapRect(lineRect);
John Reck1bcacfd2017-11-03 10:12:19 -070047 EXPECT_FALSE(lineRect.isEmpty()) << "Empty 'line' rect doesn't remain empty when rotated.";
Chris Craik261725f2016-02-29 12:52:33 -080048}