Beispiel #1
0
        public void AddTriangle(TriangleLocation location, Material material)
        {
            var index = (int)location;

            if (!triangles[index])
            {
                CreateTriangle(index, material);
            }
        }
        public TriangleLocation GetTriangleLocation(Triangle triangle)
        {
            var arrVs = new Vector2[] {
                triangle.vertexA.ToVector(),
                triangle.vertexB.ToVector(),
                triangle.vertexC.ToVector()
            };

            Array.Sort <Vector2>(arrVs, (v1, v2) => v1.Length().CompareTo(v2.Length()));
            var loc = OnGetLocation(arrVs);

            if (loc.IsValid)
            {
                loc = new TriangleLocation(loc, GetAddress(loc.Row, loc.Column));
            }
            return(loc);
        }
        public Triangle GetTriangleAt(TriangleLocation location)
        {
            var row    = location.Row;
            var column = location.Column;

            if (row < 0 || row >= TriangleRows)
            {
                throw new ArgumentOutOfRangeException($"Row parameter can not be greater than {TriangleRows - 1} and less than 0.");
            }
            if (column < 0 || column >= TriangleColumns)
            {
                throw new ArgumentOutOfRangeException($"Row parameter can not be greater than {TriangleColumns - 1} and less than 0.");
            }

            var t = OnGetTriangle(row, column);

            if (!t.IsEmpty)
            {
                t = new Triangle(t,
                                 new TriangleLocation(row, column, GetAddress(row, column)));
            }
            return(t);
        }
        public void Can_Create_Parallelogram_Container()
        {
            var cont = ContainerFactory.CreateParallelogram(60, 6, 10, TrianglePattern.TwoPerColumn);

            Assert.True(cont.Rows == cont.Columns && cont.Rows == 6);
            var loc = new TriangleLocation(4, 4);
            var t   = cont.GetTriangleAt(loc);

            Assert.False(t.IsEmpty);
            var tAddr = t.Location.Address;

            Assert.Equal("E5", tAddr);
            loc = cont.GetTriangleLocation(t);
            Assert.True(loc.IsValid);
            Assert.Equal("E5", loc.Address);

            var sz         = cont.Size;
            var testHeight = Math.Round(Math.Sin(0.33333333) * 60, 4);
            var testWidth  = Math.Round(60 * (1 + Math.Cos(0.33333333)), 4);

            Assert.Equal <double>(testHeight, Math.Round(sz.Height, 4));
            Assert.Equal <double>(testWidth, Math.Round(sz.Width, 4));
        }
Beispiel #5
0
        /// <summary>
        /// Accepts row indicator as char (A-F), int col val (1-12), and hypotenuse length and returns
        /// the triangle vertices for the right triangle in the target position (in a matrix) such that
        /// the matrix forms a full square image of right triangles. Each element in the resulting matrix
        /// is assumed to be one square pixel and each non hypotenuse side has length = nonHypoLen
        /// </summary>
        /// <returns>
        /// A Triangle object with three vertices ordered st. v1 is top left vertex
        /// and v2/v3 are the next vertices moving clockwise from v1.
        /// </returns>
        public static Triangle CalcTriangleCoords(TriangleLocation loc, int nonHypoLen)
        {
            if (loc.Row < 'A' || loc.Row > 'F' || loc.Col < 1 || loc.Col > 12 || nonHypoLen < 1)
            {
                throw new Exception("inputs outside of acceptable range for triangle coord calculation");
            }

            int rowVal = loc.Row - 'A';

            Triangle t = new Triangle();

            // v1.a will be in same place regardless of triangle orientation
            t.V1.Row = rowVal * nonHypoLen;

            // calculate other vertices based on triangle orientation
            if (loc.Col % 2 == 0)
            {
                int colIndx = loc.Col / 2 - 1;
                t.V1.Col = colIndx * nonHypoLen;
                t.V2.Row = rowVal * nonHypoLen;
                t.V2.Col = (colIndx + 1) * nonHypoLen;
                t.V3.Row = (rowVal + 1) * nonHypoLen;
                t.V3.Col = (colIndx + 1) * nonHypoLen;
            }
            else
            {
                int colIndx = loc.Col / 2;
                t.V1.Col = colIndx * nonHypoLen;
                t.V2.Row = (rowVal + 1) * nonHypoLen;
                t.V2.Col = (colIndx + 1) * nonHypoLen;
                t.V3.Row = (rowVal + 1) * nonHypoLen;
                t.V3.Col = colIndx * nonHypoLen;
            }

            return(t);
        }
 internal LocationInfo(TriangleLocation location) : base()
 {
     Row     = location.Row;
     Column  = location.Column;
     Address = location.Address;
 }