Example #1
0
 public bool CanContain(TrixelEmplacement trixel)
 {
   if ((double) trixel.X < (double) this.Size.X * 16.0 && (double) trixel.Y < (double) this.Size.Y * 16.0 && ((double) trixel.Z < (double) this.Size.Z * 16.0 && trixel.X >= 0) && trixel.Y >= 0)
     return trixel.Z >= 0;
   else
     return false;
 }
Example #2
0
 public bool TrixelExists(TrixelEmplacement trixelIdentifier)
 {
   if (!this.MissingTrixels.Empty)
     return !this.MissingTrixels.IsFilled(trixelIdentifier);
   else
     return true;
 }
Example #3
0
            internal bool TryAdd(TrixelEmplacement trixel)
            {
                bool flag = false;

                if (this.Boxes.Count > 0)
                {
                    foreach (TrixelCluster.Box box in Enumerable.ToArray <TrixelCluster.Box>(Enumerable.Where <TrixelCluster.Box>((IEnumerable <TrixelCluster.Box>) this.Boxes, (Func <TrixelCluster.Box, bool>)(b => b.IsNeighbor(trixel)))))
                    {
                        flag = true;
                        this.Dismantle(box);
                        this.Boxes.Remove(box);
                    }
                }
                if (!flag)
                {
                    foreach (TrixelEmplacement trixelEmplacement in this.Trixels)
                    {
                        if (trixelEmplacement.IsNeighbor(trixel))
                        {
                            flag = true;
                            break;
                        }
                    }
                }
                if (flag)
                {
                    this.Trixels.Add(trixel);
                }
                TrixelCluster.Chunk chunk = this;
                int num = chunk.Dirty | flag ? 1 : 0;

                chunk.Dirty = num != 0;
                return(flag);
            }
Example #4
0
 public bool IsBorderTrixelFace(TrixelEmplacement traversed)
 {
   if (this.CanContain(traversed))
     return !this.TrixelExists(traversed);
   else
     return true;
 }
Example #5
0
        private TrixelEmplacement FindNearestTrixel(TrixelEmplacement center, ICollection <TrixelEmplacement> subSurface)
        {
            TrixelEmplacement trixelEmplacement = new TrixelEmplacement(center);
            int num1 = 1;
            int num2 = 0;
            int num3 = 1;
            int num4 = 0;
            int num5 = 1;
            int num6 = -1;

            do
            {
                if (num3 > 0)
                {
                    trixelEmplacement.Position += this.Tangent * (float)num5;
                    if (--num3 == 0)
                    {
                        num6 *= -1;
                        num4  = ++num2;
                    }
                }
                else if (num4 > 0)
                {
                    trixelEmplacement.Position += this.Bitangent * (float)num6;
                    if (--num4 == 0)
                    {
                        num5 *= -1;
                        num3  = ++num1;
                    }
                }
            }while (!subSurface.Contains(trixelEmplacement));
            return(trixelEmplacement);
        }
Example #6
0
            private static List <TrixelEmplacement> FindBiggestBox(TrixelEmplacement center, ICollection <TrixelEmplacement> subChunk, out TrixelCluster.Box box)
            {
                List <TrixelEmplacement> boxTrixels = new List <TrixelEmplacement>()
                {
                    center
                };

                box = new TrixelCluster.Box()
                {
                    Start = center,
                    End   = center
                };
                int trixelsToRollback;

                do
                {
                    box.Start        -= Vector3.One;
                    box.End          += Vector3.One;
                    trixelsToRollback = 0;
                }while (TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, Vector3.UnitZ, false, box, ref trixelsToRollback) && TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, -Vector3.UnitZ, false, box, ref trixelsToRollback) && (TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, Vector3.UnitX, true, box, ref trixelsToRollback) && TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, -Vector3.UnitX, true, box, ref trixelsToRollback)) && (TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, Vector3.UnitY, true, box, ref trixelsToRollback) && TrixelCluster.Chunk.TestFace(subChunk, (ICollection <TrixelEmplacement>)boxTrixels, -Vector3.UnitY, true, box, ref trixelsToRollback)));
                boxTrixels.RemoveRange(boxTrixels.Count - trixelsToRollback, trixelsToRollback);
                box.Start += Vector3.One;
                box.End   -= Vector3.One;
                if (boxTrixels.Count < subChunk.Count)
                {
                    foreach (Vector3 normal in TrixelCluster.Directions)
                    {
                        TrixelCluster.Chunk.ExpandSide(box, subChunk, boxTrixels, normal);
                    }
                }
                box.End += Vector3.One;
                return(boxTrixels);
            }
