|
| 1 | +/* |
| 2 | + * WorldEdit, a Minecraft world manipulation toolkit |
| 3 | + * Copyright (C) sk89q <http://www.sk89q.com> |
| 4 | + * Copyright (C) WorldEdit team and contributors |
| 5 | + * |
| 6 | + * This program is free software: you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation, either version 3 of the License, or |
| 9 | + * (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 General Public License |
| 17 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +package com.sk89q.worldedit.math.transform; |
| 21 | + |
| 22 | +import com.sk89q.worldedit.math.Vector3; |
| 23 | + |
| 24 | +/** |
| 25 | + * A more light-weight {@link Transform} than {@link AffineTransform}, supporting only translation and scaling. |
| 26 | + */ |
| 27 | +public record ScaleAndTranslateTransform(Vector3 offset, Vector3 scale) implements Transform { |
| 28 | + |
| 29 | + @Override |
| 30 | + public boolean isIdentity() { |
| 31 | + return offset.equals(Vector3.ZERO) && scale.equals(Vector3.ONE); |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public Vector3 apply(Vector3 input) { |
| 36 | + return input.multiply(scale).add(offset); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public Transform inverse() { |
| 41 | + return new Transform() { |
| 42 | + @Override |
| 43 | + public boolean isIdentity() { |
| 44 | + return ScaleAndTranslateTransform.this.isIdentity(); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Vector3 apply(Vector3 input) { |
| 49 | + return input.subtract(offset).divide(scale); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Transform inverse() { |
| 54 | + return ScaleAndTranslateTransform.this; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public Transform combine(Transform other) { |
| 59 | + return new CombinedTransform(this, other); |
| 60 | + } |
| 61 | + }; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public Transform combine(Transform other) { |
| 66 | + return new CombinedTransform(this, other); |
| 67 | + } |
| 68 | +} |
0 commit comments