package com.ld.igds.grain;
|
|
import org.springframework.stereotype.Component;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 根据电缆起始方位、起始点位、布线方向等进行调转
|
*
|
* @author: chen
|
* @description:
|
* @version:
|
* @data:2022年08月06日
|
*/
|
@Component
|
public class GrainUtil {
|
|
/**
|
* 粮情点位验证
|
*
|
* @param args
|
*/
|
public static void main(String[] args) {
|
//层行列:2-3-4
|
int cableZ = 2; //层
|
int cableY = 3; //行
|
int cableX = 4; //列
|
|
List<Double> temps = new ArrayList<>();
|
for (int i = 1; i < (cableX * cableY * cableZ + 1); i++) {
|
temps.add(i + 0.0);
|
}
|
System.out.println("--默认起始,默认布线--" + temps.toString());
|
List<Double> list;
|
|
/*==========右边起始,横向布线==========*/
|
list = new ArrayList<>();
|
for (int x = 1; x <= cableX; x++) {
|
for (int y = 1; y <= cableY; y++) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
System.out.println("--右边起始,横向布线--" + list.toString());
|
|
/*==========右上起始,横向布线==========*/
|
list = new ArrayList<>();
|
for (int x = 1; x <= cableX; x++) {
|
for (int y = cableY; y >= 1; y--) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
System.out.println("--右上起始,横向布线--" + list.toString());
|
|
/*==========右上起始,纵向布线==========*/
|
list = new ArrayList<>();
|
for (int x = 1; x <= cableX; x++) {
|
for (int y = cableY; y >= 1; y--) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((x - 1) * cableZ * cableY + (y - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
System.out.println("--右上起始,纵向布线--" + list.toString());
|
|
/*==========左上起始,横向布线==========*/
|
list = new ArrayList<>();
|
for (int x = cableX; x >= 1; x--) {
|
for (int y = cableY; y >= 1; y--) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
System.out.println("--左上起始,横向布线--" + list.toString());
|
|
/*==========左上起始,纵向布线==========*/
|
list = new ArrayList<>();
|
for (int i = temps.size() - 1; i >= 0; i--) {
|
list.add(temps.get(i));
|
}
|
System.out.println("--左上起始,纵向布线--" + list.toString());
|
|
/*==========左边起始,横向布线=========*/
|
list = new ArrayList<>();
|
for (int x = cableX; x >= 1; x--) {
|
for (int y = 1; y <= cableY; y++) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
System.out.println("--左边起始,横向布线--" + list.toString());
|
|
/*==========左边起始,纵向布线==========*/
|
list = new ArrayList<>();
|
for (int i = 1; i <= temps.size(); i++) {
|
list.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ))));
|
if (i % (cableY * cableZ) == 0) {
|
cableX = cableX - 1;
|
}
|
}
|
System.out.println("--左边起始,纵向布线--" + list.toString());
|
|
/*==========上下翻转==========*/
|
list = new ArrayList<>();
|
for (int i = 0; i <= temps.size() - cableZ; i += cableZ) {
|
for (int j = cableZ - 1; j >= 0; j--) {
|
list.add(temps.get(i + j));
|
}
|
}
|
System.out.println("--上下翻转--" + list.toString());
|
}
|
|
/**
|
* 转换粮情,从右边起始,横向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalRight1(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int x = 1; x <= cableX; x++) {
|
for (int y = 1; y <= cableY; y++) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 转换粮情,从右上起始,横向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalRightUp1(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int x = 1; x <= cableX; x++) {
|
for (int y = cableY; y >= 1; y--) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 转换粮情,从右上起始,纵向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalRightUp2(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int x = 1; x <= cableX; x++) {
|
for (int y = cableY; y >= 1; y--) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((x - 1) * cableZ * cableY + (y - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 转换粮情,从左边起始,横向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalLeft1(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int x = cableX; x >= 1; x--) {
|
for (int y = 1; y <= cableY; y++) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 转换粮情,从左边起始,纵向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalLeft2(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int i = 1; i <= temps.size(); i++) {
|
list.add(temps.get((cableX - 1) * cableY * cableZ + ((i - 1) % (cableY * cableZ))));
|
if (i % (cableY * cableZ) == 0) {
|
cableX = cableX - 1;
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 转换粮情,从左上起始,横向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalLeftUp1(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int x = cableX; x >= 1; x--) {
|
for (int y = cableY; y >= 1; y--) {
|
for (int z = 1; z <= cableZ; z++) {
|
list.add(temps.get((y - 1) * cableX * cableZ + (x - 1) * cableZ + z - 1));
|
}
|
}
|
}
|
return list;
|
}
|
|
/**
|
* 转换粮情,从左上起始,纵向布线
|
*
|
* @param temps
|
* @param cable
|
* @return
|
*/
|
public List<Double> reversalLeftUp2(List<Double> temps, String cable) {
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]);
|
int cableY = Integer.valueOf(attCable[1]);
|
int cableX = Integer.valueOf(attCable[2]);
|
List<Double> list = new ArrayList<>();
|
for (int i = temps.size() - 1; i >= 0; i--) {
|
list.add(temps.get(i));
|
}
|
return list;
|
}
|
|
/**
|
* 电缆从下面开始时,将粮情电缆上下翻转
|
*
|
* @param temps 粮情数据
|
* @param cable 层行列配置,如:4-7-11
|
* @return
|
*/
|
public List<Double> reversalUpAndDown(List<Double> temps, String cable) {
|
|
List<Double> list = new ArrayList<>();
|
String[] attCable = cable.split("-");
|
int cableZ = Integer.valueOf(attCable[0]); //层
|
|
for (int i = 0; i <= temps.size() - cableZ; i += cableZ) {
|
for (int j = cableZ - 1; j >= 0; j--) {
|
list.add(temps.get(i + j));
|
}
|
}
|
return list;
|
}
|
|
}
|