geforkt von Mirrors/FastAsyncWorldEdit
Updated Math package with upstream and formatted code
Dieser Commit ist enthalten in:
Ursprung
69e547688b
Commit
4041b2aa1d
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
@ -37,8 +37,10 @@ public class BlockVector2 {
|
||||
* A comparator for BlockVector2ds that orders the vectors by rows, with x as the
|
||||
* column and z as the row.
|
||||
*
|
||||
* <p>
|
||||
* For example, if x is the horizontal axis and z is the vertical axis, it
|
||||
* sorts like so:
|
||||
* </p>
|
||||
*
|
||||
* <pre>
|
||||
* 0123
|
||||
@ -67,14 +69,18 @@ public class BlockVector2 {
|
||||
return ONE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
return new BlockVector2(x, z);
|
||||
}
|
||||
|
||||
protected int x, z;
|
||||
protected int x;
|
||||
protected int z;
|
||||
|
||||
protected BlockVector2(){}
|
||||
protected BlockVector2(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct an instance.
|
||||
@ -221,7 +227,8 @@ public class BlockVector2 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public BlockVector2 add(BlockVector2... others) {
|
||||
int newX = x, newZ = z;
|
||||
int newX = x;
|
||||
int newZ = z;
|
||||
|
||||
for (BlockVector2 other : others) {
|
||||
newX += other.x;
|
||||
@ -262,7 +269,8 @@ public class BlockVector2 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public BlockVector2 subtract(BlockVector2... others) {
|
||||
int newX = x, newZ = z;
|
||||
int newX = x;
|
||||
int newZ = z;
|
||||
|
||||
for (BlockVector2 other : others) {
|
||||
newX -= other.x;
|
||||
@ -300,7 +308,8 @@ public class BlockVector2 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public BlockVector2 multiply(BlockVector2... others) {
|
||||
int newX = x, newZ = z;
|
||||
int newX = x;
|
||||
int newZ = z;
|
||||
|
||||
for (BlockVector2 other : others) {
|
||||
newX *= other.x;
|
||||
@ -371,6 +380,7 @@ public class BlockVector2 {
|
||||
public BlockVector2 shr(int n) {
|
||||
return shr(n, n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the length of the vector.
|
||||
*
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
@ -67,6 +67,8 @@ public abstract class BlockVector3 {
|
||||
return ONE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
return new BlockVector3Imp(x, y, z);
|
||||
@ -80,9 +82,9 @@ public abstract class BlockVector3 {
|
||||
}
|
||||
|
||||
public static boolean isLongPackable(BlockVector3 location) {
|
||||
return isHorizontallyInBounds(location.getX()) &&
|
||||
isHorizontallyInBounds(location.getZ()) &&
|
||||
0 <= location.getY() && location.getY() <= WORLD_Y_MAX;
|
||||
return isHorizontallyInBounds(location.getX())
|
||||
&& isHorizontallyInBounds(location.getZ())
|
||||
&& 0 <= location.getY() && location.getY() <= WORLD_Y_MAX;
|
||||
}
|
||||
|
||||
public static void checkLongPackable(BlockVector3 location) {
|
||||
@ -110,6 +112,7 @@ public abstract class BlockVector3 {
|
||||
*
|
||||
* <p>
|
||||
* Useful for sorting by chunk block storage order.
|
||||
* </p>
|
||||
*/
|
||||
public static Comparator<BlockVector3> sortByCoordsYzx() {
|
||||
return YzxOrderComparator.YZX_ORDER;
|
||||
@ -125,7 +128,7 @@ public abstract class BlockVector3 {
|
||||
|
||||
public long toLongPackedForm() {
|
||||
checkLongPackable(this);
|
||||
return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & (long) BITS_12) << (26 + 26)));
|
||||
return (getX() & BITS_26) | ((getZ() & BITS_26) << 26) | (((getY() & BITS_12) << (26 + 26)));
|
||||
}
|
||||
|
||||
public MutableBlockVector3 mutX(double x) {
|
||||
@ -264,7 +267,9 @@ public abstract class BlockVector3 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public BlockVector3 add(BlockVector3... others) {
|
||||
int newX = getX(), newY = getY(), newZ = getZ();
|
||||
int newX = getX();
|
||||
int newY = getY();
|
||||
int newZ = getZ();
|
||||
|
||||
for (BlockVector3 other : others) {
|
||||
newX += other.getX();
|
||||
@ -307,7 +312,9 @@ public abstract class BlockVector3 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public BlockVector3 subtract(BlockVector3... others) {
|
||||
int newX = getX(), newY = getY(), newZ = getZ();
|
||||
int newX = getX();
|
||||
int newY = getY();
|
||||
int newZ = getZ();
|
||||
|
||||
for (BlockVector3 other : others) {
|
||||
newX -= other.getX();
|
||||
@ -347,7 +354,9 @@ public abstract class BlockVector3 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public BlockVector3 multiply(BlockVector3... others) {
|
||||
int newX = getX(), newY = getY(), newZ = getZ();
|
||||
int newX = getX();
|
||||
int newY = getY();
|
||||
int newZ = getZ();
|
||||
|
||||
for (BlockVector3 other : others) {
|
||||
newX *= other.getX();
|
||||
@ -766,8 +775,7 @@ public abstract class BlockVector3 {
|
||||
}
|
||||
|
||||
public final boolean equals(BlockVector3 other) {
|
||||
return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this
|
||||
.getZ();
|
||||
return other.getX() == this.getX() && other.getY() == this.getY() && other.getZ() == this.getZ();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -38,7 +38,9 @@ public final class BlockVector3Imp extends BlockVector3 {
|
||||
return new BlockVector3Imp(x, y, z);
|
||||
}
|
||||
|
||||
private final int x, y, z;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final int z;
|
||||
|
||||
/**
|
||||
* Construct an instance.
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
@ -71,6 +71,8 @@ public final class MathUtils {
|
||||
return -1.0;
|
||||
case 270:
|
||||
return 0.0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Math.cos(Math.toRadians(degrees));
|
||||
@ -100,6 +102,8 @@ public final class MathUtils {
|
||||
return 0.0;
|
||||
case 270:
|
||||
return -1.0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Math.sin(Math.toRadians(degrees));
|
||||
@ -109,7 +113,9 @@ public final class MathUtils {
|
||||
* Returns the rounded double of the given value, rounding to the
|
||||
* nearest integer value away from zero on ties.
|
||||
*
|
||||
* <p>
|
||||
* This behavior is the same as {@link java.math.RoundingMode#HALF_UP}.
|
||||
* </p>
|
||||
*
|
||||
* @param value the value
|
||||
* @return the rounded value
|
||||
|
@ -8,7 +8,8 @@ public class MutableBlockVector2 extends BlockVector2 {
|
||||
return MUTABLE_CACHE.get().setComponents(x, z);
|
||||
}
|
||||
|
||||
public MutableBlockVector2() {}
|
||||
public MutableBlockVector2() {
|
||||
}
|
||||
|
||||
public MutableBlockVector2(int x, int z) {
|
||||
super(x, z);
|
||||
|
@ -16,7 +16,8 @@ public class MutableBlockVector3 extends BlockVector3 {
|
||||
return FaweCache.IMP.MUTABLE_BLOCKVECTOR3.get().setComponents(x, y, z);
|
||||
}
|
||||
|
||||
public MutableBlockVector3() {}
|
||||
public MutableBlockVector3() {
|
||||
}
|
||||
|
||||
public MutableBlockVector3(BlockVector3 other) {
|
||||
this(other.getX(), other.getY(), other.getZ());
|
||||
@ -26,7 +27,9 @@ public class MutableBlockVector3 extends BlockVector3 {
|
||||
return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ());
|
||||
}
|
||||
|
||||
private int x,y,z;
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public MutableBlockVector3(int x, int y, int z) {
|
||||
this.x = x;
|
||||
|
@ -4,7 +4,9 @@ import com.boydti.fawe.FaweCache;
|
||||
|
||||
public class MutableVector3 extends Vector3 {
|
||||
|
||||
private double x, y, z;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
public MutableVector3() {
|
||||
}
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
@ -44,11 +44,14 @@ public final class Vector2 {
|
||||
return ONE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return new Vector2(x, z);
|
||||
}
|
||||
|
||||
private final double x, z;
|
||||
private final double x;
|
||||
private final double z;
|
||||
|
||||
/**
|
||||
* Construct an instance.
|
||||
@ -128,7 +131,8 @@ public final class Vector2 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public Vector2 add(Vector2... others) {
|
||||
double newX = x, newZ = z;
|
||||
double newX = x;
|
||||
double newZ = z;
|
||||
|
||||
for (Vector2 other : others) {
|
||||
newX += other.x;
|
||||
@ -169,7 +173,8 @@ public final class Vector2 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public Vector2 subtract(Vector2... others) {
|
||||
double newX = x, newZ = z;
|
||||
double newX = x;
|
||||
double newZ = z;
|
||||
|
||||
for (Vector2 other : others) {
|
||||
newX -= other.x;
|
||||
@ -207,7 +212,8 @@ public final class Vector2 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public Vector2 multiply(Vector2... others) {
|
||||
double newX = x, newZ = z;
|
||||
double newX = x;
|
||||
double newZ = z;
|
||||
|
||||
for (Vector2 other : others) {
|
||||
newX *= other.x;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math;
|
||||
@ -54,6 +54,8 @@ public abstract class Vector3 {
|
||||
return ONE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*/
|
||||
return new Vector3Impl(x, y, z);
|
||||
@ -75,6 +77,7 @@ public abstract class Vector3 {
|
||||
*
|
||||
* <p>
|
||||
* Useful for sorting by chunk block storage order.
|
||||
* </p>
|
||||
*/
|
||||
public static Comparator<Vector3> sortByCoordsYzx() {
|
||||
return YzxOrderComparator.YZX_ORDER;
|
||||
@ -209,7 +212,9 @@ public abstract class Vector3 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public Vector3 add(Vector3... others) {
|
||||
double newX = getX(), newY = getY(), newZ = getZ();
|
||||
double newX = getX();
|
||||
double newY = getY();
|
||||
double newZ = getZ();
|
||||
|
||||
for (Vector3 other : others) {
|
||||
newX += other.getX();
|
||||
@ -252,7 +257,9 @@ public abstract class Vector3 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public Vector3 subtract(Vector3... others) {
|
||||
double newX = getX(), newY = getY(), newZ = getZ();
|
||||
double newX = getX();
|
||||
double newY = getY();
|
||||
double newZ = getZ();
|
||||
|
||||
for (Vector3 other : others) {
|
||||
newX -= other.getX();
|
||||
@ -292,7 +299,9 @@ public abstract class Vector3 {
|
||||
* @return a new vector
|
||||
*/
|
||||
public Vector3 multiply(Vector3... others) {
|
||||
double newX = getX(), newY = getY(), newZ = getZ();
|
||||
double newX = getX();
|
||||
double newY = getY();
|
||||
double newZ = getZ();
|
||||
|
||||
for (Vector3 other : others) {
|
||||
newX *= other.getX();
|
||||
|
@ -1,7 +1,9 @@
|
||||
package com.sk89q.worldedit.math;
|
||||
|
||||
public class Vector3Impl extends Vector3 {
|
||||
private final double x,y,z;
|
||||
private final double x;
|
||||
private final double y;
|
||||
private final double z;
|
||||
|
||||
public Vector3Impl(double x, double y, double z) {
|
||||
this.x = x;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
@ -25,7 +25,7 @@ package com.sk89q.worldedit.math.convolution;
|
||||
public class GaussianKernel extends Kernel {
|
||||
|
||||
/**
|
||||
* Constructor of the kernel
|
||||
* Constructor of the kernel.
|
||||
*
|
||||
* @param radius the resulting diameter will be radius * 2 + 1
|
||||
* @param sigma controls 'flatness'
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
@ -46,14 +46,14 @@ public class HeightMap {
|
||||
private final boolean layers;
|
||||
private int[] data;
|
||||
private boolean[] invalid;
|
||||
private int width;
|
||||
private int height;
|
||||
private final int width;
|
||||
private final int height;
|
||||
|
||||
private Region region;
|
||||
private EditSession session;
|
||||
private final Region region;
|
||||
private final EditSession session;
|
||||
|
||||
/**
|
||||
* Constructs the HeightMap
|
||||
* Constructs the HeightMap.
|
||||
*
|
||||
* @param session an edit session
|
||||
* @param region the region
|
||||
@ -106,10 +106,11 @@ public class HeightMap {
|
||||
int yTmp = 255;
|
||||
for (int z = 0; z < height; ++z) {
|
||||
for (int x = 0; x < width; ++x, index++) {
|
||||
if (mask != null)
|
||||
if (mask != null) {
|
||||
yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE, mask);
|
||||
else
|
||||
} else {
|
||||
yTmp = session.getNearestSurfaceTerrainBlock(x + minX, z + minZ, yTmp, minY, maxY, Integer.MIN_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
switch (yTmp) {
|
||||
case Integer.MIN_VALUE:
|
||||
yTmp = minY;
|
||||
@ -145,8 +146,8 @@ public class HeightMap {
|
||||
* @param filter the filter
|
||||
* @param iterations the number of iterations
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException if the maximum block change limit is exceeded
|
||||
*/
|
||||
|
||||
public int applyFilter(HeightMapFilter filter, int iterations) throws MaxChangedBlocksException {
|
||||
checkNotNull(filter);
|
||||
|
||||
@ -182,7 +183,9 @@ public class HeightMap {
|
||||
for (int z = 0; z < height; ++z) {
|
||||
int zr = z + originZ;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
if (this.invalid != null && this.invalid[index]) continue;
|
||||
if (this.invalid != null && this.invalid[index]) {
|
||||
continue;
|
||||
}
|
||||
int curHeight = this.data[index];
|
||||
|
||||
//Clamp newHeight within the selection area
|
||||
@ -204,7 +207,9 @@ public class HeightMap {
|
||||
// Grow -- start from 1 below top replacing airblocks
|
||||
for (int setY = newBlock - 1, getY = curBlock; setY >= curBlock; --setY, getY--) {
|
||||
BlockStateHolder<BlockState> get = session.getBlock(xr, getY, zr);
|
||||
if (get != BlockTypes.AIR.getDefaultState()) tmpBlock = get;
|
||||
if (get != BlockTypes.AIR.getDefaultState()) {
|
||||
tmpBlock = get;
|
||||
}
|
||||
session.setBlock(xr, setY, zr, tmpBlock);
|
||||
++blocksChanged;
|
||||
}
|
||||
@ -244,17 +249,18 @@ public class HeightMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a raw heightmap to the region
|
||||
* Apply a raw heightmap to the region.
|
||||
*
|
||||
* @param data the data
|
||||
* @return number of blocks affected
|
||||
* @throws MaxChangedBlocksException if the maximum block change limit is exceeded
|
||||
*/
|
||||
|
||||
public int apply(int[] data) throws MaxChangedBlocksException {
|
||||
checkNotNull(data);
|
||||
|
||||
BlockVector3 minY = region.getMinimumPoint();
|
||||
int originX = minY.getBlockX();
|
||||
int originY = minY.getBlockY();
|
||||
int originZ = minY.getBlockZ();
|
||||
|
||||
int maxY = region.getMaximumPoint().getBlockY();
|
||||
@ -268,7 +274,9 @@ public class HeightMap {
|
||||
for (int z = 0; z < height; ++z) {
|
||||
int zr = z + originZ;
|
||||
for (int x = 0; x < width; ++x, index++) {
|
||||
if (this.invalid != null && this.invalid[index]) continue;
|
||||
if (this.invalid != null && this.invalid[index]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int curHeight = this.data[index];
|
||||
|
||||
@ -293,7 +301,9 @@ public class HeightMap {
|
||||
} else {
|
||||
get = BlockTypes.AIR.getDefaultState();
|
||||
}
|
||||
if (get != BlockTypes.AIR.getDefaultState()) tmpBlock = get;
|
||||
if (get != BlockTypes.AIR.getDefaultState()) {
|
||||
tmpBlock = get;
|
||||
}
|
||||
session.setBlock(xr, setY, zr, tmpBlock);
|
||||
++blocksChanged;
|
||||
}
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
@ -53,14 +53,14 @@ public class HeightMapFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the kernel
|
||||
* Get the kernel.
|
||||
*/
|
||||
public Kernel getKernel() {
|
||||
return kernel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Kernel
|
||||
* Set the kernel.
|
||||
*
|
||||
* @param kernel the kernel
|
||||
*/
|
||||
@ -71,7 +71,7 @@ public class HeightMapFilter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter with a 2D kernel
|
||||
* Filter with a 2D kernel.
|
||||
*
|
||||
* @param inData the data
|
||||
* @param width the width
|
||||
@ -107,7 +107,9 @@ public class HeightMapFilter {
|
||||
int matrixOffset = ky * kw;
|
||||
for (int kx = 0; kx < kw; ++kx) {
|
||||
float f = matrix[matrixOffset + kx];
|
||||
if (f == 0) continue;
|
||||
if (f == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int offsetX = x + kx - kox;
|
||||
// Clamp coordinates inside data
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
@ -27,11 +27,11 @@ package com.sk89q.worldedit.math.convolution;
|
||||
*/
|
||||
public class Kernel {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
private int xOrigin;
|
||||
private int yOrigin;
|
||||
private float[] data;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int xOrigin;
|
||||
private final int yOrigin;
|
||||
private final float[] data;
|
||||
|
||||
public Kernel(int width, int height, float[] data) {
|
||||
this.width = width;
|
||||
|
@ -3,24 +3,26 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.convolution;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A linear Kernel generator (all cells weight the same)
|
||||
* A linear Kernel generator (all cells weigh the same).
|
||||
*/
|
||||
public class LinearKernel extends Kernel {
|
||||
|
||||
@ -32,7 +34,7 @@ public class LinearKernel extends Kernel {
|
||||
int diameter = radius * 2 + 1;
|
||||
float[] data = new float[diameter * diameter];
|
||||
|
||||
for (int i = 0; i < data.length; data[i++] = 1.0f / data.length);
|
||||
Arrays.fill(data, 1.0f / data.length);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.geom;
|
||||
@ -31,7 +31,6 @@ import java.util.List;
|
||||
public final class Polygons {
|
||||
|
||||
private Polygons() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -43,7 +42,7 @@ public final class Polygons {
|
||||
* @return a list of {@link BlockVector2} which resemble the shape as a polygon
|
||||
*/
|
||||
public static List<BlockVector2> polygonizeCylinder(BlockVector2 center, Vector2 radius, int maxPoints) {
|
||||
int nPoints = (int) Math.ceil(Math.PI*radius.length());
|
||||
int nPoints = (int) Math.ceil(Math.PI * radius.length());
|
||||
|
||||
// These strange semantics for maxPoints are copied from the selectSecondary method.
|
||||
if (maxPoints >= 0 && nPoints >= maxPoints) {
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// $Id$
|
||||
@ -26,7 +26,7 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents an arbitrary function in ℝ → ℝ<sup>3</sup>
|
||||
* Represents an arbitrary function in ℝ → ℝ<sup>3</sup>.
|
||||
*/
|
||||
public interface Interpolation {
|
||||
|
||||
@ -39,7 +39,7 @@ public interface Interpolation {
|
||||
void setNodes(List<Node> nodes);
|
||||
|
||||
/**
|
||||
* Gets the result of f(position)
|
||||
* Gets the result of f(position).
|
||||
*
|
||||
* @param position the position to interpolate
|
||||
* @return the result
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// $Id$
|
||||
@ -43,10 +43,10 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
private Vector3[] coeffC;
|
||||
private Vector3[] coeffD;
|
||||
private double scaling;
|
||||
private MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
private final MutableBlockVector3 mutable = new MutableBlockVector3();
|
||||
|
||||
public KochanekBartelsInterpolation() {
|
||||
setNodes(Collections.<Node>emptyList());
|
||||
setNodes(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -64,8 +64,9 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
coeffC = new Vector3[nNodes];
|
||||
coeffD = new Vector3[nNodes];
|
||||
|
||||
if (nNodes == 0)
|
||||
if (nNodes == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
Node nodeB = nodes.get(0);
|
||||
double tensionB = nodeB.getTension();
|
||||
@ -84,14 +85,14 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
}
|
||||
|
||||
// Kochanek-Bartels tangent coefficients
|
||||
final double ta = (1-tensionA)*(1+biasA)*(1+continuityA)/2; // Factor for lhs of d[i]
|
||||
final double tb = (1-tensionA)*(1-biasA)*(1-continuityA)/2; // Factor for rhs of d[i]
|
||||
final double tc = (1-tensionB)*(1+biasB)*(1-continuityB)/2; // Factor for lhs of d[i+1]
|
||||
final double td = (1-tensionB)*(1-biasB)*(1+continuityB)/2; // Factor for rhs of d[i+1]
|
||||
final double ta = (1 - tensionA) * (1 + biasA) * (1 + continuityA) / 2; // Factor for lhs of d[i]
|
||||
final double tb = (1 - tensionA) * (1 - biasA) * (1 - continuityA) / 2; // Factor for rhs of d[i]
|
||||
final double tc = (1 - tensionB) * (1 + biasB) * (1 - continuityB) / 2; // Factor for lhs of d[i+1]
|
||||
final double td = (1 - tensionB) * (1 - biasB) * (1 + continuityB) / 2; // Factor for rhs of d[i+1]
|
||||
|
||||
coeffA[i] = linearCombination(i, -ta, ta- tb-tc+2, tb+tc-td-2, td);
|
||||
coeffB[i] = linearCombination(i, 2*ta, -2*ta+2*tb+tc-3, -2*tb-tc+td+3, -td);
|
||||
coeffC[i] = linearCombination(i, -ta, ta- tb , tb , 0);
|
||||
coeffA[i] = linearCombination(i, -ta, ta - tb - tc + 2, tb + tc - td - 2, td);
|
||||
coeffB[i] = linearCombination(i, 2 * ta, -2 * ta + 2 * tb + tc - 3, -2 * tb - tc + td + 3, -td);
|
||||
coeffC[i] = linearCombination(i, -ta, ta - tb, tb, 0);
|
||||
//coeffD[i] = linearCombination(i, 0, 1, 0, 0);
|
||||
coeffD[i] = retrieve(i); // this is an optimization
|
||||
}
|
||||
@ -125,11 +126,13 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
* @return nodes[clamp(0, nodes.length-1)]
|
||||
*/
|
||||
private Vector3 retrieve(int index) {
|
||||
if (index < 0)
|
||||
if (index < 0) {
|
||||
return fastRetrieve(0);
|
||||
}
|
||||
|
||||
if (index >= nodes.size())
|
||||
return fastRetrieve(nodes.size()-1);
|
||||
if (index >= nodes.size()) {
|
||||
return fastRetrieve(nodes.size() - 1);
|
||||
}
|
||||
|
||||
return fastRetrieve(index);
|
||||
}
|
||||
@ -140,11 +143,13 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public Vector3 getPosition(double position) {
|
||||
if (coeffA == null)
|
||||
if (coeffA == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
position *= scaling;
|
||||
|
||||
@ -166,11 +171,13 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public Vector3 get1stDerivative(double position) {
|
||||
if (coeffA == null)
|
||||
if (coeffA == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
position *= scaling;
|
||||
|
||||
@ -181,16 +188,18 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final Vector3 b = coeffB[index];
|
||||
final Vector3 c = coeffC[index];
|
||||
|
||||
return a.multiply(1.5*position - 3.0*index).add(b).multiply(2.0*position).add(a.multiply(1.5*index).subtract(b).multiply(2.0*index)).add(c).multiply(scaling);
|
||||
return a.multiply(1.5 * position - 3.0 * index).add(b).multiply(2.0 * position).add(a.multiply(1.5 * index).subtract(b).multiply(2.0 * index)).add(c).multiply(scaling);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double arcLength(double positionA, double positionB) {
|
||||
if (coeffA == null)
|
||||
if (coeffA == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (positionA > positionB)
|
||||
if (positionA > positionB) {
|
||||
return arcLength(positionB, positionA);
|
||||
}
|
||||
|
||||
positionA *= scaling;
|
||||
positionB *= scaling;
|
||||
@ -205,7 +214,7 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes a < b
|
||||
* Assumes a < b.
|
||||
*/
|
||||
private double arcLengthRecursive(int indexLeft, double remainderLeft, int indexRight, double remainderRight) {
|
||||
switch (indexRight - indexLeft) {
|
||||
@ -214,14 +223,12 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
|
||||
case 1:
|
||||
// This case is merely a speed-up for a very common case
|
||||
return
|
||||
arcLengthRecursive(indexLeft, remainderLeft, 1.0) +
|
||||
arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
return arcLengthRecursive(indexLeft, remainderLeft, 1.0)
|
||||
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
|
||||
default:
|
||||
return
|
||||
arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0) +
|
||||
arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
return arcLengthRecursive(indexLeft, remainderLeft, indexRight - 1, 1.0)
|
||||
+ arcLengthRecursive(indexRight, 0.0, remainderRight);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,9 +240,9 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
final int nPoints = 8;
|
||||
|
||||
double accum = a.multiply(remainderLeft).add(b).multiply(remainderLeft).add(c).length() / 2.0;
|
||||
for (int i = 1; i < nPoints-1; ++i) {
|
||||
for (int i = 1; i < nPoints - 1; ++i) {
|
||||
double t = ((double) i) / nPoints;
|
||||
t = (remainderRight-remainderLeft)*t + remainderLeft;
|
||||
t = (remainderRight - remainderLeft) * t + remainderLeft;
|
||||
accum += a.multiply(t).add(b).multiply(t).add(c).length();
|
||||
}
|
||||
|
||||
@ -245,11 +252,13 @@ public class KochanekBartelsInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public int getSegment(double position) {
|
||||
if (coeffA == null)
|
||||
if (coeffA == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
position *= scaling;
|
||||
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// $Id$
|
||||
@ -43,11 +43,13 @@ public class LinearInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public Vector3 getPosition(double position) {
|
||||
if (nodes == null)
|
||||
if (nodes == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
position *= nodes.size() - 1;
|
||||
|
||||
@ -77,11 +79,13 @@ public class LinearInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public Vector3 get1stDerivative(double position) {
|
||||
if (nodes == null)
|
||||
if (nodes == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
position *= nodes.size() - 1;
|
||||
|
||||
@ -95,11 +99,13 @@ public class LinearInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public double arcLength(double positionA, double positionB) {
|
||||
if (nodes == null)
|
||||
if (nodes == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (positionA > positionB)
|
||||
if (positionA > positionB) {
|
||||
return arcLength(positionB, positionA);
|
||||
}
|
||||
|
||||
positionA *= nodes.size() - 1;
|
||||
positionB *= nodes.size() - 1;
|
||||
@ -123,14 +129,12 @@ public class LinearInterpolation implements Interpolation {
|
||||
|
||||
case 1:
|
||||
// This case is merely a speed-up for a very common case
|
||||
return
|
||||
arcLengthRecursive(indexA, remainderA, 1.0) +
|
||||
arcLengthRecursive(indexB, 0.0, remainderB);
|
||||
return arcLengthRecursive(indexA, remainderA, 1.0)
|
||||
+ arcLengthRecursive(indexB, 0.0, remainderB);
|
||||
|
||||
default:
|
||||
return
|
||||
arcLengthRecursive(indexA, remainderA, indexB - 1, 1.0) +
|
||||
arcLengthRecursive(indexB, 0.0, remainderB);
|
||||
return arcLengthRecursive(indexA, remainderA, indexB - 1, 1.0)
|
||||
+ arcLengthRecursive(indexB, 0.0, remainderB);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,11 +147,13 @@ public class LinearInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public int getSegment(double position) {
|
||||
if (nodes == null)
|
||||
if (nodes == null) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
position *= nodes.size() - 1;
|
||||
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// $Id$
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
// $Id$
|
||||
@ -67,16 +67,18 @@ public class ReparametrisingInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public Vector3 getPosition(double position) {
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return baseInterpolation.getPosition(arcToParameter(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector3 get1stDerivative(double position) {
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return baseInterpolation.get1stDerivative(arcToParameter(position)).normalize().multiply(totalArcLength);
|
||||
}
|
||||
@ -87,10 +89,13 @@ public class ReparametrisingInterpolation implements Interpolation {
|
||||
}
|
||||
|
||||
private double arcToParameter(double arc) {
|
||||
if (cache.isEmpty())
|
||||
if (cache.isEmpty()) {
|
||||
throw new IllegalStateException("Must call setNodes first.");
|
||||
}
|
||||
|
||||
if (arc > 1) arc = 1;
|
||||
if (arc > 1) {
|
||||
arc = 1;
|
||||
}
|
||||
arc *= totalArcLength;
|
||||
|
||||
Entry<Double, Double> floorEntry = cache.floorEntry(arc);
|
||||
@ -140,8 +145,7 @@ public class ReparametrisingInterpolation implements Interpolation {
|
||||
// search between left and mid
|
||||
rightArc = midArc;
|
||||
rightParameter = midParameter;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// search between mid and right
|
||||
leftArc = midArc;
|
||||
leftParameter = midParameter;
|
||||
@ -152,8 +156,9 @@ public class ReparametrisingInterpolation implements Interpolation {
|
||||
|
||||
@Override
|
||||
public int getSegment(double position) {
|
||||
if (position > 1)
|
||||
if (position > 1) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
return baseInterpolation.getSegment(arcToParameter(position));
|
||||
}
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.noise;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.noise;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.noise;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.noise;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.noise;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.noise;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
@ -34,15 +34,13 @@ import java.io.Serializable;
|
||||
*/
|
||||
public class AffineTransform implements Transform, Serializable {
|
||||
|
||||
private AffineTransform inverse;
|
||||
|
||||
/**
|
||||
* coefficients for x coordinate.
|
||||
*/
|
||||
private final double m00;
|
||||
private final double m01;
|
||||
private final double m02;
|
||||
private double m03;
|
||||
private final double m03;
|
||||
|
||||
/**
|
||||
* coefficients for y coordinate.
|
||||
@ -50,7 +48,7 @@ public class AffineTransform implements Transform, Serializable {
|
||||
private final double m10;
|
||||
private final double m11;
|
||||
private final double m12;
|
||||
private double m13;
|
||||
private final double m13;
|
||||
|
||||
/**
|
||||
* coefficients for z coordinate.
|
||||
@ -58,13 +56,13 @@ public class AffineTransform implements Transform, Serializable {
|
||||
private final double m20;
|
||||
private final double m21;
|
||||
private final double m22;
|
||||
private double m23;
|
||||
private final double m23;
|
||||
|
||||
// ===================================================================
|
||||
// constructors
|
||||
|
||||
/**
|
||||
* Creates a new affine transform3D set to identity.
|
||||
* Creates a new affine transform3D set to the identity.
|
||||
*/
|
||||
public AffineTransform() {
|
||||
// init to identity matrix
|
||||
@ -85,6 +83,7 @@ public class AffineTransform implements Transform, Serializable {
|
||||
m20 = coefs[6];
|
||||
m21 = coefs[7];
|
||||
m22 = coefs[8];
|
||||
m03 = m13 = m23 = 0;
|
||||
} else if (coefs.length == 12) {
|
||||
m00 = coefs[0];
|
||||
m01 = coefs[1];
|
||||
@ -99,11 +98,14 @@ public class AffineTransform implements Transform, Serializable {
|
||||
m22 = coefs[10];
|
||||
m23 = coefs[11];
|
||||
} else {
|
||||
throw new IllegalArgumentException("Input array must have 9 or 12 elements");
|
||||
throw new IllegalArgumentException(
|
||||
"Input array must have 9 or 12 elements");
|
||||
}
|
||||
}
|
||||
|
||||
public AffineTransform(double xx, double yx, double zx, double tx, double xy, double yy, double zy, double ty, double xz, double yz, double zz, double tz) {
|
||||
public AffineTransform(double xx, double yx, double zx, double tx,
|
||||
double xy, double yy, double zy, double ty, double xz, double yz,
|
||||
double zz, double tz) {
|
||||
m00 = xx;
|
||||
m01 = yx;
|
||||
m02 = zx;
|
||||
@ -123,40 +125,10 @@ public class AffineTransform implements Transform, Serializable {
|
||||
|
||||
@Override
|
||||
public boolean isIdentity() {
|
||||
if (m00 != 1) {
|
||||
return false;
|
||||
}
|
||||
if (m11 != 1) {
|
||||
return false;
|
||||
}
|
||||
if (m22 != 1) {
|
||||
return false;
|
||||
}
|
||||
if (m01 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m02 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m03 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m10 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m12 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m13 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m20 != 0) {
|
||||
return false;
|
||||
}
|
||||
if (m21 != 0) {
|
||||
return false;
|
||||
}
|
||||
return m23 == 0;
|
||||
return m00 == m11 && m11 == m22 && m22 == 1
|
||||
&& m01 == m02 && m02 == m03 && m03 == 0
|
||||
&& m10 == m12 && m12 == m13 && m13 == 0
|
||||
&& m20 == m21 && m21 == m23 && m23 == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -164,20 +136,7 @@ public class AffineTransform implements Transform, Serializable {
|
||||
* 12 double.
|
||||
*/
|
||||
public double[] coefficients() {
|
||||
return new double[] {
|
||||
m00,
|
||||
m01,
|
||||
m02,
|
||||
m03,
|
||||
m10,
|
||||
m11,
|
||||
m12,
|
||||
m13,
|
||||
m20,
|
||||
m21,
|
||||
m22,
|
||||
m23
|
||||
};
|
||||
return new double[]{m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23};
|
||||
}
|
||||
|
||||
public boolean isOffAxis() {
|
||||
@ -198,8 +157,8 @@ public class AffineTransform implements Transform, Serializable {
|
||||
* @return the determinant of the transform.
|
||||
*/
|
||||
private double determinant() {
|
||||
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m20 * m12) + m02 * (m10 * m21
|
||||
- m20 * m11);
|
||||
return m00 * (m11 * m22 - m12 * m21) - m01 * (m10 * m22 - m20 * m12)
|
||||
+ m02 * (m10 * m21 - m20 * m11);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,26 +166,23 @@ public class AffineTransform implements Transform, Serializable {
|
||||
*/
|
||||
@Override
|
||||
public AffineTransform inverse() {
|
||||
if (inverse != null) {
|
||||
return inverse;
|
||||
}
|
||||
double det = this.determinant();
|
||||
return new AffineTransform(
|
||||
(m11 * m22 - m21 * m12) / det,
|
||||
(m21 * m02 - m01 * m22) / det,
|
||||
(m01 * m12 - m11 * m02) / det,
|
||||
(m01 * (m22 * m13 - m12 * m23) + m02 * (m11 * m23 - m21 * m13) - m03 * (m11 * m22
|
||||
- m21 * m12)) / det,
|
||||
(m01 * (m22 * m13 - m12 * m23) + m02 * (m11 * m23 - m21 * m13)
|
||||
- m03 * (m11 * m22 - m21 * m12)) / det,
|
||||
(m20 * m12 - m10 * m22) / det,
|
||||
(m00 * m22 - m20 * m02) / det,
|
||||
(m10 * m02 - m00 * m12) / det,
|
||||
(m00 * (m12 * m23 - m22 * m13) - m02 * (m10 * m23 - m20 * m13) + m03 * (m10 * m22
|
||||
- m20 * m12)) / det,
|
||||
(m00 * (m12 * m23 - m22 * m13) - m02 * (m10 * m23 - m20 * m13)
|
||||
+ m03 * (m10 * m22 - m20 * m12)) / det,
|
||||
(m10 * m21 - m20 * m11) / det,
|
||||
(m20 * m01 - m00 * m21) / det,
|
||||
(m00 * m11 - m10 * m01) / det,
|
||||
(m00 * (m21 * m13 - m11 * m23) + m01 * (m10 * m23 - m20 * m13) - m03 * (m10 * m21
|
||||
- m20 * m11)) / det);
|
||||
(m00 * (m21 * m13 - m11 * m23) + m01 * (m10 * m23 - m20 * m13)
|
||||
- m03 * (m10 * m21 - m20 * m11)) / det);
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
@ -252,7 +208,10 @@ public class AffineTransform implements Transform, Serializable {
|
||||
double n21 = m20 * that.m01 + m21 * that.m11 + m22 * that.m21;
|
||||
double n22 = m20 * that.m02 + m21 * that.m12 + m22 * that.m22;
|
||||
double n23 = m20 * that.m03 + m21 * that.m13 + m22 * that.m23 + m23;
|
||||
return new AffineTransform(n00, n01, n02, n03, n10, n11, n12, n13, n20, n21, n22, n23);
|
||||
return new AffineTransform(
|
||||
n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -275,7 +234,10 @@ public class AffineTransform implements Transform, Serializable {
|
||||
double n21 = that.m20 * m01 + that.m21 * m11 + that.m22 * m21;
|
||||
double n22 = that.m20 * m02 + that.m21 * m12 + that.m22 * m22;
|
||||
double n23 = that.m20 * m03 + that.m21 * m13 + that.m22 * m23 + that.m23;
|
||||
return new AffineTransform(n00, n01, n02, n03, n10, n11, n12, n13, n20, n21, n22, n23);
|
||||
return new AffineTransform(
|
||||
n00, n01, n02, n03,
|
||||
n10, n11, n12, n13,
|
||||
n20, n21, n22, n23);
|
||||
}
|
||||
|
||||
public AffineTransform translate(Vector3 vec) {
|
||||
@ -293,19 +255,31 @@ public class AffineTransform implements Transform, Serializable {
|
||||
public AffineTransform rotateX(double theta) {
|
||||
double cot = MathUtils.dCos(theta);
|
||||
double sit = MathUtils.dSin(theta);
|
||||
return concatenate(new AffineTransform(1, 0, 0, 0, 0, cot, -sit, 0, 0, sit, cot, 0));
|
||||
return concatenate(
|
||||
new AffineTransform(
|
||||
1, 0, 0, 0,
|
||||
0, cot, -sit, 0,
|
||||
0, sit, cot, 0));
|
||||
}
|
||||
|
||||
public AffineTransform rotateY(double theta) {
|
||||
double cot = MathUtils.dCos(theta);
|
||||
double sit = MathUtils.dSin(theta);
|
||||
return concatenate(new AffineTransform(cot, 0, sit, 0, 0, 1, 0, 0, -sit, 0, cot, 0));
|
||||
return concatenate(
|
||||
new AffineTransform(
|
||||
cot, 0, sit, 0,
|
||||
0, 1, 0, 0,
|
||||
-sit, 0, cot, 0));
|
||||
}
|
||||
|
||||
public AffineTransform rotateZ(double theta) {
|
||||
double cot = MathUtils.dCos(theta);
|
||||
double sit = MathUtils.dSin(theta);
|
||||
return concatenate(new AffineTransform(cot, -sit, 0, 0, sit, cot, 0, 0, 0, 0, 1, 0));
|
||||
return concatenate(
|
||||
new AffineTransform(
|
||||
cot, -sit, 0, 0,
|
||||
sit, cot, 0, 0,
|
||||
0, 0, 1, 0));
|
||||
}
|
||||
|
||||
public AffineTransform scale(double s) {
|
||||
@ -361,13 +335,20 @@ public class AffineTransform implements Transform, Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this affine transform is representing a horizontal flip.
|
||||
* Returns if this affine transform represents a horizontal flip.
|
||||
*/
|
||||
public boolean isHorizontalFlip() {
|
||||
// use the determinant of the x-z submatrix to check if this is a horizontal flip
|
||||
return m00 * m22 - m02 * m20 < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if this affine transform represents a vertical flip.
|
||||
*/
|
||||
public boolean isVerticalFlip() {
|
||||
return m11 < 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Affine[%g %g %g %g, %g %g %g %g, %g %g %g %g]}", m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23);
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
|
@ -2,7 +2,7 @@ package com.sk89q.worldedit.math.transform;
|
||||
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
|
||||
public class RoundedTransform implements Transform{
|
||||
public class RoundedTransform implements Transform {
|
||||
private final Transform transform;
|
||||
|
||||
public RoundedTransform(Transform transform) {
|
||||
@ -17,7 +17,8 @@ public class RoundedTransform implements Transform{
|
||||
@Override
|
||||
public Vector3 apply(Vector3 input) {
|
||||
Vector3 val = transform.apply(input);
|
||||
return Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math.floor(val.getY() + 0.5));
|
||||
return Vector3.at(Math.floor(val.getX() + 0.5), Math.floor(val.getY() + 0.5), Math
|
||||
.floor(val.getY() + 0.5));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
|
@ -3,18 +3,18 @@
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* Copyright (C) WorldEdit team and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||
* for more details.
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.math.transform;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren