예제 #1
0
        /// <summary>
        /// Gets a block face based on its orientation.
        /// </summary>
        /// <param name="o">Vector indicating the orientation of the face we try to get.</param>
        /// <returns>The searched Blockface if found, otherwise, null is returned.</returns>
        public BlockFace GetBlockFace(SphericalVector o)
        {
            if (o == null)
            {
                throw new ArgumentNullException("Orientation is mandatory", nameof(o));
            }

            return(m_Faces.FirstOrDefault(f => this.Orientation.Rotate(f.Position).IsSameVector(CoordinateConverter.ConvertToCartesian(o))));
        }
예제 #2
0
        private void GetBlock(string blockId)
        {
            Block b = Core.Blocks.FirstOrDefault(block => block.Id == blockId);

            Console.WriteLine($"{b.Id} {FormatCoordinates(b.Position)}");

            foreach (BlockFace face in b.Faces)
            {
                SphericalVector ccf = CoordinateConverter.ConvertToSpherical(face.Position);
                System.Console.WriteLine($"{face.Id} {FormatCoordinates(face.Position)} {FormatCoordinates(ccf)}");
            }
        }
예제 #3
0
        public void Block_CreateAndGetFaceWithBadOrientation_ReturnNull()
        {
            // 1. Prepare
            SphericalVector faceOrientation = new SphericalVector(Math.PI, Math.PI);
            Block           b = new TestBlock(new BlockFace("test", faceOrientation));

            // 2. Execute
            BlockFace f = b.GetBlockFace(new SphericalVector(100, 100));

            // 3. Verify
            Assert.Null(f);
        }
예제 #4
0
        public void Block_CreateAndGetFace_ShouldFindFace()
        {
            // 1. Prepare
            SphericalVector faceOrientation = new SphericalVector(Math.PI, Math.PI);

            // 2. Execute
            Block     b = new TestBlock(new BlockFace("test", faceOrientation));
            BlockFace f = b.GetBlockFace(faceOrientation);

            // 3. Verify
            Assert.NotNull(f);
        }
예제 #5
0
        public void SphericalVector_CreateWithIntToNormalize_ShouldBeExpected(double phi, double theta, double expectedPhi, double expectedTheta)
        {
            // 1. Prepare
            // Nothing to prepare.

            // 2. Execute
            SphericalVector o = new SphericalVector(phi, theta);

            // 3. Verify
            Assert.Equal(expectedPhi, o.Phi, PRECISION_DOUBLE);
            Assert.Equal(expectedTheta, o.Theta, PRECISION_DOUBLE);
        }
예제 #6
0
        public void SphericalVector_CreateWithCorrectInt_ShouldBeInchanged(double phi, double theta)
        {
            // 1. Prepare
            // Nothing to prepare.

            // 2. Execute
            SphericalVector o = new SphericalVector(phi, theta);

            // 3. Verify
            Assert.Equal(phi, o.Phi);
            Assert.Equal(theta, o.Theta);
        }
        public void CoordinateConverter_ConvertFromSphericalToCartesian_BeExpected(double phi, double theta, double x, double y, double z)
        {
            // 1. Prepare
            SphericalVector sc = new SphericalVector(phi, theta);

            // 2. Execute
            Cartesian3dCoordinate cc = CoordinateConverter.ConvertToCartesian(sc);

            // 3. Verify
            Assert.Equal(x, cc.X, PRECISION_DOUBLE);
            Assert.Equal(y, cc.Y, PRECISION_DOUBLE);
            Assert.Equal(z, cc.Z, PRECISION_DOUBLE);
        }
예제 #8
0
        public void SphericalVector_CompareSphericalVector_ShouldBeExpected(double phi1, double theta1, double phi2, double theta2, bool expected)
        {
            // 1. Prepare
            SphericalVector o1 = new SphericalVector(phi1, theta1);
            SphericalVector o2 = new SphericalVector(phi2, theta2);

            // 2. Execute
            bool resultEquals1            = o1.Equals(o2);
            bool resultEquals2            = o2.Equals(o1);
            bool resultEqualsOperator1    = o1 == o2;
            bool resultEqualsOperator2    = o2 == o1;
            bool resultDifferentOperator1 = o1 != o2;
            bool resultDifferentOperator2 = o2 != o1;

            // 3. Verify
            Assert.Equal(expected, resultEquals1);
            Assert.Equal(expected, resultEquals2);
            Assert.Equal(expected, resultEqualsOperator1);
            Assert.Equal(expected, resultEqualsOperator2);
            Assert.Equal(!expected, resultDifferentOperator1);
            Assert.Equal(!expected, resultDifferentOperator2);
        }
예제 #9
0
 protected string FormatCoordinates(SphericalVector v) => $"({v.Phi:0.00}, {v.Theta:0.00})";
예제 #10
0
 /// <summary>
 /// Create a new objet representing a block face.
 /// </summary>
 /// <param name="identifier">Identifier of the BlockFaces that should match the expected face.</param>
 /// <param name="p"></param>
 public BlockFace(string identifier, SphericalVector p)
 {
     this.Position = CoordinateConverter.ConvertToCartesian(p);
     this.Id       = identifier;
 }