Example #7
0
            private static bool TestFace(ICollection <TrixelEmplacement> subChunk, ICollection <TrixelEmplacement> boxTrixels, Vector3 normal, bool partial, TrixelCluster.Box box, ref int trixelsToRollback)
            {
                Vector3 vector3_1 = FezMath.Abs(normal);
                Vector3 vector2_1 = (double)normal.Z != 0.0 ? Vector3.UnitX : Vector3.UnitZ;
                Vector3 vector2_2 = (double)normal.Z != 0.0 ? Vector3.UnitY : new Vector3(1f, 1f, 0.0f) - vector3_1;
                Vector3 vector3_2 = ((double)Vector3.Dot(normal, Vector3.One) > 0.0 ? box.End.Position : box.Start.Position) * vector3_1;
                int     num1      = (int)Vector3.Dot(box.Start.Position, vector2_1);
                int     num2      = (int)Vector3.Dot(box.End.Position, vector2_1);
                int     num3      = (int)Vector3.Dot(box.Start.Position, vector2_2);
                int     num4      = (int)Vector3.Dot(box.End.Position, vector2_2);

                if (partial)
                {
                    ++num1;
                    --num2;
                }
                for (int index1 = num1; index1 <= num2; ++index1)
                {
                    for (int index2 = num3; index2 <= num4; ++index2)
                    {
                        TrixelEmplacement trixelEmplacement = new TrixelEmplacement((float)index1 * vector2_1 + (float)index2 * vector2_2 + vector3_2);
                        if (!subChunk.Contains(trixelEmplacement))
                        {
                            return(false);
                        }
                        ++trixelsToRollback;
                        boxTrixels.Add(trixelEmplacement);
                    }
                }
                return(true);
            }
Example #8
0
 public TrixelSurface(FaceOrientation orientation, TrixelEmplacement firstTrixel)
 {
     this.RectangularParts = new List <RectangularTrixelSurfacePart>();
     this.Orientation      = orientation;
     this.Initialize();
     this.Trixels.Add(firstTrixel);
     this.MarkAsDirty();
     this.InitializeDepth();
 }
Example #9
0
 public TrixelSurface(FaceOrientation orientation, TrixelEmplacement firstTrixel)
 {
   this.RectangularParts = new List<RectangularTrixelSurfacePart>();
   this.Orientation = orientation;
   this.Initialize();
   this.Trixels.Add(firstTrixel);
   this.MarkAsDirty();
   this.InitializeDepth();
 }
Example #10
0
 public bool CanContain(TrixelEmplacement trixel)
 {
     if ((double)trixel.X < (double)this.Size.X * 16.0 && (double)trixel.Y < (double)this.Size.Y * 16.0 && ((double)trixel.Z < (double)this.Size.Z * 16.0 && trixel.X >= 0) && trixel.Y >= 0)
     {
         return(trixel.Z >= 0);
     }
     else
     {
         return(false);
     }
 }
Example #11
0
 public bool IsBorderTrixelFace(TrixelEmplacement traversed)
 {
     if (this.CanContain(traversed))
     {
         return(!this.TrixelExists(traversed));
     }
     else
     {
         return(true);
     }
 }
Example #12
0
 public bool IsBorderTrixelFace(TrixelEmplacement traversed)
 {
     if (Trile.TrixelInRange(traversed))
     {
         return(!this.TrixelExists(traversed));
     }
     else
     {
         return(true);
     }
 }
Example #13
0
 internal bool Contains(TrixelEmplacement trixel)
 {
     for (int index = 0; index < this.Boxes.Count; ++index)
     {
         if (this.Boxes[index].Contains(trixel))
         {
             return(true);
         }
     }
     return(this.Trixels.Contains(trixel));
 }
Example #14
0
 public bool TrixelExists(TrixelEmplacement trixelIdentifier)
 {
     if (!this.MissingTrixels.Empty)
     {
         return(!this.MissingTrixels.IsFilled(trixelIdentifier));
     }
     else
     {
         return(true);
     }
 }
Example #15
0
 internal bool IsNeighbor(TrixelEmplacement trixel)
 {
     if (Enumerable.Any <TrixelCluster.Box>((IEnumerable <TrixelCluster.Box>) this.Boxes, (Func <TrixelCluster.Box, bool>)(b => b.IsNeighbor(trixel))))
     {
         return(true);
     }
     else
     {
         return(Enumerable.Any <TrixelEmplacement>((IEnumerable <TrixelEmplacement>) this.Trixels, (Func <TrixelEmplacement, bool>)(t => t.IsNeighbor(trixel))));
     }
 }
Example #16
0
 public static bool TrixelInRange(TrixelEmplacement trixel)
 {
     if (trixel.X < 16 && trixel.Y < 16 && (trixel.Z < 16 && trixel.X >= 0) && trixel.Y >= 0)
     {
         return(trixel.Z >= 0);
     }
     else
     {
         return(false);
     }
 }
