MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / flattenInput

Method flattenInput

src/main/java/field/graphics/FLine.java:869–952  ·  view source on GitHub ↗
(Object i)

Source from the content-addressed store, hash-verified

867 for (Object q : ((Iterable) i)) {
868 o.addAll(flattenInput(q));
869 }
870 return o;
871 }
872 if (i instanceof Vec2) o.add(((Vec2) i).toVec3());
873 else if (i instanceof Vec3) o.add((Vec3) i);
874 else if (i instanceof Vec4) o.add(((Vec4) i).toVec3());
875 else if (i instanceof Supplier) {
876 Object ni = ((Supplier) i).get();
877 if (i != ni) o.addAll(flattenInput(ni));
878 } else if (i instanceof Object[]) {
879 for (Object ii : (Object[]) i)
880 o.addAll(flattenInput(ii));
881 } else if (i instanceof CubicTo) {
882 o.add(((CubicTo) i).c1);
883 o.add(((CubicTo) i).c2);
884 o.add(((CubicTo) i).to);
885 } else if (i instanceof LineTo) {
886 o.add(((LineTo) i).to);
887 } else if (i instanceof MoveTo) {
888 o.add(((MoveTo) i).to);
889 } else if (i instanceof Quad) {
890 o.addAll(flattenInput(((Quad) i).first));
891 o.addAll(flattenInput(((Quad) i).second));
892 o.addAll(flattenInput(((Quad) i).third));
893 o.addAll(flattenInput(((Quad) i).fourth));
894 } else if (i instanceof Triple) {
895 o.addAll(flattenInput(((Triple) i).first));
896 o.addAll(flattenInput(((Triple) i).second));
897 o.addAll(flattenInput(((Triple) i).third));
898 } else if (i instanceof Pair) {
899 o.addAll(flattenInput(((Pair) i).first));
900 o.addAll(flattenInput(((Pair) i).second));
901 } else if (i instanceof MappedFloatArray) {
902 Iterator<Vec3> ii = ((MappedFloatArray) i).getVec3s();
903 ii.forEachRemaining(x -> o.add(x));
904 } else if (i instanceof Collection) {
905
906 Collection co = (Collection) i;
907 if (co.size() == 2 || co.size() == 3) {
908 //peek at it, it might be a vec3 or vec2 spelled as a collection
909 Iterator m = co.iterator();
910 List<Double> out = new ArrayList<>();
911 boolean fail = false;
912 while (m.hasNext()) {
913 Object mn = m.next();
914 if (!(mn instanceof Number)) {
915 fail = true;
916 break;
917 } else out.add(((Number) mn).doubleValue());
918 }
919 if (!fail) {
920 if (out.size() == 2) {
921 return flattenInput(new Vec3(out.get(0), out.get(1), 0));
922 } else {
923 return flattenInput(new Vec3(out.get(0), out.get(1), out.get(2)));
924 }
925 }
926 }

Callers 1

dataMethod · 0.95

Calls 9

getVec3sMethod · 0.80
getMethod · 0.65
hasNextMethod · 0.65
nextMethod · 0.65
addAllMethod · 0.45
addMethod · 0.45
toVec3Method · 0.45
sizeMethod · 0.45
iteratorMethod · 0.45

Tested by

no test coverage detected