PageRenderTime 103ms CodeModel.GetById 74ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 0ms

/unmaintained/adsoda/adsoda-tests.factor

http://github.com/abeaumont/factor
Unknown | 310 lines | 254 code | 56 blank | 0 comment | 0 complexity | 516205d585e134e39bf5af7cc40a4b13 MD5 | raw file
  1USING: adsoda
  2kernel
  3math
  4accessors
  5sequences
  6    adsoda.solution2
  7    fry
  8    tools.test 
  9    arrays ;
 10
 11IN: adsoda.tests
 12
 13
 14
 15: s1 ( -- solid )
 16    <solid> 
 17    2 >>dimension
 18    "s1" >>name
 19    { 1 1 1 } >>color
 20    { 1 -1 -5 } cut-solid 
 21    { -1 -1 -21 } cut-solid 
 22    { -1 0 -12 } cut-solid 
 23    { 1 2 16 } cut-solid
 24;
 25: solid1 ( -- solid )
 26    <solid> 
 27    2 >>dimension
 28    "solid1" >>name
 29    { 1 -1 -5 } cut-solid 
 30    { -1 -1 -21 } cut-solid 
 31    { -1 0 -12 } cut-solid 
 32    { 1 2 16 } cut-solid
 33    ensure-adjacencies
 34    
 35;
 36: solid2 ( -- solid )
 37    <solid> 
 38    2 >>dimension
 39    "solid2" >>name
 40    { -1 1 -10 } cut-solid 
 41    { -1 -1 -28 } cut-solid 
 42    { 1 0 13 } cut-solid 
 43 !   { 1 2 16 } cut-solid
 44    ensure-adjacencies
 45    
 46;
 47
 48: solid3 ( -- solid )
 49      <solid> 
 50    2 >>dimension
 51    "solid3" >>name
 52    { 1 1 1 } >>color
 53    { 1 0 16 } cut-solid 
 54    { -1 0 -36 } cut-solid 
 55    { 0 1 1 } cut-solid 
 56    { 0 -1  -17 } cut-solid 
 57 !   { 1 2 16 } cut-solid
 58    ensure-adjacencies
 59    
 60
 61;
 62
 63: solid4 ( -- solid )
 64      <solid> 
 65    2 >>dimension
 66    "solid4" >>name
 67    { 1 1 1 } >>color
 68    { 1 0 21 } cut-solid 
 69    { -1 0 -36 } cut-solid 
 70    { 0 1 1 } cut-solid 
 71    { 0 -1  -17 } cut-solid 
 72    ensure-adjacencies
 73    
 74;
 75
 76: solid5 ( -- solid )
 77      <solid> 
 78    2 >>dimension
 79    "solid5" >>name
 80    { 1 1 1 } >>color
 81    { 1 0 6 } cut-solid 
 82    { -1 0 -17 } cut-solid 
 83    { 0 1 17 } cut-solid 
 84    { 0 -1  -19 } cut-solid 
 85    ensure-adjacencies
 86    
 87;
 88
 89: solid7 ( -- solid )
 90      <solid> 
 91    2 >>dimension
 92    "solid7" >>name
 93    { 1 1 1 } >>color
 94    { 1 0 38 } cut-solid 
 95    { 1 -5 -66 } cut-solid 
 96    { -2 1 -75 } cut-solid
 97    ensure-adjacencies
 98    
 99;
