コード例 #1
0
        /// <summary>
        /// Relational equality test.
        /// </summary>
        /// <param name="that">The bearing to compare with</param>
        /// <returns>True if the supplied bearing has the same from-point, and the
        /// same observed value.</returns>
        public bool Equals(BearingDirection that)
        {
            if (that == null)
            {
                return(false);
            }

            return(Object.ReferenceEquals(this.m_From, that.m_From) &&
                   Math.Abs(this.m_Observation.Value - that.m_Observation.Value) < Constants.TINY);
        }
コード例 #2
0
ファイル: Direction.cs プロジェクト: 15831944/backsight
        /// <summary>
        /// Relational equality test. When comparing any offsets, it's the actual ground
        /// dimension of the offset we're concerned with -- NOT the address of the offset,
        /// or the way it was specified (i.e. an offset can be the same, even if one is
        ///	an OffsetDistance, and the other is an OffsetPoint).
        ///
        /// The result of the comparison is from the Direction class & down. Directions will
        /// compare the same, even if the info in parent classes is different.
        /// </summary>
        /// <param name="other">The direction to compare with</param>
        /// <returns></returns>
        internal bool IsEquivalent(Direction other)
        {
            // Check the simple fields.
            if (this.GetType() != other.GetType())
            {
                return(false);
            }

            // If one direction has an offset & the other doesn't, the directions are different.

            if ((m_Offset != null && other.m_Offset == null) ||
                (m_Offset == null && other.m_Offset != null))
            {
                return(false);
            }

            //	If BOTH offsets are defined, see if they are equivalent.
            if (m_Offset != null && other.m_Offset != null)
            {
                // It is assumed that the point from which the direction
                // was measured has already been checked by the operator==
                // function in derived sub-classes.

                // Get the (signed) offsets, in meters on the ground.
                double offThis = m_Offset.GetMetric(this);
                double offThat = other.m_Offset.GetMetric(other);

                // The sign matters.
                if ((offThis < 0.0 && offThat >= 0.0) || (offThis >= 0.0 && offThat < 0.0))
                {
                    return(false);
                }

                // Same sign, so if the offsets are the same, they should subtract to zero.
                if (Math.Abs(offThis - offThat) > Double.Epsilon)
                {
                    return(false);
                }
            }

            // Return the result of comparing the two derived classes.
            // ...not sure what's going on here... (shouldn't this just call an abstract method? -- maybe
            // needs to be a templated method, since both types need to be the same.

            if (this is AngleDirection || this is DeflectionDirection)
            {
                AngleDirection rThis = (AngleDirection)this;
                AngleDirection rThat = (AngleDirection)other;
                return(rThis.Equals(rThat));
            }
            else if (this is BearingDirection)
            {
                BearingDirection rThis = (BearingDirection)this;
                BearingDirection rThat = (BearingDirection)other;
                return(rThis.Equals(rThat));
            }
            else if (this is ParallelDirection)
            {
                ParallelDirection rThis = (ParallelDirection)this;
                ParallelDirection rThat = (ParallelDirection)other;
                return(rThis.Equals(rThat));
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Checks whether the current data is enough to construct a direction. If so,
        /// draw it. Take care to erase any previously drawn direction.
        /// </summary>
        void OnChange()
        {
            Direction dir=null;	            // Constructed direction.
            AngleDirection angle;			// Angle from a backsight.
            DeflectionDirection deflect;	// Deflection angle.
            BearingDirection bearing;		// Bearing from north.
            ParallelDirection par;			// Parallel to 2 points.
            double srad;			        // Signed radian value.

            // Apply sign to any angle we have.
            if (m_IsClockwise)
                srad = m_Radians;
            else
                srad = -m_Radians;

            if (m_Backsight!=null)
            {
                // If we have a backsight, we could either have a regular
                // angle or a deflection. To construct either, we need a
                // from-point as well.

                // Note that an angle of zero (passing through the backsight
                // or foresight) is fine.

                if (m_From!=null)
                {
                    IAngle obsv = new RadianValue(srad);

                    if (m_IsDeflection)
                    {
                        deflect = new DeflectionDirection(m_Backsight, m_From, obsv);
                        dir = deflect;
                    }
                    else
                    {
                        angle = new AngleDirection(m_Backsight, m_From, obsv);
                        dir = angle;
                    }
                }
            }
            else if (m_From!=null)
            {
                // No backsight, so we could have either a bearing,
                // or a direction defined using 2 parallel points.
                // Since a bearing of zero is quite valid, we check
                // the dialog field to see if this is an entered value,
                // or just the initial value.

                if (m_Par1!=null && m_Par2!=null)
                {
                    par = new ParallelDirection(m_From, m_Par1, m_Par2);
                    dir = par;
                }
                else
                {
                    if (m_Radians>Constants.TINY || angleTextBox.Text.Trim().Length==0)
                    {
                        bearing = new BearingDirection(m_From, new RadianValue(srad));
                        dir = bearing;
                    }
                }
            }

            // If we have formed a direction, apply any offset.
            if (dir!=null)
                dir.Offset = m_Offset;

            // Try to calulate the position of the sideshot.
            IPosition to = RadialOperation.Calculate(dir, this.Length);

            // Return if we calculated a position that is identical to the old one.
            //if (to!=null && to.IsAt(m_To, Double.Epsilon))
            //    return;

            m_Dir = dir;
            m_To = to;

            m_Cmd.ErasePainting();
        }
コード例 #4
0
        /// <summary>
        /// Uses the currently displayed information to try to construct a
        /// direction object.
        /// </summary>
        /// <returns>The constructed direction (null if a direction cannot be created
        /// based on the information that's currently displayed)</returns>
        Direction GetCurrentDirection()
        {
            Direction result = null;

            // Get signed direction
            double srad = (m_IsClockwise ? m_Radians : -m_Radians);
            IAngle dir = new RadianValue(srad);

            if (m_Backsight!=null)
            {
                // If we have a backsight, we could either have a regular
                // angle or a deflection. To construct either, we need a
                // from-point as well.

                // Note that an angle of zero (passing through the backsight
                // or foresight) is fine.

                if (m_From!=null)
                {
                    if (m_IsDeflection)
                        result = new DeflectionDirection(m_Backsight, m_From, dir);
                    else
                        result = new AngleDirection(m_Backsight, m_From, dir);
                }
            }
            else if (m_From!=null)
            {
                // No backsight, so we could have either a bearing,
                // or a direction defined using 2 parallel points.
                // Since a bearing of zero is quite valid, we check
                // the dialog field to see if this is an entered value,
                // or just the initial value.

                if (m_Par1!=null && m_Par2!=null)
                    result = new ParallelDirection(m_From, m_Par1, m_Par2);
                else if (m_Radians > Constants.TINY || directionTextBox.Text.Length>0)
                    result = new BearingDirection(m_From, dir);
            }

            // If we haven't formed a direction, ignore any offset
            if (result==null)
                return null;

            // An offset could have been specified by a point, or by
            // entering a distance left or right of the direction.

            Offset offset = null;

            if (m_OffsetPoint!=null)
                offset = new OffsetPoint(m_OffsetPoint);
            else if (m_OffsetDistance!=null)
                offset = new OffsetDistance(m_OffsetDistance, !m_IsRight);

            // If we got an offset, include it in the direction.
            if (offset!=null)
                result.Offset = offset;

            return result;
        }
コード例 #5
0
        /// <summary>
        /// Relational equality test. 
        /// </summary>
        /// <param name="that">The bearing to compare with</param>
        /// <returns>True if the supplied bearing has the same from-point, and the
        /// same observed value.</returns>
        public bool Equals(BearingDirection that)
        {
            if (that==null)
                return false;

            return (Object.ReferenceEquals(this.m_From, that.m_From) &&
                    Math.Abs(this.m_Observation.Value - that.m_Observation.Value) < Constants.TINY);
        }