mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-04 00:45:57 +00:00
abstract BinaryColumn boolean operators
This commit is contained in:
parent
8a35e3f21d
commit
a7d0d52dfb
@ -9,6 +9,7 @@ package com.dfsek.terra.api.structure.feature;
|
|||||||
|
|
||||||
import com.dfsek.terra.api.util.Range;
|
import com.dfsek.terra.api.util.Range;
|
||||||
|
|
||||||
|
import java.util.function.BinaryOperator;
|
||||||
import java.util.function.IntConsumer;
|
import java.util.function.IntConsumer;
|
||||||
|
|
||||||
|
|
||||||
@ -73,15 +74,7 @@ public class BinaryColumn {
|
|||||||
* @throws IllegalArgumentException if column heights do not match
|
* @throws IllegalArgumentException if column heights do not match
|
||||||
*/
|
*/
|
||||||
public BinaryColumn and(BinaryColumn that) {
|
public BinaryColumn and(BinaryColumn that) {
|
||||||
if(that.minY != this.minY) throw new IllegalArgumentException("Must share same min Y");
|
return bool(that, Boolean::logicalAnd);
|
||||||
if(that.data.length != this.data.length) throw new IllegalArgumentException("Must share same max Y");
|
|
||||||
BinaryColumn next = new BinaryColumn(minY, data.length - minY);
|
|
||||||
|
|
||||||
for(int i = 0; i < this.data.length; i++) {
|
|
||||||
next.data[i] = this.data[i] && that.data[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -92,6 +85,10 @@ public class BinaryColumn {
|
|||||||
* @throws IllegalArgumentException if column heights do not match
|
* @throws IllegalArgumentException if column heights do not match
|
||||||
*/
|
*/
|
||||||
public BinaryColumn or(BinaryColumn that) {
|
public BinaryColumn or(BinaryColumn that) {
|
||||||
|
return bool(that, Boolean::logicalOr);
|
||||||
|
}
|
||||||
|
|
||||||
|
private BinaryColumn bool(BinaryColumn that, BinaryOperator<Boolean> operator) {
|
||||||
int smallMinY = Math.min(this.minY, that.minY);
|
int smallMinY = Math.min(this.minY, that.minY);
|
||||||
int bigMaxY = Math.max(this.maxY, that.maxY);
|
int bigMaxY = Math.max(this.maxY, that.maxY);
|
||||||
|
|
||||||
@ -108,7 +105,7 @@ public class BinaryColumn {
|
|||||||
if(that.data.length > index) {
|
if(that.data.length > index) {
|
||||||
right = this.data[index];
|
right = this.data[index];
|
||||||
}
|
}
|
||||||
next.data[i] = left || right;
|
next.data[i] = operator.apply(left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
return next;
|
return next;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user