Example #17
0
 internal bool Contains(TrixelEmplacement trixel)
 {
     if (trixel.X >= this.Start.X && trixel.Y >= this.Start.Y && (trixel.Z >= this.Start.Z && trixel.X < this.End.X) && trixel.Y < this.End.Y)
     {
         return(trixel.Z < this.End.Z);
     }
     else
     {
         return(false);
     }
 }
Example #18
0
        private void ExpandSide(ref Rectangle rectangle, TrixelEmplacement center, ICollection <TrixelEmplacement> subSurface, List <TrixelEmplacement> rectangleTrixels, bool useTangent, int sign)
        {
            TrixelEmplacement other1 = center + (float)rectangle.X * this.Tangent + (float)rectangle.Y * this.Bitangent;

            if (sign > 0)
            {
                other1 += useTangent ? this.Tangent * (float)(rectangle.Width - 1) : this.Bitangent * (float)(rectangle.Height - 1);
            }
            int  num = useTangent ? rectangle.Height : rectangle.Width;
            bool flag;

            do
            {
                other1.Position += (useTangent ? this.Tangent : this.Bitangent) * (float)sign;
                TrixelEmplacement other2 = new TrixelEmplacement(other1);
                int count = 0;
                for (flag = subSurface.Contains(other2); flag; flag = subSurface.Contains(other2))
                {
                    rectangleTrixels.Add(new TrixelEmplacement(other2));
                    if (++count != num)
                    {
                        other2.Position += useTangent ? this.Bitangent : this.Tangent;
                    }
                    else
                    {
                        break;
                    }
                }
                if (flag)
                {
                    if (useTangent)
                    {
                        if (sign < 0)
                        {
                            --rectangle.X;
                        }
                        ++rectangle.Width;
                    }
                    else
                    {
                        if (sign < 0)
                        {
                            --rectangle.Y;
                        }
                        ++rectangle.Height;
                    }
                }
                else if (count > 0)
                {
                    rectangleTrixels.RemoveRange(rectangleTrixels.Count - count, count);
                }
            }while (flag);
        }
Example #19
0
        public void RebuildParts()
        {
            this.Dirty = false;
            this.RectangularParts.Clear();
            Queue <HashSet <TrixelEmplacement> > queue = new Queue <HashSet <TrixelEmplacement> >();

            if (this.Trixels.Count > 0)
            {
                queue.Enqueue(new HashSet <TrixelEmplacement>((IEnumerable <TrixelEmplacement>) this.Trixels));
            }
            while (queue.Count > 0)
            {
                HashSet <TrixelEmplacement> hashSet1 = queue.Dequeue();
                TrixelEmplacement           center   = new TrixelEmplacement();
                foreach (TrixelEmplacement trixelEmplacement in hashSet1)
                {
                    center.Position += trixelEmplacement.Position;
                }
                center.Position = FezMath.Floor(center.Position / (float)hashSet1.Count);
                if ((double)Vector3.Dot(center.Position, this.normal) != (double)this.depth)
                {
                    center.Position = center.Position * (Vector3.One - FezMath.Abs(this.normal)) + (float)this.depth * this.normal;
                }
                if (!hashSet1.Contains(center))
                {
                    center = this.FindNearestTrixel(center, (ICollection <TrixelEmplacement>)hashSet1);
                }
                Rectangle rectangle;
                List <TrixelEmplacement> biggestRectangle = this.FindBiggestRectangle(center, (ICollection <TrixelEmplacement>)hashSet1, out rectangle);
                rectangle.Offset((int)Vector3.Dot(center.Position, this.Tangent), (int)Vector3.Dot(center.Position, this.Bitangent));
                this.RectangularParts.Add(new RectangularTrixelSurfacePart()
                {
                    Orientation   = this.Orientation,
                    Start         = new TrixelEmplacement((float)rectangle.X * this.Tangent + (float)rectangle.Y * this.Bitangent + (float)this.depth * this.normal),
                    TangentSize   = rectangle.Width,
                    BitangentSize = rectangle.Height
                });
                hashSet1.ExceptWith((IEnumerable <TrixelEmplacement>)biggestRectangle);
                while (hashSet1.Count > 0)
                {
                    HashSet <TrixelEmplacement> hashSet2 = this.TraverseSurface(Enumerable.First <TrixelEmplacement>((IEnumerable <TrixelEmplacement>)hashSet1), (ICollection <TrixelEmplacement>)hashSet1);
                    queue.Enqueue(hashSet2);
                    if (hashSet1.Count == hashSet2.Count)
                    {
                        hashSet1.Clear();
                    }
                    else
                    {
                        hashSet1.ExceptWith((IEnumerable <TrixelEmplacement>)hashSet2);
                    }
                }
            }
        }