100
101: solid6s ( -- seq )
102  solid3 clone solid2 clone subtract
103;
104
105: space1 ( -- space )
106    <space>
107        2 >>dimension
108     !    solid3 suffix-solids
109        solid1 suffix-solids
110        solid2 suffix-solids
111    !   solid6s [ suffix-solids ] each 
112        solid4 suffix-solids
113     !   solid5 suffix-solids
114        solid7 suffix-solids
115        { 1 1 1 } >>ambient-color
116            <light>
117        { -100 -100 } >>position
118        { 0.2 0.7 0.1 } >>color
119        suffix-lights
120;
121
122: space2 ( -- space )
123    <space>
124        4 >>dimension
125       ! 4cube suffix-solids
126        { 1 1 1 } >>ambient-color
127            <light>
128        { -100 -100 } >>position
129        { 0.2 0.7 0.1 } >>color
130        suffix-lights
131
132       ;
133
134
135
136! {
137!        { 1 0 0 0 }
138!        { 0 1 0 0 }
139!        { 0 0 0.984807753012208 -0.1736481776669303 }
140!        { 0 0 0.1736481776669303 0.984807753012208 }
141!    }
142
143! ------------------------------------------------------------
144! constant+
145[ { 1 2 5 } ] [ { 1 2 3 } 2 constant+ ] unit-test
146
147! ------------------------------------------------------------
148! translate
149[ { 1 -1 0 } ] [ { 1 -1 -5 } { 3 -2 } translate ] unit-test
150
151! ------------------------------------------------------------
152! transform
153[ { -1 -1 -5 21.0 } ] [ { -1 -1 -5 21 }
154  { { 1 0 0 }
155    { 0 1 0 }
156    { 0 0 1 }
157    } transform  
158] unit-test
159
160! ------------------------------------------------------------
161! compare-nleft-to-identity-matrix
162[ t ] [ 
163    { 
164        { 1 0 0 1232 } 
165        { 0 1 0 0 321 } 
166        { 0 0 1 0 } } 
167        3 compare-nleft-to-identity-matrix 
168]  unit-test
169
170[ f ] [ 
171    { { 1 0 0 } { 0 1 0 } { 0 0 0 } } 
172    3 compare-nleft-to-identity-matrix 
173] unit-test
174
175[ f ] [ 
176    { { 2 0 0 } { 0 1 0 } { 0 0 1 } } 
177    3 compare-nleft-to-identity-matrix 
178] unit-test
179! ------------------------------------------------------------
180[ t ] [ 
181  { { 1 0 0 }
182    { 0 1 0 }
183    { 0 0 1 } } 3 valid-solution? 
184] unit-test
185
186[ f ] [ 
187  { { 1 0 0 1 }
188    { 0 0 0 1 }
189    { 0 0 1 0 } } 3 valid-solution? 
190] unit-test
191
192[ f ] [ 
193  { { 1 0 0 1 }
194    { 0 0 0 1 } } 3 valid-solution? 
195] unit-test
196
197[ f ] [ 
198  { { 1 0 0 1 }
199    { 0 0 0 1 }
200    { 0 0 1 0 } } 2 valid-solution? 
201] unit-test
202
203! ------------------------------------------------------------
204[ 3 ] [ { 1 2 3 } last ] unit-test 
205
206[ { 1 2 5 } ] [ { 1 2 3 } dup [ 2 + ] change-last ] unit-test 
207
208! ------------------------------------------------------------
209! position-point 
210[ 0 ] [ 
211    { 1 -1 -5 } { 2 7 } position-point 
212] unit-test
213
214! ------------------------------------------------------------
215
216! transform
217! TODO construire un exemple
218
219
220! ------------------------------------------------------------
221! slice-solid 
222
223! ------------------------------------------------------------
224! solve-equation 
225! deux cas de tests, avec solution et sans solution
226
227[ { 2 7 } ] 
228[ { { 1 -1 -5 } { 1 2 16 } } intersect-hyperplanes ] 
229unit-test
230
231[ f ] 
232[ { { 1 -1 -5 } { 1 2 16 } { -1 -1 -21 } } intersect-hyperplanes  ]
233unit-test
234
235[ f ] 
236[ { { 1 0 -5 } { 1 0 16 }  } intersect-hyperplanes  ]
237unit-test
238
239! ------------------------------------------------------------
240! point-inside-halfspace
241[ t ] [ { 1 -1 -5 } { 0 0 }  point-inside-halfspace? ] 
242unit-test
243[ f ] [ { 1 -1 -5 } { 8 13 }  point-inside-halfspace? ] 
244unit-test
245[ t ] [ { 1 -1 -5 } { 8 13 }  point-inside-or-on-halfspace? ] 
246unit-test
247
248
249! ------------------------------
250! order solid
251
252[  1 ] [ 0 >pv solid1 solid2 order-solid ] unit-test
253[ -1 ] [ 0 >pv solid2 solid1 order-solid ] unit-test
254[  f ] [ 1 >pv solid1 solid2 order-solid ] unit-test
255[  f ] [ 1 >pv solid2 solid1 order-solid ] unit-test
256
257
258! clip-solid
259[ { { 13 15 } { 15 13 } { 13 13 } } ]
260    [ 0 >pv solid2 solid1 clip-solid first corners>> ] unit-test
261
262solid1 corners>> '[ _ ]
263    [ 0 >pv solid1 solid1 clip-solid first corners>> ] unit-test
264
265solid1 corners>> '[ _ ]
266    [ 0 >pv solid1 solid2 clip-solid first corners>> ] unit-test
267
268solid1 corners>> '[ _ ]
269    [ 1 >pv solid1 solid2 clip-solid first corners>> ] unit-test
270solid2 corners>> '[ _ ]
271    [ 1 >pv solid2 solid1 clip-solid first corners>> ] unit-test
272
273!
274[
275    {
276        { { 13 15 } { 15 13 } { 13 13 } }
277        { { 16 17 } { 16 13 } { 36 17 } { 36 13 } }
278        { { 16 1 } { 16 2 } { 36 1 } { 36 2 } }
279    }
280] [     0 >pv solid2 solid3  2array 
281        solid1 (solids-silhouette-subtract) 
282        [ corners>> ] map
283  ] unit-test
284
285
286[
287{
288    { { 8 13 } { 2 7 } { 12 9 } { 12 2 } }
289    { { 13 15 } { 15 13 } { 13 13 } }
290    { { 16 17 } { 16 15 } { 36 17 } { 36 15 } }
291    { { 16 1 } { 16 2 } { 36 1 } { 36 2 } }
292}
293] [ 
294    0 >pv  <space> solid1 suffix-solids 
295        solid2 suffix-solids 
296        solid3 suffix-solids
297     remove-hidden-solids
298    solids>> [ corners>> ] map
299] unit-test
300
301! { }
302! { }
303! <light> { 0.2 0.3 0.4 } >>color { 1 -1 1 } >>direction     suffix
304! <light> { 0.4 0.3 0.1 } >>color { -1 -1 -1 } >>direction   suffix
305! suffix 
306! { 0.1 0.1 0.1 } suffix ! ambient color
307! { 0.23 0.32 0.17 } suffix ! solid color
308! solid3 faces>> first 
309
310! enlight-projection