Skip to content

Commit

Permalink
Merge pull request #21 from maslankam/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
maslankam authored Dec 14, 2019
2 parents 6fe2a96 + 2204e8d commit 4077b7c
Show file tree
Hide file tree
Showing 58 changed files with 819 additions and 931 deletions.
10 changes: 2 additions & 8 deletions Model/Boundary/AbsorbingBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
namespace Model{
namespace Model.Boundary{


public class AbsorbingBoundary : IBoundaryCondition
{
public string Name
{
get
{
return this.ToString();
}
}
public string Name => this.ToString();

// AbsorbingBoundary always return null Cell
/// |nl|nl|nl|nl|nl|
Expand Down
6 changes: 2 additions & 4 deletions Model/Boundary/IBoundaryCondition.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;

namespace Model{
namespace Model.Boundary{

public enum BoundaryDirection{
N, NE, E, SE , S, SW, W, NW
N, Ne, E, Se , S, Sw, W, Nw
}

public interface IBoundaryCondition
Expand Down
18 changes: 6 additions & 12 deletions Model/Boundary/PeriodicBoundary.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
using System;

namespace Model
namespace Model.Boundary
{


public class PeriodicBoundary : IBoundaryCondition
{
public string Name
{
get
{
return this.ToString();
}
}
public string Name => this.ToString();

public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDirection direction)
{
switch (direction)
{
case BoundaryDirection.N: return space.GetCell( space.GetXLength() - 1, y);
case BoundaryDirection.NE:
case BoundaryDirection.Ne:
{
if (y == space.GetYLength() - 1)
{
Expand All @@ -38,7 +32,7 @@ public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDire
}
}
case BoundaryDirection.E: return space.GetCell( x, 0);
case BoundaryDirection.SE:
case BoundaryDirection.Se:
{
if (x == space.GetXLength() - 1)
{
Expand All @@ -57,7 +51,7 @@ public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDire
}
}
case BoundaryDirection.S: return space.GetCell( 0, y);
case BoundaryDirection.SW:
case BoundaryDirection.Sw:
{
if (x == space.GetYLength() - 1)
{
Expand All @@ -76,7 +70,7 @@ public Cell GetBoundaryNeighbour(CelluralSpace space, int x, int y, BoundaryDire
}
}
case BoundaryDirection.W: return space.GetCell( x, space.GetYLength() - 1);
case BoundaryDirection.NW:
case BoundaryDirection.Nw:
{
if (y == 0)
{
Expand Down
9 changes: 2 additions & 7 deletions Model/Cell.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Drawing;
using Model.Microelements;

namespace Model{
public class Cell
{
public int? Phase
{
get{return MicroelementMembership?.Phase ?? null;}
private set{}
}
public int? Phase => MicroelementMembership?.Phase;
public Microelement MicroelementMembership { get; set; }

public Cell()
Expand Down
10 changes: 7 additions & 3 deletions Model/CellularAutomaton.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
using System;
using System.Collections.Generic;
using Model.Boundary;
using Model.Executors;
using Model.Microelements;
using Model.Neighbourhood;
using Model.Transition;


namespace Model{
Expand Down Expand Up @@ -53,8 +58,7 @@ public CellularAutomaton(
List<Inclusion> inclusions,
ITransitionRule transition,
INeighbourhood neighbourhood,
IBoundaryCondition boundary,
int step, ISimulationExecutor executor)
IBoundaryCondition boundary, ISimulationExecutor executor)
{
if (transition == null ||
neighbourhood == null ||
Expand Down Expand Up @@ -87,7 +91,7 @@ public void NextStep()
_executor.NextState(Space, _lastStepSpace, _transition, _neighbourhood);
}

public void PopulateSimulation(int grainsCount, int inclusionsCount, int minRadius, int maxRadius)
private void PopulateSimulation(int grainsCount, int inclusionsCount, int minRadius, int maxRadius)
{
Grains = _grainInitializer.Initialize(grainsCount);
_grainSeeder.Seed(Space, Grains);
Expand Down
17 changes: 7 additions & 10 deletions Model/CelluralSpace.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using Model.Microelements;

namespace Model{
public class CelluralSpace : IEnumerable<Cell>, ICloneable
{
public int Size{
get {return _space.GetLength(0); }
private set{}
}
public int Size => _space.GetLength(0);

private readonly Cell[,] _space;

Expand All @@ -23,9 +20,9 @@ public CelluralSpace(int size)
public CelluralSpace(Cell[,] cells)
{
_space = cells;
}
}

public void Initialize()
private void Initialize()
{
for (int i = 0; i < _space.GetLength(0); i++)
{
Expand Down Expand Up @@ -80,17 +77,17 @@ public CelluralSpace Clone() //copy membership reference
}

object ICloneable.Clone(){
return (object)Clone();
return Clone();
}

IEnumerator IEnumerable.GetEnumerator()
{
return (IEnumerator)GetEnumerator();
return GetEnumerator();
}

IEnumerator<Cell> IEnumerable<Cell>.GetEnumerator()
{
return (IEnumerator<Cell>)GetEnumerator();
return GetEnumerator();
}


Expand Down
4 changes: 0 additions & 4 deletions Model/CsvAutomatonFormatter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Text;

namespace Model{
Expand Down
28 changes: 13 additions & 15 deletions Model/CurvatureExecutor.cs → Model/Executors/CurvatureExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Model.Boundary;
using Model.Neighbourhood;
using Model.Transition;

namespace Model
namespace Model.Executors
{
public class CurvatureExecutor : ISimulationExecutor
{
public string Name
{
get { return ToString(); }
set { }
}

public string Name => ToString();


public int Step { get; set; }

public int Threshold { get; set; }

public int Step { get; private set; }

public CurvatureExecutor()
{
Expand All @@ -39,7 +37,6 @@ public void NextState(CelluralSpace space, CelluralSpace lastSpace, ITransitionR
for (int j = 0; j < space.GetYLength(); j++)
{
// TODO: refactor, injected arguments are not used !!
IBoundaryCondition boun = new AbsorbingBoundary();
INeighbourhood nei = new MooreNeighbourhood(new AbsorbingBoundary());
ITransitionRule rule = new RuleOne();
Cell[] neighbours = nei.GetNeighbours(lastSpace, i, j);
Expand Down Expand Up @@ -73,10 +70,11 @@ public void NextState(CelluralSpace space, CelluralSpace lastSpace, ITransitionR
continue;
}

nei = new FurtherMooreNeighbourhood(new AbsorbingBoundary());
rule = new RuleFour();
nei = new MooreNeighbourhood(new AbsorbingBoundary());
var ruleFour = new RuleFour();
ruleFour.Threshhold = Threshold;
neighbours = nei.GetNeighbours(lastSpace, i, j);
element = rule.NextState(space.GetCell(i, j), neighbours);
element = ruleFour.NextState(space.GetCell(i, j), neighbours);
space.SetCellMembership(element, i, j);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using Model.Neighbourhood;
using Model.Transition;

namespace Model
namespace Model.Executors
{
public interface ISimulationExecutor
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using Model.Neighbourhood;
using Model.Transition;

namespace Model{
namespace Model.Executors{
public class SimulationExecutor : ISimulationExecutor
{
public string Name
{
get { return ToString(); }
}
public string Name => ToString();

public int Step{get; private set;}
private int Step{get; set;}

public SimulationExecutor(){
}
Expand Down
10 changes: 4 additions & 6 deletions Model/Microelements/Grain.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using System;
using System.Collections.Generic;
using System.Drawing;

namespace Model{
namespace Model.Microelements{

public class Grain : Microelement
{
public override int? Phase{get; set;}
public override Color Color {get; set;}
public override int Id{get; set;}
public sealed override int? Phase{get; set;}
public sealed override Color Color {get; set;}
public sealed override int Id{get; set;}

public Grain(int id, int phase, Color color)
{
Expand Down
3 changes: 1 addition & 2 deletions Model/Microelements/GrainInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Model
namespace Model.Microelements
{
public class GrainInitializer
{
Expand Down
4 changes: 1 addition & 3 deletions Model/Microelements/GrainSeeder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Model
namespace Model.Microelements
{
public class GrainSeeder
{
Expand Down
15 changes: 6 additions & 9 deletions Model/Microelements/Inclusion.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing;

namespace Model
namespace Model.Microelements
{
public class Inclusion : Microelement
{
public int? Radius{get; set;}
public override int? Phase {get; set;}
public int? Radius{get; }
public sealed override int? Phase {get; set;}

public override Color Color {get; set;}
public override int Id{get; set;}
public sealed override Color Color {get; set;}
public sealed override int Id{get; set;}

public Inclusion(int id, int phase, int radius, Color color)
{
Expand Down
12 changes: 6 additions & 6 deletions Model/Microelements/InclusionExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Model.Transition;
using Model.Boundary;
using Model.Neighbourhood;
using Model.Transition;

namespace Model
namespace Model.Microelements
{
class InclusionExecutor
{
private IBoundaryCondition _boundary;
private ITransitionRule _transition;
private INeighbourhood _neighbourhood;
private readonly INeighbourhood _neighbourhood;

public InclusionExecutor(IBoundaryCondition boundary)
{
_boundary = boundary;
_neighbourhood = new PentagonNeighbourhood(_boundary);
_neighbourhood = new PentagonNeighbourhood(boundary);
}

public void Grow(CelluralSpace space, int maxRadius)
Expand Down
3 changes: 1 addition & 2 deletions Model/Microelements/InclusionInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Model
namespace Model.Microelements
{
public class InclusionInitializer
{
Expand Down
Loading

0 comments on commit 4077b7c

Please sign in to comment.