public IBoundedPlaneSurface <F> Slice <F>(Surfacize <T, F> SurfacizeFunc, F Default, Axis Axis, int Level) where F : IEquatable <F> { return(new QuadtreeSurface <F>( Octree.GetSlice <T, F>(SurfacizeFunc, this, Axis, Level), Default, Axis, Level)); }
public OctreeSurface(Octree <T> Source, Surfacize <T, F> SurfacizeFunc, T Default, F Excluded) { this._Source = Source; this._SurfacizeFunc = SurfacizeFunc; this._Default = Default; this._Excluded = Excluded; }
public StratifiedRenderer(IBoundedShape <T> Source, Surfacize <T, Material> SurfacizeFunc, T Default) { this._Default = Default; this._Source = Source; this._SurfacizeFunc = SurfacizeFunc; this._OrientedRenderers = new _OrientedRenderer[3]; }
/// <summary> /// Produces a surface using the specified source shape and a surfacization function. /// </summary> public static ISurface <F> Form <T, F>(IInfiniteShape <T> Source, Surfacize <T, F> Surfacization) where F : IEquatable <F> { ISurfaceFormableShape <T> sfs = Source.Extend <ISurfaceFormableShape <T> >(); if (sfs != null) { return(sfs.FormSurface <F>(Surfacization)); } return(new FormSurface <T, F>() { Source = Source, Surfacization = Surfacization }); }
/// <summary> /// Gets the renderer between this and another chunk. /// </summary> public OrientedPartRenderer GetInteriorSide(Axis Direction, Chunk Side, Axis SliceDirection, Octree <byte> Data) { int i = Direction == Axis.X ? 0 : 1; if (SliceDirection == Direction) { if (this.InteriorSides[i, 1] != null) { return(this.InteriorSides[i, 1]); } else { return(GetInteriorSide(Direction, Side, Axis.Z, Data)); } } Surfacize <byte, Material> mb = this.Scheme.MaterialBorder; Func <QuadtreeSurface <Material> > createsurface = delegate { Octree <byte> lower = Data; Octree <byte> higher = Side._DataOctree; return(new QuadtreeSurface <Material>( Octree.GetSurface <byte, Material>(mb, lower, higher, Direction), Material.Default, Direction, ChunkSize - 1)); }; if (SliceDirection == Axis.Z) { if (this.InteriorSides[i, 0] == null) { this.InteriorSides[i, 0] = new OrientedPartRenderer(createsurface(), Axis.Z, ChunkSize); } return(this.InteriorSides[i, 0]); } else { if (this.InteriorSides[i, 1] == null) { this.InteriorSides[i, 1] = new OrientedPartRenderer(createsurface(), (Axis)(((int)Direction + 1) % 2), ChunkSize); } return(this.InteriorSides[i, 1]); } }
/// <summary> /// Gets the renderer for a side of the chunk. /// </summary> public OrientedPartRenderer GetSide(Axis MainDirection, Polarity Polarity, Axis SliceDirection, Octree <byte> Data) { if (MainDirection == Axis.Z) { if (Polarity == Polarity.Positive) { if (SliceDirection == Axis.Z) { if (this.Sides[4, 1] != null) { return(this.Sides[4, 1]); } return(this.GetSide(Axis.Z, Polarity.Positive, Axis.X, Data)); } Surfacize <byte, Material> mb = this.Scheme.MaterialBorder; Func <QuadtreeSurface <Material> > createsurface = delegate { Octree <byte> lower = Data; Octree <byte> higher = Octree <byte> .Solid(MinecraftBlock.DefaultType, ChunkDepth); return(new QuadtreeSurface <Material>( Octree.GetSurface <byte, Material>(mb, lower, higher, Axis.Z), Material.Default, Axis.Z, ChunkSize - 1)); }; if (SliceDirection == Axis.X) { if (this.Sides[4, 0] == null) { this.Sides[4, 0] = new OrientedPartRenderer(createsurface(), Axis.X, ChunkSize); } return(this.Sides[4, 0]); } else { if (this.Sides[4, 1] == null) { this.Sides[4, 1] = new OrientedPartRenderer(createsurface(), Axis.Y, ChunkSize); } return(this.Sides[4, 1]); } } } else { int mi = 0; if (MainDirection == Axis.Y) { mi += 1; } if (Polarity == Polarity.Negative) { mi += 2; } if (SliceDirection == MainDirection) { if (this.Sides[mi, 1] != null) { return(this.Sides[mi, 1]); } else { return(this.GetSide(MainDirection, Polarity, Axis.Z, Data)); } } Surfacize <byte, Material> mb = this.Scheme.MaterialBorder; Func <QuadtreeSurface <Material> > createsurface = delegate { Octree <byte> lower = Octree <byte> .Solid(MinecraftBlock.DefaultType, ChunkDepth); Octree <byte> higher = Data; if (Polarity == Polarity.Positive) { Octree <byte> temp = lower; lower = higher; higher = temp; } return(new QuadtreeSurface <Material>( Octree.GetSurface <byte, Material>(mb, lower, higher, MainDirection), Material.Default, MainDirection, Polarity == Polarity.Positive ? ChunkSize - 1 : -1)); }; if (SliceDirection == Axis.Z) { if (this.Sides[mi, 0] == null) { this.Sides[mi, 0] = new OrientedPartRenderer(createsurface(), Axis.Z, ChunkSize); } return(this.Sides[mi, 0]); } else { if (this.Sides[mi, 1] == null) { this.Sides[mi, 1] = new OrientedPartRenderer(createsurface(), (Axis)(((int)MainDirection + 1) % 2), ChunkSize); } return(this.Sides[mi, 1]); } } return(null); }
public OctreeInteriorSurface(Octree <T> Source, Surfacize <T, F> SurfacizeFunc, F Excluded) { this._SurfacizeFunc = SurfacizeFunc; this._Excluded = Excluded; this._Source = Source; }
public IEnumerableSurface <F> EnumerateInteriorBorders <F>(Surfacize <T, F> SurfacizeFunc, F Excluded) where F : IEquatable <F> { return(new OctreeInteriorSurface <T, F>(this, SurfacizeFunc, Excluded)); }
public IEnumerableSurface <F> EnumerateBorders <F>(Surfacize <T, F> SurfacizeFunc, T Default, F Excluded) where F : IEquatable <F> { return(new OctreeSurface <T, F>(this, SurfacizeFunc, Default, Excluded)); }
public IEnumerableSurface <F> EnumerateBorders <F>(Surfacize <T, F> SurfacizeFunc, F Excluded) where F : IEquatable <F> { Axis[] axies = new Axis[] { Axis.X, Axis.Y, Axis.Z }; // Check to insure noninfinince. foreach (Axis a in axies) { if (!SurfacizeFunc(this.Default, this.Default, a).Equals(Excluded)) { return(null); } } // Could save some time if the source already knows how to do this. IBoundedEnumerableSurfaceShape <T> bess = this.Source as IBoundedEnumerableSurfaceShape <T>; if (bess != null) { // Hooray, less work for us. return(bess.EnumerateBorders <F>(SurfacizeFunc, this.Default, Excluded)); } // Check main area List <Border <F> > borders = new List <Border <F> >(); Vector <int> sourcebounds = this.Source.Bound; for (int x = 0; x < sourcebounds.X; x++) { for (int y = 0; y < sourcebounds.Y; y++) { for (int z = 0; z < sourcebounds.Z; z++) { Vector <int> pos = new Vector <int>(x, y, z); foreach (Axis a in axies) { Vector <int> norm = new Vector <int>(1, 0, 0).AxisUnorder(a); Vector <int> upperpos = Vector.Add(pos, norm); T low = this.Source.Lookup(pos); T high = (upperpos.X >= sourcebounds.X || upperpos.Y >= sourcebounds.Y || upperpos.Z >= sourcebounds.Z) ? this.Default : this.Source.Lookup(upperpos); F val = SurfacizeFunc(low, high, a); if (!val.Equals(Default)) { borders.Add(new Border <F>() { Position = pos, Direction = a, Value = val }); } } } } } // Check negative area. foreach (Axis a in axies) { Vector <int> unorderedbounds = sourcebounds.AxisUnorder(a); for (int y = 0; y < unorderedbounds.Y; y++) { for (int z = 0; z < unorderedbounds.Z; z++) { Vector <int> posneg = new Vector <int>(0, y, z).AxisUnorder(a); T highneg = this.Source.Lookup(posneg); F val = SurfacizeFunc(this.Default, highneg, a); if (val != null) { borders.Add(new Border <F>() { Position = new Vector <int>(-1, y, z).AxisUnorder(a), Direction = a, Value = val }); } } } } return(new FiniteBorderSurface <F>(borders, Excluded)); }
public EnumerableInteriorSurface(IBoundedShape <T> Source, Surfacize <T, F> SurfacizeFunc, F Excluded) { this._Source = Source; this._SurfacizeFunc = SurfacizeFunc; this._Excluded = Excluded; }
/// <summary> /// Enumerates the interior surfaces in a bounded shape. /// </summary> public static IEnumerableSurface <F> EnumerateInterior <T, F>(IBoundedShape <T> Source, Surfacize <T, F> SurfacizeFunc, F Excluded) where F : IEquatable <F> { IEnumerableInteriorSurfaceShape <T> eiss = Source.Extend <IEnumerableInteriorSurfaceShape <T> >(); if (eiss != null) { return(eiss.EnumerateInteriorBorders(SurfacizeFunc, Excluded)); } return(new EnumerableInteriorSurface <T, F>(Source, SurfacizeFunc, Excluded)); }
/// <summary> /// "Slices" the specified shape, returning a plane of the borders on the specified axis /// and level. /// </summary> public static IBoundedPlaneSurface <F> Slice <T, F>(IBoundedShape <T> Source, Axis Axis, int Level, Surfacize <T, F> SurfacizeFunc, F Excluded) where F : IEquatable <F> { IBoundedSliceableSurfaceShape <T> bsss = Source.Extend <IBoundedSliceableSurfaceShape <T> >(); if (bsss != null) { return(bsss.Slice(SurfacizeFunc, Excluded, Axis, Level)); } // Too sleepy to do this right now... throw new NotImplementedException(); }