| 1 |
/* |
| 2 |
* Copyright 2016 by Edi Weissmann ([email protected]). |
| 3 |
* |
| 4 |
* This file is part of the Sejda source code |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU Affero General Public License as |
| 8 |
* published by the Free Software Foundation, either version 3 of the |
| 9 |
* License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Affero General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
package org.sejda.impl.sambox.util; |
| 20 |
|
| 21 |
import static org.hamcrest.CoreMatchers.is; |
| 22 |
import static org.hamcrest.MatcherAssert.assertThat; |
| 23 |
|
| 24 |
import org.junit.Test; |
| 25 |
import org.sejda.sambox.pdmodel.common.PDRectangle; |
| 26 |
|
| 27 |
public class RectangleUtilsTest { |
| 28 |
|
| 29 |
@Test |
| 30 |
public void translateRectangle() { |
| 31 |
PDRectangle in = new PDRectangle(0, 0, 396, 612); |
| 32 |
|
| 33 |
assertThat(RectangleUtils.translate(100, 50, in), is(new PDRectangle(100, 50, 396, 612))); |
| 34 |
} |
| 35 |
|
| 36 |
@Test |
| 37 |
public void rotateRectangle() { |
| 38 |
PDRectangle in = new PDRectangle(0, 0, 396, 612); |
| 39 |
PDRectangle mediaBox = new PDRectangle(0, 0, 792, 612); |
| 40 |
|
| 41 |
assertThat(RectangleUtils.rotate(-90, in, mediaBox), is(new PDRectangle(0, 0, 612, 396))); |
| 42 |
assertThat(RectangleUtils.rotate(270, in, mediaBox), is(RectangleUtils.rotate(-90, in, mediaBox))); |
| 43 |
|
| 44 |
assertThat(RectangleUtils.rotate(90, in, mediaBox), is(new PDRectangle(0, 396, 612, 396))); |
| 45 |
|
| 46 |
assertThat(RectangleUtils.rotate(180, in, mediaBox), is(new PDRectangle(396, 0, 396, 612))); |
| 47 |
} |
| 48 |
} |