~jan-zarsky/tree/trunk

« back to all changes in this revision

Viewing changes to TreeGenerator/Polyhedron.cs

  • Committer: janzarsky
  • Date: 2012-09-22 20:11:36 UTC
  • Revision ID: git-v1:1715cd6dba5aaf240423efa558eeae36e01e2cbd
Code cleaning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  
 
2
//  MatrixComposite.cs
 
3
//  
 
4
//  Author:
 
5
//       janzarsky <${AuthorEmail}>
 
6
// 
 
7
//  Copyright (c) 2012 janzarsky
 
8
// 
 
9
//  This program is free software: you can redistribute it and/or modify
 
10
//  it under the terms of the GNU General Public License as published by
 
11
//  the Free Software Foundation, either version 3 of the License, or
 
12
//  (at your option) any later version.
 
13
// 
 
14
//  This program is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
//  GNU General Public License for more details.
 
18
// 
 
19
//  You should have received a copy of the GNU General Public License
 
20
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
21
using System;
 
22
using System.Collections.Generic;
 
23
 
 
24
namespace TreeGenerator {
 
25
        class Polyhedron : IMatrix, IComposite<Polyhedron> {
 
26
                Matrix generalMatrix;
 
27
                Matrix matrix = Matrix.Empty;
 
28
                double perimeter;
 
29
                int quality;
 
30
                List<Polyhedron> children = new List<Polyhedron>();
 
31
                
 
32
                public Polyhedron(double perimeter, int quality, Matrix generalMatrix) {
 
33
                        this.perimeter = perimeter;
 
34
                        this.quality = quality;
 
35
                        this.generalMatrix = generalMatrix;
 
36
                }
 
37
 
 
38
                public void AddChild(double perimeter, int quality) {
 
39
                        children.Add(new Polyhedron(perimeter, quality, generalMatrix));
 
40
                }
 
41
                
 
42
                public Circle CreateCircle(Circle circle) {
 
43
                        Matrix finalMatrix = Matrix.FromMatrixes(matrix, generalMatrix);
 
44
                        
 
45
                        circle.AddChild(new Circle(perimeter/2, quality, finalMatrix));
 
46
 
 
47
                        for (int i = 0; i < children.Count; i++)
 
48
                                children[i].CreateCircle(circle.Children[circle.Children.Count - 1]);
 
49
                        
 
50
                        return circle;
 
51
                }
 
52
 
 
53
                public List<Polyhedron> Children {
 
54
                        get { return children; }
 
55
                }
 
56
                
 
57
                public void ApplyMatrix(Matrix matrix) {
 
58
                        this.matrix.Multiply(matrix);
 
59
                        
 
60
                        foreach (Polyhedron child in children)
 
61
                                child.ApplyMatrix(matrix);
 
62
                }
 
63
        }
 
64
}
 
 
b'\\ No newline at end of file'