Project

General

Profile

Download (5.15 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / DistortedCubes.java @ b73dcaa7

1 d333eb6b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2016 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Distorted.                                                               //
5
//                                                                                               //
6
// Distorted is free software: you can redistribute it and/or modify                             //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Distorted is distributed in the hope that it will be useful,                                  //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Distorted.  If not, see <http://www.gnu.org/licenses/>.                            //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20 6a06a912 Leszek Koltunski
package org.distorted.library;
21
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24 b73dcaa7 Leszek Koltunski
 * DistortedObject descendant - with a Grid composed of a set of cubes, centers of which all have equal Z-coords.
25 6a06a912 Leszek Koltunski
 * (a subset of a NxMx1 cuboid build with 1x1x1 cubes, i.e. the MxNx1 cuboid with arbitrary cubes missing)
26
 */
27
public class DistortedCubes extends DistortedObject
28
   {
29
   
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31
// PUBLIC API
32 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
33 6a06a912 Leszek Koltunski
/**
34
 * Creates internal memory representation of a cuboid subset.
35 9361b337 Leszek Koltunski
 *
36 6a06a912 Leszek Koltunski
 * @param cols Integer helping to parse the next parameter.
37
 * @param desc String describing the subset of a MxNx1 cuboid that we want to create.
38
 *             Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
39 688662ef Leszek Koltunski
 *      <p></p>
40
 *      <p>
41
 *      <pre>
42
 *      For example, (cols=2, desc="111010") describes the following shape:
43 9361b337 Leszek Koltunski
 *
44 688662ef Leszek Koltunski
 *      XX
45
 *      X
46
 *      X
47 9361b337 Leszek Koltunski
 *
48 688662ef Leszek Koltunski
 *      whereas (cols=2,desc="110001") describes
49 9361b337 Leszek Koltunski
 *
50 688662ef Leszek Koltunski
 *      XX
51 9361b337 Leszek Koltunski
 *
52 688662ef Leszek Koltunski
 *       X
53
 *      </pre>
54
 *      </p>
55 ffbf279e Leszek Koltunski
 * @param cubeSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
56 6a06a912 Leszek Koltunski
 * @param frontOnly Only create the front wall or side and back as well?
57
 */
58 ffbf279e Leszek Koltunski
 public DistortedCubes(int cols, String desc, int cubeSize, boolean frontOnly)
59 9361b337 Leszek Koltunski
   {
60
   int Rs = 0;
61
   int Cs = 0;
62 6a06a912 Leszek Koltunski
     
63 9361b337 Leszek Koltunski
   if( cols>0 )
64
     {
65
     int reallen = desc.length();
66
     int len = reallen;
67 6a06a912 Leszek Koltunski
68 9361b337 Leszek Koltunski
     if( (reallen/cols)*cols != reallen )
69
       {
70
       len = ((reallen/cols)+1)*cols;
71
       for(int i=reallen; i<len; i++) desc += "0";
72
       }
73 6a06a912 Leszek Koltunski
    
74 ada90d33 Leszek Koltunski
     if( desc.contains("1") )
75 9361b337 Leszek Koltunski
       {
76
       Cs = cols;
77
       Rs = len/cols;
78 6a06a912 Leszek Koltunski
       }
79
     }
80 9361b337 Leszek Koltunski
     
81 0729bc41 Leszek Koltunski
   mGrid = DistortedGridFactory.getGrid(cols,desc, frontOnly);
82 3d590d8d Leszek Koltunski
   initializeData(cubeSize*Cs,cubeSize*Rs,frontOnly ? 1 : cubeSize);
83 9361b337 Leszek Koltunski
   }
84
85 665e2c45 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
86
/**
87
 * Creates internal memory representation of a full, hole-less cuboid subset.
88
 *
89
 * @param cols Number of columns
90
 * @param rows Number of rows
91
 * @param cubeSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
92
 * @param frontOnly Only create the front wall or side and back as well?
93
 */
94
 public DistortedCubes(int cols, int rows, int cubeSize, boolean frontOnly)
95
   {
96
   mGrid = DistortedGridFactory.getGrid(cols,rows, frontOnly);
97 3d590d8d Leszek Koltunski
   initializeData(cubeSize*cols,cubeSize*rows,frontOnly ? 1 : cubeSize);
98 665e2c45 Leszek Koltunski
   }
99
100 9361b337 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
101
/**
102 350cc2f5 Leszek Koltunski
 * Convenience constructor.
103 9361b337 Leszek Koltunski
 */
104
 public DistortedCubes(int cols, String desc, int gridSize)
105
   {
106
   this(cols,desc,gridSize,false);
107
   }
108
109 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
110
/**
111 8298e6af Leszek Koltunski
 * Copy constructor.
112
 *
113
 * @param dc Object to copy
114 b911dc09 Leszek Koltunski
 * @param flags see {@link DistortedObject#DistortedObject(DistortedObject,int)}
115 6a06a912 Leszek Koltunski
 */
116 9361b337 Leszek Koltunski
 public DistortedCubes(DistortedCubes dc, int flags)
117
   {
118
   super(dc,flags);
119
   }
120 6a06a912 Leszek Koltunski
121 ada90d33 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123 0729bc41 Leszek Koltunski
 protected DistortedObject deepCopy(int flags)
124
   {
125
   return new DistortedCubes(this,flags);
126
   }
127 ada90d33 Leszek Koltunski
128 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////   
129 9361b337 Leszek Koltunski
 }