Example #20
0
        private List <TrixelEmplacement> FindBiggestRectangle(TrixelEmplacement center, ICollection <TrixelEmplacement> subSurface, out Rectangle rectangle)
        {
            List <TrixelEmplacement> rectangleTrixels = new List <TrixelEmplacement>();
            TrixelEmplacement        other            = new TrixelEmplacement(center);
            int num1 = 1;
            int num2 = 0;
            int num3 = 1;
            int num4 = 0;
            int num5 = 1;
            int num6 = -1;

            do
            {
                rectangleTrixels.Add(new TrixelEmplacement(other));
                if (num3 > 0)
                {
                    other.Position += this.Tangent * (float)num5;
                    if (--num3 == 0)
                    {
                        num6 *= -1;
                        num4  = ++num2;
                    }
                }
                else if (num4 > 0)
                {
                    other.Position += this.Bitangent * (float)num6;
                    if (--num4 == 0)
                    {
                        num5 *= -1;
                        num3  = ++num1;
                    }
                }
            }while (subSurface.Contains(other));
            int num7 = TrixelSurface.ClampToRectangleSpiral(rectangleTrixels.Count);

            if (num7 != rectangleTrixels.Count)
            {
                rectangleTrixels.RemoveRange(num7, rectangleTrixels.Count - num7);
            }
            rectangle = TrixelSurface.GetRectangleSpiralLimits(num7);
            if (rectangleTrixels.Count < subSurface.Count)
            {
                this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, true, 1);
                this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, true, -1);
                this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, false, 1);
                this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, false, -1);
            }
            return(rectangleTrixels);
        }
