@@ -18,7 +18,7 @@ public class Element {
1818 public final int x2 , y2 , z2 ;
1919 public final List <String > faces ;
2020
21- private Element (int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , List <String > faces ) {
21+ public Element (int x1 , int y1 , int z1 , int x2 , int y2 , int z2 , List <String > faces ) {
2222 this .x1 = Math .min (x1 , x2 );
2323 this .y1 = Math .min (y1 , y2 );
2424 this .z1 = Math .min (z1 , z2 );
@@ -68,34 +68,31 @@ public boolean isValid() {
6868
6969 public Element rotateX (int degrees ) {
7070 double rads = Math .toRadians (degrees );
71- int yOff = degrees > 89 && degrees < 271 ? 16 : 0 ;
72- int zOff = degrees > 179 && degrees < 361 ? 16 : 0 ;
73- int z1 = (int ) Math .round (this .z1 * Math .cos (rads ) - this .y1 * Math .sin (rads )) + zOff ;
74- int y1 = (int ) Math .round (this .y1 * Math .cos (rads ) + this .z1 * Math .sin (rads )) + yOff ;
75- int z2 = (int ) Math .round (this .z2 * Math .cos (rads ) - this .y2 * Math .sin (rads )) + zOff ;
76- int y2 = (int ) Math .round (this .y2 * Math .cos (rads ) + this .z2 * Math .sin (rads )) + yOff ;
71+ int cz = 8 , cy = 8 ;
72+ int z1 = cz + (int ) Math .round ((this .z1 - cz ) * Math .cos (rads ) - (this .y1 - cy ) * Math .sin (rads ));
73+ int y1 = cy + (int ) Math .round ((this .y1 - cy ) * Math .cos (rads ) + (this .z1 - cz ) * Math .sin (rads ));
74+ int z2 = cz + (int ) Math .round ((this .z2 - cz ) * Math .cos (rads ) - (this .y2 - cy ) * Math .sin (rads ));
75+ int y2 = cy + (int ) Math .round ((this .y2 - cy ) * Math .cos (rads ) + (this .z2 - cz ) * Math .sin (rads ));
7776 return new Element (x1 , y1 , z1 , x2 , y2 , z2 , faces );
7877 }
7978
8079 public Element rotateY (int degrees ) {
8180 double rads = Math .toRadians (degrees );
82- int xOff = degrees > 89 && degrees < 270 ? 16 : 0 ;
83- int zOff = degrees > 179 && degrees < 360 ? 16 : 0 ;
84- int x1 = (int ) Math .round (this .x1 * Math .cos (rads ) - this .z1 * Math .sin (rads )) + xOff ;
85- int z1 = (int ) Math .round (this .z1 * Math .cos (rads ) + this .x1 * Math .sin (rads )) + zOff ;
86- int x2 = (int ) Math .round (this .x2 * Math .cos (rads ) - this .z2 * Math .sin (rads )) + xOff ;
87- int z2 = (int ) Math .round (this .z2 * Math .cos (rads ) + this .x2 * Math .sin (rads )) + zOff ;
81+ int cx = 8 , cz = 8 ;
82+ int x1 = cx + (int ) Math .round ((this .x1 - cx ) * Math .cos (rads ) - (this .z1 - cz ) * Math .sin (rads ));
83+ int z1 = cz + (int ) Math .round ((this .z1 - cz ) * Math .cos (rads ) + (this .x1 - cx ) * Math .sin (rads ));
84+ int x2 = cx + (int ) Math .round ((this .x2 - cx ) * Math .cos (rads ) - (this .z2 - cz ) * Math .sin (rads ));
85+ int z2 = cz + (int ) Math .round ((this .z2 - cz ) * Math .cos (rads ) + (this .x2 - cx ) * Math .sin (rads ));
8886 return new Element (x1 , y1 , z1 , x2 , y2 , z2 , faces );
8987 }
9088
9189 public Element rotateZ (int degrees ) {
9290 double rads = Math .toRadians (degrees );
93- int xOff = degrees > 89 && degrees < 271 ? 16 : 0 ;
94- int yOff = degrees > 179 && degrees < 361 ? 16 : 0 ;
95- int x1 = (int ) Math .round (this .x1 * Math .cos (rads ) - this .y1 * Math .sin (rads )) + xOff ;
96- int y1 = (int ) Math .round (this .y1 * Math .cos (rads ) + this .x1 * Math .sin (rads )) + yOff ;
97- int x2 = (int ) Math .round (this .x2 * Math .cos (rads ) - this .y2 * Math .sin (rads )) + xOff ;
98- int y2 = (int ) Math .round (this .y2 * Math .cos (rads ) + this .x2 * Math .sin (rads )) + yOff ;
91+ int cx = 8 , cy = 8 ;
92+ int x1 = cx + (int ) Math .round ((this .x1 - cx ) * Math .cos (rads ) - (this .z1 - cy ) * Math .sin (rads ));
93+ int y1 = cy + (int ) Math .round ((this .y1 - cy ) * Math .cos (rads ) + (this .x1 - cx ) * Math .sin (rads ));
94+ int x2 = cx + (int ) Math .round ((this .x2 - cx ) * Math .cos (rads ) - (this .z2 - cy ) * Math .sin (rads ));
95+ int y2 = cy + (int ) Math .round ((this .y2 - cy ) * Math .cos (rads ) + (this .x2 - cx ) * Math .sin (rads ));
9996 return new Element (x1 , y1 , z1 , x2 , y2 , z2 , faces );
10097 }
10198
0 commit comments