Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.library;
21

    
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23
/**
24
 * DistortedObject descendant - with a Grid composed of a set of cubes, centers of which all have equal Z-coords.
25
 * (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
///////////////////////////////////////////////////////////////////////////////////////////////////
33
/**
34
 * Creates internal memory representation of a cuboid subset.
35
 *
36
 * @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
 *      <p></p>
40
 *      <p>
41
 *      <pre>
42
 *      For example, (cols=2, desc="111010") describes the following shape:
43
 *
44
 *      XX
45
 *      X
46
 *      X
47
 *
48
 *      whereas (cols=2,desc="110001") describes
49
 *
50
 *      XX
51
 *
52
 *       X
53
 *      </pre>
54
 *      </p>
55
 * @param cubeSize size, in pixels, of the single 1x1x1 cube our cuboid is built from
56
 * @param frontOnly Only create the front wall or side and back as well?
57
 */
58
 public DistortedCubes(int cols, String desc, int cubeSize, boolean frontOnly)
59
   {
60
   int Rs = 0;
61
   int Cs = 0;
62
     
63
   if( cols>0 )
64
     {
65
     int reallen = desc.length();
66
     int len = reallen;
67

    
68
     if( (reallen/cols)*cols != reallen )
69
       {
70
       len = ((reallen/cols)+1)*cols;
71
       for(int i=reallen; i<len; i++) desc += "0";
72
       }
73
    
74
     if( desc.contains("1") )
75
       {
76
       Cs = cols;
77
       Rs = len/cols;
78
       }
79
     }
80
     
81
   mGrid = DistortedGridFactory.getGrid(cols,desc, frontOnly);
82
   initializeData(cubeSize*Cs,cubeSize*Rs,frontOnly ? 1 : cubeSize);
83
   }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
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
   initializeData(cubeSize*cols,cubeSize*rows,frontOnly ? 1 : cubeSize);
98
   }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
/**
102
 * Convenience constructor.
103
 */
104
 public DistortedCubes(int cols, String desc, int gridSize)
105
   {
106
   this(cols,desc,gridSize,false);
107
   }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
/**
111
 * Copy constructor.
112
 *
113
 * @param dc Object to copy
114
 * @param flags see {@link DistortedObject#DistortedObject(DistortedObject,int)}
115
 */
116
 public DistortedCubes(DistortedCubes dc, int flags)
117
   {
118
   super(dc,flags);
119
   }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
 protected DistortedObject deepCopy(int flags)
124
   {
125
   return new DistortedCubes(this,flags);
126
   }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////   
129
 }
(4-4/17)