1// Copyright (C) 2024 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {intersectRects, expandRect, rebaseRect, rectSize, Rect} from './geom'; 16 17describe('intersectRects', () => { 18 it('should correctly intersect two overlapping rects', () => { 19 const a: Rect = {left: 1, top: 1, right: 4, bottom: 4}; 20 const b: Rect = {left: 2, top: 2, right: 5, bottom: 5}; 21 const result = intersectRects(a, b); 22 expect(result).toEqual({left: 2, top: 2, right: 4, bottom: 4}); 23 }); 24 // Note: Non-overlapping rects are not supported and thus not tested 25}); 26 27describe('expandRect', () => { 28 it('should correctly expand a rect by a given amount', () => { 29 const rect: Rect = {left: 1, top: 1, right: 3, bottom: 3}; 30 const amount = 1; 31 const result = expandRect(rect, amount); 32 expect(result).toEqual({left: 0, top: 0, right: 4, bottom: 4}); 33 }); 34}); 35 36describe('rebaseRect', () => { 37 it('should correctly rebase a rect', () => { 38 const rect: Rect = {left: 2, top: 2, right: 5, bottom: 5}; 39 const x = 1; 40 const y = 1; 41 const result = rebaseRect(rect, x, y); 42 expect(result).toEqual({left: 1, top: 1, right: 4, bottom: 4}); 43 }); 44}); 45 46describe('rectSize', () => { 47 it('should correctly calculate the size of a rect', () => { 48 const rect: Rect = {left: 1, top: 1, right: 4, bottom: 3}; 49 const result = rectSize(rect); 50 expect(result).toEqual({width: 3, height: 2}); 51 }); 52}); 53