Example #21
0
 public bool AnyRectangleContains(TrixelEmplacement trixel)
 {
     foreach (RectangularTrixelSurfacePart trixelSurfacePart in this.RectangularParts)
     {
         Vector3 vector1 = trixel.Position - trixelSurfacePart.Start.Position;
         if ((double)vector1.X >= 0.0 && (double)vector1.Y >= 0.0 && (double)vector1.Z >= 0.0)
         {
             int num1 = (int)Vector3.Dot(vector1, this.Tangent);
             int num2 = (int)Vector3.Dot(vector1, this.Bitangent);
             if (num1 < trixelSurfacePart.TangentSize && num2 < trixelSurfacePart.BitangentSize)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Example #22
0
            internal bool TryRemove(TrixelEmplacement trixel)
            {
                bool flag1 = false;

                foreach (TrixelCluster.Box box in Enumerable.Where <TrixelCluster.Box>((IEnumerable <TrixelCluster.Box>) this.Boxes, (Func <TrixelCluster.Box, bool>)(b =>
                {
                    if (!b.Contains(trixel))
                    {
                        return(b.IsNeighbor(trixel));
                    }
                    else
                    {
                        return(true);
                    }
                })))
                {
                    flag1 = true;
                    this.Dismantle(box);
                }
                if (flag1)
                {
                    this.Boxes.RemoveAll((Predicate <TrixelCluster.Box>)(b =>
                    {
                        if (!b.Contains(trixel))
                        {
                            return(b.IsNeighbor(trixel));
                        }
                        else
                        {
                            return(true);
                        }
                    }));
                }
                bool flag2 = flag1 | this.Trixels.Remove(trixel);

                TrixelCluster.Chunk chunk = this;
                int num = chunk.Dirty | flag2 ? 1 : 0;

                chunk.Dirty = num != 0;
                return(flag2);
            }
Example #23
0
            internal void ConsolidateTrixels()
            {
                if (this.Trixels.Count <= 1)
                {
                    return;
                }
                Stack <HashSet <TrixelEmplacement> > stack = new Stack <HashSet <TrixelEmplacement> >();

                stack.Push(new HashSet <TrixelEmplacement>((IEnumerable <TrixelEmplacement>) this.Trixels));
                while (stack.Count > 0)
                {
                    HashSet <TrixelEmplacement> hashSet1 = stack.Pop();
                    TrixelEmplacement           center   = new TrixelEmplacement();
                    foreach (TrixelEmplacement trixelEmplacement in hashSet1)
                    {
                        center.Offset(trixelEmplacement.X, trixelEmplacement.Y, trixelEmplacement.Z);
                    }
                    center.Position = FezMath.Floor(FezMath.Round(center.Position / (float)hashSet1.Count, 3));
                    if (!hashSet1.Contains(center))
                    {
                        center = Enumerable.First <TrixelEmplacement>((IEnumerable <TrixelEmplacement>)hashSet1);
                    }
                    TrixelCluster.Box        box;
                    List <TrixelEmplacement> biggestBox = TrixelCluster.Chunk.FindBiggestBox(center, (ICollection <TrixelEmplacement>)hashSet1, out box);
                    this.Boxes.Add(box);
                    hashSet1.ExceptWith((IEnumerable <TrixelEmplacement>)biggestBox);
                    this.Trixels.ExceptWith((IEnumerable <TrixelEmplacement>)biggestBox);
                    while (hashSet1.Count > 1)
                    {
                        HashSet <TrixelEmplacement> hashSet2 = TrixelCluster.Chunk.VisitChunk(Enumerable.First <TrixelEmplacement>((IEnumerable <TrixelEmplacement>)hashSet1), (ICollection <TrixelEmplacement>)hashSet1);
                        stack.Push(hashSet2);
                        hashSet1.ExceptWith((IEnumerable <TrixelEmplacement>)hashSet2);
                    }
                }
                this.Dirty = false;
            }
Example #24
0
 public TrixelEmplacement(TrixelEmplacement other)
 {
     X = other.X;
     Y = other.Y;
     Z = other.Z;
 }
Example #25
0
 public static bool TrixelInRange(TrixelEmplacement trixel)
 {
   if (trixel.X < 16 && trixel.Y < 16 && (trixel.Z < 16 && trixel.X >= 0) && trixel.Y >= 0)
     return trixel.Z >= 0;
   else
     return false;
 }
Example #26
0
 public bool IsBorderTrixelFace(TrixelEmplacement id, FaceOrientation face)
 {
   return this.IsBorderTrixelFace(id.GetTraversal(face));
 }
Example #27
0
 public TrixelFace(TrixelEmplacement id, FaceOrientation face)
 {
     this.Id   = id;
     this.Face = face;
 }
Example #28
0
            private static HashSet <TrixelEmplacement> VisitChunk(TrixelEmplacement origin, ICollection <TrixelEmplacement> subChunk)
            {
                HashSet <TrixelEmplacement> hashSet = new HashSet <TrixelEmplacement>()
                {
                    origin
                };
                Queue <TrixelCluster.Chunk.TrixelToVisit> queue = new Queue <TrixelCluster.Chunk.TrixelToVisit>();

                queue.Enqueue(new TrixelCluster.Chunk.TrixelToVisit()
                {
                    Trixel = origin
                });
                while (queue.Count != 0)
                {
                    TrixelCluster.Chunk.TrixelToVisit toTraverse = queue.Dequeue();
                    TrixelEmplacement trixelEmplacement1         = toTraverse.Trixel;
                    using (IEnumerator <Vector3> enumerator = Enumerable.Where <Vector3>((IEnumerable <Vector3>)TrixelCluster.Directions, (Func <Vector3, bool>)(x =>
                    {
                        if (toTraverse.Except.HasValue)
                        {
                            return(toTraverse.Except.Value != x);
                        }
                        else
                        {
                            return(true);
                        }
                    })).GetEnumerator())
                    {
label_8:
                        while (enumerator.MoveNext())
                        {
                            Vector3           current            = enumerator.Current;
                            TrixelEmplacement trixelEmplacement2 = trixelEmplacement1 + current;
                            while (true)
                            {
                                if (!hashSet.Contains(trixelEmplacement2) && subChunk.Contains(trixelEmplacement2))
                                {
                                    hashSet.Add(trixelEmplacement2);
                                    if (hashSet.Count != subChunk.Count)
                                    {
                                        queue.Enqueue(new TrixelCluster.Chunk.TrixelToVisit()
                                        {
                                            Trixel = trixelEmplacement2,
                                            Except = new Vector3?(current)
                                        });
                                        trixelEmplacement2 += current;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                else
                                {
                                    goto label_8;
                                }
                            }
                            return(hashSet);
                        }
                    }
                }
                return(hashSet);
            }
Example #29
0
 private TrixelEmplacement FindNearestTrixel(TrixelEmplacement center, ICollection<TrixelEmplacement> subSurface)
 {
   TrixelEmplacement trixelEmplacement = new TrixelEmplacement(center);
   int num1 = 1;
   int num2 = 0;
   int num3 = 1;
   int num4 = 0;
   int num5 = 1;
   int num6 = -1;
   do
   {
     if (num3 > 0)
     {
       trixelEmplacement.Position += this.Tangent * (float) num5;
       if (--num3 == 0)
       {
         num6 *= -1;
         num4 = ++num2;
       }
     }
     else if (num4 > 0)
     {
       trixelEmplacement.Position += this.Bitangent * (float) num6;
       if (--num4 == 0)
       {
         num5 *= -1;
         num3 = ++num1;
       }
     }
   }
   while (!subSurface.Contains(trixelEmplacement));
   return trixelEmplacement;
 }
Example #30
0
 private void ExpandSide(ref Rectangle rectangle, TrixelEmplacement center, ICollection<TrixelEmplacement> subSurface, List<TrixelEmplacement> rectangleTrixels, bool useTangent, int sign)
 {
   TrixelEmplacement other1 = center + (float) rectangle.X * this.Tangent + (float) rectangle.Y * this.Bitangent;
   if (sign > 0)
     other1 += useTangent ? this.Tangent * (float) (rectangle.Width - 1) : this.Bitangent * (float) (rectangle.Height - 1);
   int num = useTangent ? rectangle.Height : rectangle.Width;
   bool flag;
   do
   {
     other1.Position += (useTangent ? this.Tangent : this.Bitangent) * (float) sign;
     TrixelEmplacement other2 = new TrixelEmplacement(other1);
     int count = 0;
     for (flag = subSurface.Contains(other2); flag; flag = subSurface.Contains(other2))
     {
       rectangleTrixels.Add(new TrixelEmplacement(other2));
       if (++count != num)
         other2.Position += useTangent ? this.Bitangent : this.Tangent;
       else
         break;
     }
     if (flag)
     {
       if (useTangent)
       {
         if (sign < 0)
           --rectangle.X;
         ++rectangle.Width;
       }
       else
       {
         if (sign < 0)
           --rectangle.Y;
         ++rectangle.Height;
       }
     }
     else if (count > 0)
       rectangleTrixels.RemoveRange(rectangleTrixels.Count - count, count);
   }
   while (flag);
 }
Example #31
0
 private List<TrixelEmplacement> FindBiggestRectangle(TrixelEmplacement center, ICollection<TrixelEmplacement> subSurface, out Rectangle rectangle)
 {
   List<TrixelEmplacement> rectangleTrixels = new List<TrixelEmplacement>();
   TrixelEmplacement other = new TrixelEmplacement(center);
   int num1 = 1;
   int num2 = 0;
   int num3 = 1;
   int num4 = 0;
   int num5 = 1;
   int num6 = -1;
   do
   {
     rectangleTrixels.Add(new TrixelEmplacement(other));
     if (num3 > 0)
     {
       other.Position += this.Tangent * (float) num5;
       if (--num3 == 0)
       {
         num6 *= -1;
         num4 = ++num2;
       }
     }
     else if (num4 > 0)
     {
       other.Position += this.Bitangent * (float) num6;
       if (--num4 == 0)
       {
         num5 *= -1;
         num3 = ++num1;
       }
     }
   }
   while (subSurface.Contains(other));
   int num7 = TrixelSurface.ClampToRectangleSpiral(rectangleTrixels.Count);
   if (num7 != rectangleTrixels.Count)
     rectangleTrixels.RemoveRange(num7, rectangleTrixels.Count - num7);
   rectangle = TrixelSurface.GetRectangleSpiralLimits(num7);
   if (rectangleTrixels.Count < subSurface.Count)
   {
     this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, true, 1);
     this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, true, -1);
     this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, false, 1);
     this.ExpandSide(ref rectangle, center, subSurface, rectangleTrixels, false, -1);
   }
   return rectangleTrixels;
 }
Example #32
0
    private HashSet<TrixelEmplacement> TraverseSurface(TrixelEmplacement origin, ICollection<TrixelEmplacement> subSurface)
    {
      HashSet<TrixelEmplacement> hashSet = new HashSet<TrixelEmplacement>()
      {
        origin
      };
      Queue<TrixelSurface.TrixelToTraverse> queue = new Queue<TrixelSurface.TrixelToTraverse>();
      queue.Enqueue(new TrixelSurface.TrixelToTraverse()
      {
        Trixel = origin
      });
      while (queue.Count != 0)
      {
        TrixelSurface.TrixelToTraverse toTraverse = queue.Dequeue();
        TrixelEmplacement trixelEmplacement = toTraverse.Trixel;
        using (IEnumerator<FaceOrientation> enumerator = Enumerable.Where<FaceOrientation>((IEnumerable<FaceOrientation>) this.tangentFaces, (Func<FaceOrientation, bool>) (x =>
        {
          if (toTraverse.Except.HasValue)
            return toTraverse.Except.Value != x;
          else
            return true;
        })).GetEnumerator())
        {
label_8:
          while (enumerator.MoveNext())
          {
            FaceOrientation current = enumerator.Current;
            TrixelEmplacement traversal = trixelEmplacement.GetTraversal(current);
            while (true)
            {
              if (!hashSet.Contains(traversal) && subSurface.Contains(traversal))
              {
                hashSet.Add(traversal);
                if (hashSet.Count != subSurface.Count)
                {
                  queue.Enqueue(new TrixelSurface.TrixelToTraverse()
                  {
                    Trixel = traversal,
                    Except = new FaceOrientation?(current)
                  });
                  traversal = traversal.GetTraversal(current);
                }
                else
                  break;
              }
              else
                goto label_8;
            }
            return hashSet;
          }
        }
      }
      return hashSet;
    }
Example #33
0
 internal bool IsNeighbor(TrixelEmplacement trixel)
 {
     return(new BoundingBox(this.Start.Position, this.End.Position).Intersects(new BoundingBox(trixel.Position, trixel.Position + Vector3.One)));
 }
Example #34
0
 public TrixelEmplacement(TrixelEmplacement other) {
     X = other.X;
     Y = other.Y;
     Z = other.Z;
 }
Example #35
0
 public bool CanContain(TrixelEmplacement trixel, FaceOrientation face)
 {
     return(face == this.Orientation && (int)Vector3.Dot(trixel.Position, this.normal) == this.depth && (this.Trixels.Contains(trixel + this.Tangent) || this.Trixels.Contains(trixel + this.Bitangent) || (this.Trixels.Contains(trixel - this.Tangent) || this.Trixels.Contains(trixel - this.Bitangent))));
 }
Example #36
0
 public bool CanContain(TrixelEmplacement trixel)
 {
     return(Trile.TrixelInRange(trixel));
 }
Example #37
0
 public bool CanContain(TrixelEmplacement trixel, FaceOrientation face)
 {
   return face == this.Orientation && (int) Vector3.Dot(trixel.Position, this.normal) == this.depth && (this.Trixels.Contains(trixel + this.Tangent) || this.Trixels.Contains(trixel + this.Bitangent) || (this.Trixels.Contains(trixel - this.Tangent) || this.Trixels.Contains(trixel - this.Bitangent)));
 }
Example #38
0
 public bool CanContain(TrixelEmplacement trixel)
 {
   return Trile.TrixelInRange(trixel);
 }
Example #39
0
        private HashSet <TrixelEmplacement> TraverseSurface(TrixelEmplacement origin, ICollection <TrixelEmplacement> subSurface)
        {
            HashSet <TrixelEmplacement> hashSet = new HashSet <TrixelEmplacement>()
            {
                origin
            };
            Queue <TrixelSurface.TrixelToTraverse> queue = new Queue <TrixelSurface.TrixelToTraverse>();

            queue.Enqueue(new TrixelSurface.TrixelToTraverse()
            {
                Trixel = origin
            });
            while (queue.Count != 0)
            {
                TrixelSurface.TrixelToTraverse toTraverse = queue.Dequeue();
                TrixelEmplacement trixelEmplacement       = toTraverse.Trixel;
                using (IEnumerator <FaceOrientation> enumerator = Enumerable.Where <FaceOrientation>((IEnumerable <FaceOrientation>) this.tangentFaces, (Func <FaceOrientation, bool>)(x =>
                {
                    if (toTraverse.Except.HasValue)
                    {
                        return(toTraverse.Except.Value != x);
                    }
                    else
                    {
                        return(true);
                    }
                })).GetEnumerator())
                {
label_8:
                    while (enumerator.MoveNext())
                    {
                        FaceOrientation   current   = enumerator.Current;
                        TrixelEmplacement traversal = trixelEmplacement.GetTraversal(current);
                        while (true)
                        {
                            if (!hashSet.Contains(traversal) && subSurface.Contains(traversal))
                            {
                                hashSet.Add(traversal);
                                if (hashSet.Count != subSurface.Count)
                                {
                                    queue.Enqueue(new TrixelSurface.TrixelToTraverse()
                                    {
                                        Trixel = traversal,
                                        Except = new FaceOrientation?(current)
                                    });
                                    traversal = traversal.GetTraversal(current);
                                }
                                else
                                {
                                    break;
                                }
                            }
                            else
                            {
                                goto label_8;
                            }
                        }
                        return(hashSet);
                    }
                }
            }
            return(hashSet);
        }
Example #40
0
 public bool IsBorderTrixelFace(TrixelEmplacement traversed)
 {
   if (Trile.TrixelInRange(traversed))
     return !this.TrixelExists(traversed);
   else
     return true;
 }
Example #41
0
 public void RebuildParts()
 {
   this.Dirty = false;
   this.RectangularParts.Clear();
   Queue<HashSet<TrixelEmplacement>> queue = new Queue<HashSet<TrixelEmplacement>>();
   if (this.Trixels.Count > 0)
     queue.Enqueue(new HashSet<TrixelEmplacement>((IEnumerable<TrixelEmplacement>) this.Trixels));
   while (queue.Count > 0)
   {
     HashSet<TrixelEmplacement> hashSet1 = queue.Dequeue();
     TrixelEmplacement center = new TrixelEmplacement();
     foreach (TrixelEmplacement trixelEmplacement in hashSet1)
       center.Position += trixelEmplacement.Position;
     center.Position = FezMath.Floor(center.Position / (float) hashSet1.Count);
     if ((double) Vector3.Dot(center.Position, this.normal) != (double) this.depth)
       center.Position = center.Position * (Vector3.One - FezMath.Abs(this.normal)) + (float) this.depth * this.normal;
     if (!hashSet1.Contains(center))
       center = this.FindNearestTrixel(center, (ICollection<TrixelEmplacement>) hashSet1);
     Rectangle rectangle;
     List<TrixelEmplacement> biggestRectangle = this.FindBiggestRectangle(center, (ICollection<TrixelEmplacement>) hashSet1, out rectangle);
     rectangle.Offset((int) Vector3.Dot(center.Position, this.Tangent), (int) Vector3.Dot(center.Position, this.Bitangent));
     this.RectangularParts.Add(new RectangularTrixelSurfacePart()
     {
       Orientation = this.Orientation,
       Start = new TrixelEmplacement((float) rectangle.X * this.Tangent + (float) rectangle.Y * this.Bitangent + (float) this.depth * this.normal),
       TangentSize = rectangle.Width,
       BitangentSize = rectangle.Height
     });
     hashSet1.ExceptWith((IEnumerable<TrixelEmplacement>) biggestRectangle);
     while (hashSet1.Count > 0)
     {
       HashSet<TrixelEmplacement> hashSet2 = this.TraverseSurface(Enumerable.First<TrixelEmplacement>((IEnumerable<TrixelEmplacement>) hashSet1), (ICollection<TrixelEmplacement>) hashSet1);
       queue.Enqueue(hashSet2);
       if (hashSet1.Count == hashSet2.Count)
         hashSet1.Clear();
       else
         hashSet1.ExceptWith((IEnumerable<TrixelEmplacement>) hashSet2);
     }
   }
 }
Example #42
0
 public bool IsBorderTrixelFace(TrixelEmplacement id, FaceOrientation face)
 {
     return(this.IsBorderTrixelFace(id.GetTraversal(face)));
 }
Example #43
0
 private void InitializeSurfaces()
 {
   this.surfaces.Clear();
   foreach (FaceOrientation faceOrientation in Util.GetValues<FaceOrientation>())
   {
     TrixelEmplacement firstTrixel = new TrixelEmplacement(FezMath.IsPositive(faceOrientation) ? FezMath.AsVector(faceOrientation) * (this.size * 16f - Vector3.One) : Vector3.Zero);
     TrixelSurface trixelSurface = new TrixelSurface(faceOrientation, firstTrixel);
     Vector3 mask1 = FezMath.GetMask(FezMath.AsAxis(FezMath.GetTangent(faceOrientation)));
     int num1 = (int) Vector3.Dot(this.size, mask1) * 16;
     Vector3 mask2 = FezMath.GetMask(FezMath.AsAxis(FezMath.GetBitangent(faceOrientation)));
     int num2 = (int) Vector3.Dot(this.size, mask2) * 16;
     trixelSurface.RectangularParts.Add(new RectangularTrixelSurfacePart()
     {
       Orientation = faceOrientation,
       TangentSize = num1,
       BitangentSize = num2,
       Start = firstTrixel
     });
     for (int index1 = 0; index1 < num1; ++index1)
     {
       for (int index2 = 0; index2 < num2; ++index2)
         trixelSurface.Trixels.Add(new TrixelEmplacement(firstTrixel + mask1 * (float) index1 + mask2 * (float) index2));
     }
     this.surfaces.Add(trixelSurface);
   }
 }
Example #44
0
 public bool AnyRectangleContains(TrixelEmplacement trixel)
 {
   foreach (RectangularTrixelSurfacePart trixelSurfacePart in this.RectangularParts)
   {
     Vector3 vector1 = trixel.Position - trixelSurfacePart.Start.Position;
     if ((double) vector1.X >= 0.0 && (double) vector1.Y >= 0.0 && (double) vector1.Z >= 0.0)
     {
       int num1 = (int) Vector3.Dot(vector1, this.Tangent);
       int num2 = (int) Vector3.Dot(vector1, this.Bitangent);
       if (num1 < trixelSurfacePart.TangentSize && num2 < trixelSurfacePart.BitangentSize)
         return true;
     }
   }
   return false;
 }