Esempio n. 1
0
		public int CompareTo(IPosition other)
		{
			NaryPosition otherNary = other as NaryPosition;
			if (otherNary != null)
				return CompareTo(otherNary);
			return 0;
		}
Esempio n. 2
0
 /// <summary>
 /// Checks if the figure is on the way that the figures want to move
 /// </summary>
 /// <param name="position">Position on which the figure moves</param>
 /// <param name="board">The game board</param>
 /// <exception cref="InvalidPositionException"></exception>
 public static void CheckIfFigureOnTheWay(IPosition position, IBoard board)
 {
     if (board.GetFigureAtPosition(position) != null)
     {
         throw new InvalidPositionException(GlobalErrorMessages.FigureOnTheWayErrorMessage);
     }
 }
		public static SpatialCriteria WithinRadiusOf(this SpatialCriteriaFactory @this,
													double radius,
													IPosition position)
		{
			var coordinate = position.GetCoordinate();
			return @this.WithinRadiusOf(radius, coordinate.Longitude, coordinate.Latitude);
		}
 public override void MouseUp(IPosition p, MouseButtons b)
 {
     if (b == MouseButtons.Left)
     {
         RectFinish();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Add the specific figure at the specific position on the board
 /// </summary>
 /// <param name="figure">Figure to be added</param>
 /// <param name="position">The position on which the figure should be added</param>
 public void AddFigure(IFigure figure, IPosition position)
 {
     Validator.CheckIfObjectIsNull(figure);
     Validator.CheckIfPositionValid(position);
     this.board[position.Row, position.Col] = figure;
     this.figurePositionsOnBoard[figure.DisplaySign] = position;
 }
Esempio n. 6
0
 private void RobotReportedPosition(int robotId, IPosition position, IHeading heading)
 {
     if (ReportedPosition != null)
     {
         ReportedPosition(robotId, position, heading);
     }
 }
Esempio n. 7
0
 public virtual IGrid Fill(IPosition position, Mark mark)
 {
     var grid = new Mark[3, 3];
     Array.Copy(_grid, grid, _grid.Length);
     grid[position.Row, position.Col] = mark;
     return new Grid3X3(grid);
 }
Esempio n. 8
0
 public void WhenMarkPosition_TheGridShouldGetUpdatedForTheSamePosition(IPosition position)
 {
     var mock = new Mock<IGrid>();
     mock.Setup(x => x.Fill(position, Mark.Cross));
     Mark.Cross.On(mock.Object, position);
     mock.Verify(x => x.Fill(position, Mark.Cross), Times.Once());
 }
        /// <summary>
        /// Creates a new <c>FindOverlapsQuery</c> (and executes it). The result of the query
        /// can then be obtained through the <c>Result</c> property.
        /// </summary>
        /// <param name="index">The spatial index to search</param>
        /// <param name="closedShape">The closed shape defining the search area.</param>
        /// <param name="spatialType">The type of objects to look for.</param>
        internal FindOverlapsQuery(ISpatialIndex index, IPosition[] closedShape, SpatialType spatialType)
        {
            m_ClosedShape = new ClosedShape(closedShape);
            m_Points = new List<PointFeature>(100);
            m_Result = new List<ISpatialObject>(100);

            // If we are looking for points or lines, locate points that overlap. Note that
            // if the user does not actually want points in the result, we still do a point
            // search, since it helps with the selection of lines.
            if ((spatialType & SpatialType.Point)!=0 || (spatialType & SpatialType.Line)!=0)
            {
                index.QueryWindow(m_ClosedShape.Extent, SpatialType.Point, OnPointFound);

                // Remember the points in the result if the caller wants them
                if ((spatialType & SpatialType.Point)!=0)
                    m_Result.AddRange(m_Points.ToArray());
            }

            // Find lines (this automatically includes lines connected to the points we just found)
            if ((spatialType & SpatialType.Line)!=0)
                index.QueryWindow(m_ClosedShape.Extent, SpatialType.Line, OnLineFound);

            // Find any overlapping text
            if ((spatialType & SpatialType.Text)!=0)
                index.QueryWindow(m_ClosedShape.Extent, SpatialType.Text, OnTextFound);

            m_Result.TrimExcess();
            m_Points = null;
        }
 public CircularArcGeometry(ICircleGeometry circle, IPosition bc, IPosition ec, bool isClockwise)
 {
     m_Circle = circle;
     m_BC = PositionGeometry.Create(bc);
     m_EC = PositionGeometry.Create(ec);
     m_IsClockwise = isClockwise;
 }
 /// <summary>
 /// Constructor with 3 parameters
 /// </summary>
 /// <param name="playerPosition">Parameter of type IPosition</param>
 /// <param name="rows">Parameter of type int</param>
 /// <param name="cols">Parameter of type int</param>
 public StandardPlayFieldGenerator(IPosition playerPosition, int rows = Constants.StandardGameLabyrinthRows, int cols = Constants.StandardGameLabyrinthCols)
 {
     this.playField = new ICell[rows, cols];
     this.playerPosition = playerPosition;
     this.rows = rows;
     this.cols = cols;
 }
Esempio n. 12
0
 public void AddFigure(IFigure figure, IPosition position)
 {
     Validator.CheckIfObjectIsNull(figure, GlobalErrorMessages.NullFigureErrorMessage);
     Validator.CheckIfPositionValid(position, GlobalErrorMessages.PositionNotValidMessage);
     this.board[position.Row, position.Col] = figure;
     this.figurePositionsOnBoard[figure.DisplayName] = position;
 }
Esempio n. 13
0
 /// <summary>
 /// Creates a new <c>PositionGeometry</c> from the supplied position (or casts
 /// the supplied position if it's already an instance of <c>PositionGeometry</c>).
 /// </summary>
 /// <param name="p">The position the geometry should correspond to</param>
 /// <returns>A newly created <c>PositionGeometry</c> instance, or the supplied
 /// position if it's already an instance of <c>PositionGeometry</c></returns>
 public static PositionGeometry Create(IPosition p)
 {
     if (p is PositionGeometry)
         return (p as PositionGeometry);
     else
         return new PositionGeometry(p.X, p.Y);
 }
Esempio n. 14
0
        public virtual void SetUp()
        {
            RcvBuffer = new UnsafeBuffer(new byte[ALIGNED_FRAME_LENGTH]);
            DataHeader = new DataHeaderFlyweight();
            MockFragmentHandler = A.Fake<FragmentHandler>();
            MockControlledFragmentHandler = A.Fake<IControlledFragmentHandler>();
            Position = A.Fake<IPosition>(options => options.Wrapping(new AtomicLongPosition()));
            LogBuffers = A.Fake<LogBuffers>();
            ErrorHandler = A.Fake<ErrorHandler>();
            Subscription = A.Fake<Subscription>();

            AtomicBuffers = new UnsafeBuffer[(LogBufferDescriptor.PARTITION_COUNT * 2) + 1];
            TermBuffers = new UnsafeBuffer[LogBufferDescriptor.PARTITION_COUNT];

            DataHeader.Wrap(RcvBuffer);

            for (var i = 0; i < LogBufferDescriptor.PARTITION_COUNT; i++)
            {
                AtomicBuffers[i] = new UnsafeBuffer(new byte[TERM_BUFFER_LENGTH]);
                TermBuffers[i] = AtomicBuffers[i];

                AtomicBuffers[i + LogBufferDescriptor.PARTITION_COUNT] = new UnsafeBuffer(new byte[LogBufferDescriptor.TERM_META_DATA_LENGTH]);
            }

            AtomicBuffers[LogBufferDescriptor.LOG_META_DATA_SECTION_INDEX] = new UnsafeBuffer(new byte[LogBufferDescriptor.LOG_META_DATA_LENGTH]);

            A.CallTo(() => LogBuffers.AtomicBuffers()).Returns(AtomicBuffers);
            A.CallTo(() => LogBuffers.TermLength()).Returns(TERM_BUFFER_LENGTH);
        }
Esempio n. 15
0
        public static MediaQuery Parse(string value, IPosition forPosition)
        {
            if (value.Contains(','))
            {
                var parts = value.Split(',');

                var ret = new List<MediaQuery>();

                foreach (var part in parts)
                {
                    ret.Add(Parse(part.Trim(), forPosition));
                }

                if (ret.Count == 1) return ret[0];

                return new CommaDelimitedMedia(ret, forPosition);
            }

            if (value.StartsWith("only ", StringComparison.InvariantCultureIgnoreCase))
            {
                return new OnlyMedia(ParseQuery(value.Substring("only ".Length).Trim(), forPosition), forPosition);
            }

            if (value.StartsWith("not ", StringComparison.InvariantCultureIgnoreCase))
            {
                return new NotMedia(ParseQuery(value.Substring("not ".Length).Trim(), forPosition), forPosition);
            }

            return ParseQuery(value, forPosition);
        }
Esempio n. 16
0
        public void Action(Team myTeam, Team enemyTeam, Ball ball, MatchInfo matchInfo)
        {
            var pl1 = myTeam.Players.First(pl => pl.PlayerType == PlayerType.RightDefender);

            myTeam.DevMessage = string.Format("speed {0}", pl1.Velocity.Length);

            if (maxReached)
            {
                if (pl1.Velocity.Length > 0.05)
                {
                    pl1.ActionWait();
                    return;
                }

                myTeam.DevMessage += "\r\n0.05 minReached";
                maxReached = false;
                point = pl1.Position.X < Field.Borders.Center.X ? Field.EnemyGoal : Field.MyGoal;
            }

            if (pl1.Velocity.Length > 3 * 0.95)
            {
                myTeam.DevMessage += "\r\n0.95 maxReached";
                maxReached = true;
                prevVelocity = 0;
                pl1.ActionWait();
            }
            else
            {
                pl1.ActionGo(point);
                prevVelocity = pl1.Velocity.Length;
            }
        }
Esempio n. 17
0
            public void Goto(IPosition position, bool KeepRunning)
            {
                var distance = DistanceTo(position);

                if (DistanceTo(position) > DistanceTolerance)
                {
                    DateTime duration = DateTime.Now.AddSeconds(5);
                    var player = api.Entity.GetLocalPlayer();
                    api.ThirdParty.KeyDown(Keys.NUMPAD8);

                    while (DistanceTo(position) > DistanceTolerance && DateTime.Now < duration)
                    {
                        if ((ViewMode)api.Player.ViewMode != ViewMode.FirstPerson)
                        {
                            api.Player.ViewMode = (int)ViewMode.FirstPerson;
                        }

                        FaceHeading(position);

                        System.Threading.Thread.Sleep(30);
                    }

                    api.ThirdParty.KeyUp(Keys.NUMPAD8);
                }
            }
Esempio n. 18
0
 public static void CheckIfFigureOnTheWay(IPosition position, IBoard board, string message)
 {
     if (board.GetFigureAtPosition(position) != null)
     {
         throw new ArgumentException(message);
     }
 }
        public static double CalculateDistance(IPosition position1, IPosition position2)
        {
            var xPortion = (position2.XCoord - position1.XCoord) * (position2.XCoord - position1.XCoord);
            var yPortion = (position2.YCoord - position1.YCoord) * (position2.YCoord - position1.YCoord);

            return Math.Sqrt(xPortion + yPortion);
        }
Esempio n. 20
0
 public override void MouseMove(IPosition p, MouseButtons b)
 {
     if (b == MouseButtons.Left)
     {
         RectUpdate(p);
     }
 }
		public void Init()
		{
			this._field = new Field();
			this._field.Position = new Position(2, 2);
			this._originalPosition = this._field.Position.Clone();
			this._movement = new StraightMovement(this._field);
		}
 /// <summary>
 /// Field constructor that takes an IPosition object as argument
 /// </summary>
 /// <param name="position">The position for the current IField object</param>
 /// <param name="color">The color for the current IField object</param>
 /// <param name="chessBoard">The chess board for the current IField object</param>
 protected Field(IPosition position, ColorType color, IChessBoard chessBoard)
 {
     this.ChessBoard = chessBoard;
     this.Position = position;
     this.Color = color;
     this.HasChessPiece = false;
     this.IsDrawable = true;
 }
Esempio n. 23
0
 public void createOn(IPosition position, int barIndex)
 {
     position.CloseAtStop(
         barIndex,
         stopLossPrice,
         Signals.STOP_LOSS_CLOSE
     );
 }
Esempio n. 24
0
 /// <summary>
 /// Makes the player look at the specified position. 
 /// </summary>            
 /// Author: SMD111
 /// https://github.com/smd111/EliteMMO.Scripted
 public bool FaceHeading(IPosition position)
 {
     var player = api.Entity.GetLocalPlayer();
     var angle = (byte)(Math.Atan((position.Z - player.Z) / (position.X - player.X)) * -(128.0f / Math.PI));
     if (player.X > position.X) angle += 128;
     var radian = (((float)angle) / 255) * 2 * Math.PI;
     return api.Entity.SetEntityHPosition(api.Entity.LocalPlayerIndex, (float)radian);
 }
Esempio n. 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Annotation"/> class with the
 /// <see cref="FontStyle"/> property set to <see cref="System.Drawing.FontStyle.Regular"/>.
 /// </summary>
 /// <param name="text">The annotation text.</param>
 /// <param name="position">The position for the text (center-baseline aligned).</param>
 /// <param name="height">The height of the text (in meters on the ground).</param>
 /// <param name="rotation">The rotation (in radians clockwise from horizontal).</param>
 internal Annotation(string text, IPosition position, double height, double rotation)
 {
     m_Text = text;
     m_Position = PointGeometry.Create(position);
     m_Height = height;
     m_Rotation = new RadianValue(rotation);
     m_FontStyle = FontStyle.Regular;
 }
Esempio n. 26
0
 public void GetRowsOfPositionReturnsCorrectly(IPosition position)
 {
     var rows = Rows.OfPosition<Rows3X3>(position);
     Assert.That(rows, Is.Not.Null);
     Assert.That(rows, Is.Not.Empty);
     CollectionAssert.AllItemsAreNotNull(rows);
     Assert.IsTrue(rows.All(x => x.Includes(position)));
 }
 private StandardPlayer(string name, int id, IGame game, ICharacter character, IPosition position)
 {
     this._name = name;
     this._id = id;
     this._game = game;
     this._character = character;
     this._position = position;
 }
Esempio n. 28
0
        internal HorizontalRay(IPosition start, double distance)
        {
            if (distance < 0.0)
                throw new ArgumentOutOfRangeException();

            m_Start = PointGeometry.Create(start);
            m_EndX = start.X + distance;
        }
Esempio n. 29
0
        public Position(IPosition position)
        {
            position.PositionChanged += this.OnPositionChanged;
            this.AccountName = position.AccountName;
            this.Symbol = position.Contract.Symbol;

            this.OnPositionChanged(position);
        }
Esempio n. 30
0
        /// <summary>
        /// Creates a new <c>PositionedIcon</c>
        /// </summary>
        /// <param name="p">The position of the center of the icon (not null)</param>
        /// <param name="i">The icon involved (not null)</param>
        /// <exception cref="ArgumentNullException">If either the supplied position or the icon are null</exception>
        internal PositionedIcon(IPosition p, Icon i)
        {
            if (p==null || i==null)
                throw new ArgumentNullException();

            m_Icon = i;
            m_Position = p;
        }
Esempio n. 31
0
 /// <summary>
 /// Полный размер позиции в бумагах. Учитывается размер лота.
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public static double GetPositionSize(this IPosition pos)
 {
     return(pos.Shares * pos.Security.LotSize);
 }
Esempio n. 32
0
 public Window(IPosition a, IPosition b)
     : this(a.X, a.Y, b.X, b.Y)
 {
 }
Esempio n. 33
0
 public void Union(IPosition position)
 {
     Union(position.X, position.Y);
 }
Esempio n. 34
0
 public void AttachTo(IPosition parent)
 {
     _parent = new Optional <IPosition>(parent);
     Local   = Local - parent.World;
 }
Esempio n. 35
0
        /// <summary>
        /// Intersects this direction with a specific entity type.
        /// </summary>
        /// <param name="ent">The entity type to look for.</param>
        /// <param name="maxdist">Observation defining the maximum distance between the
        /// direction's from-point & the intersection. This can either be a <c>Distance</c>
        /// or an <c>OffsetPoint</c> object.</param>
        /// <param name="xsect">The position of the intersection (if any). Null if no intersection found.</param>
        /// <returns>True if an intersection was found.</returns>
        bool Intersect(IEntity ent, Observation maxdist, out IPosition xsect)
        {
            // Initialize the intersection.
            xsect = null;

            //	Get the max distance. It has to be defined to be SOMETHING.
            double dist = maxdist.GetDistance(this.From).Meters;

            if (Math.Abs(dist) < Constants.TINY)
            {
                return(false);
            }

            //	Define the position of the direction line.
            IPosition from = this.StartPosition;
            IPosition to   = Geom.Polar(from, this.Bearing.Radians, dist);

            throw new NotImplementedException("Direction.Intersect");

            /*
             * //	Construct a corresponding line segment.
             * CeLocation start(vfrom);
             * CeLocation end(vto);
             * CeSegment seg(start,end);
             *
             * //	Intersect the segment with the map (all features on
             * //	the currently active theme).
             * CeLayerList curlayer;
             * CeXObject xseg(seg,&curlayer);
             *
             * //	Get the first intersection (if any) with the specified
             * //	entity type.
             *
             * UINT4 nprim = xseg.GetCount();	// How many primitives did we intersect?
             * FLOAT8 bestdsq = 10e+38;		// Closest distance (squared) so far.
             * FLOAT8 tdistsq;					// Test distance (squared).
             * LOGICAL gotone=FALSE;
             *
             * for ( UINT4 i=0; i<nprim; i++ ) {
             *
             * //		Get the next thing we intersected.
             *  const CeXResult& xres = xseg[i];
             *  const CeLine* const pLine =
             *          dynamic_cast<const CeLine* const>(xres.GetpObject());
             *
             * //		Skip if it wasn't a line.
             *  if ( !pLine ) continue;
             *
             * //		Find the attached arc that has the current theme. Has
             * //		to be topological(?)
             *  const CeArc* const pArc = pLine->GetpArc(curlayer);
             *
             * //		Skip if it doesn't have the desired entity type.
             *  if ( pArc && pArc->GetpEntity()!=&ent ) continue;
             *
             * //		Determine the intersection on the primitive that is
             * //		closest to the start of the direction (ignoring any
             * //		intersections that are right at the start of the
             * //		direction line).
             *
             *  gotone = TRUE;
             *  UINT4 nx = xres.GetCount();
             *  CeVertex vtest;
             *
             *  for ( UINT4 j=0; j<nx; j++ ) {
             *
             *          vtest = xres.GetX1(j);
             *          tdistsq = vfrom.DistanceSquared(vtest);
             *          if ( tdistsq<bestdsq && tdistsq>TINY ) {
             *                  xsect = vtest;
             *                  bestdsq = tdistsq;
             *          }
             *
             * //			Check any grazing intersection too.
             *          if ( xres.IsGrazing() ) {
             *                  vtest = xres.GetX2(j);
             *                  tdistsq = vfrom.DistanceSquared(vtest);
             *                  if ( tdistsq<bestdsq && tdistsq>TINY ) {
             *                          xsect = vtest;
             *                          bestdsq = tdistsq;
             *                  }
             *          }
             *
             *  } // next intersection
             *
             * } // next intersected primitive
             *
             * return gotone;
             *
             * } // end of Intersect
             */
        }
Esempio n. 36
0
 /// <summary>
 /// Obtains the geometry for spans along an alternate face attached to this leg.
 /// </summary>
 /// <param name="start">The position for the start of the leg.
 /// <param name="end">The position for the end of the leg.</param>
 /// <param name="spans">Information for the spans coinciding with this leg.</param>
 /// <returns>The sections along this leg</returns>
 abstract internal ILineGeometry[] GetSpanSections(IPosition start, IPosition end, SpanInfo[] spans);
Esempio n. 37
0
 abstract internal void Project(ref IPosition pos, ref double bearing, double sfac);
Esempio n. 38
0
        /// <summary>
        /// Calculates positions that are parallel to a line.
        /// </summary>
        /// <param name="line">The reference line.</param>
        /// <param name="offset">The observed offset (either a <c>Distance</c> or an <c>OffsetPoint</c>).</param>
        /// <param name="sres">The position of the start of the parallel.</param>
        /// <param name="eres">The position of the end of the parallel.</param>
        /// <returns>True if positions calculated ok</returns>
        internal static bool Calculate(LineFeature line, Observation offset, out IPosition sres, out IPosition eres)
        {
            sres = eres = null;

            // Can't calculate if there is insufficient data.
            if (line == null || offset == null)
            {
                return(false);
            }

            // Is it an observed distance?
            Distance dist = (offset as Distance);

            if (dist != null)
            {
                return(ParallelLineUI.Calculate(line, dist, out sres, out eres));
            }

            // The only other thing it could be is an offset point.
            OffsetPoint offPoint = (offset as OffsetPoint);

            if (offPoint != null)
            {
                PointFeature point = offPoint.Point;
                return(ParallelLineUI.Calculate(line, point, out sres, out eres));
            }

            MessageBox.Show("ParallelLineUI.Calculate - Unexpected sort of observation");
            return(false);
        }
Esempio n. 39
0
        /// <summary>
        /// Reacts to selection of the OK button in the dialog.
        /// </summary>
        /// <param name="wnd">The dialog window. If this matches the dialog that
        /// this command knows about, the command will be executed (and, on success,
        /// the dialog will be destroyed). If it's some other window, it must
        /// be a sub-dialog created by our guy, so let it handle the request.</param>
        /// <returns>True if command finished ok</returns>
        internal override bool DialFinish(Control wnd)
        {
            // If it's the offset dialog that's just finished, grab info
            // from it, delete it, and go to the dialog for the first
            // terminal line.

            ISpatialDisplay view = ActiveDisplay;
            UpdateUI        up   = this.Update;

            if (m_ParDial != null)
            {
                // Get info from dialog (it'll be ONE of the two). The dialog
                // should only call this function after validating that one
                // of them is defined.
                m_OffsetPoint = m_ParDial.OffsetPoint;
                if (m_OffsetPoint == null)
                {
                    m_Offset = m_ParDial.OffsetDistance;
                }

                // Destroy the dialog.
                KillDialogs();

                // Calculate the positions for the parallel points.
                Calculate();

                // Repaint what we know about.
                Draw();

                // And start the dialog for the first terminal line.
                if (up != null)
                {
                    m_TermDial1 = new TerminalControl(up, false);
                }
                else
                {
                    m_TermDial1 = new TerminalControl(this, false);
                }

                //m_TermDial1.Show();
                this.Container.Display(m_TermDial1);
                return(true);
            }

            if (m_TermDial1 != null)
            {
                // Get the first terminal line (if any). And the position.
                m_TermLine1 = m_TermDial1.TerminalLine;
                m_Term1     = m_TermDial1.TerminalPosition;

                // And move on to the 2nd terminal dialog.
                KillDialogs();

                // Repaint what we know about.

                Draw();
                // And start the dialog for the first terminal line.
                if (up != null)
                {
                    m_TermDial2 = new TerminalControl(up, true);
                }
                else
                {
                    m_TermDial2 = new TerminalControl(this, true);
                }

                this.Container.Display(m_TermDial2);
                //m_TermDial2.Show();
                return(true);
            }

            if (m_TermDial2 == null)
            {
                throw new Exception("ParallelLineUI.DialFinish - No dialog!");
            }

            // Get the nortthern terminal line (if any). And the position.
            m_TermLine2 = m_TermDial2.TerminalLine;
            m_Term2     = m_TermDial2.TerminalPosition;

            // Erase everything special that we've drawn.
            ErasePainting();

            // And ensure the view has nothing selected (sometimes the line
            // last selected had been unhighlighted, although it's end points
            // stay highlighted for some reason).
            EditingController.Current.ClearSelection();

            // If we are doing an update, remember the changes
            if (up != null)
            {
                // Get the original operation.
                ParallelLineOperation op = (ParallelLineOperation)up.GetOp();
                if (op == null)
                {
                    throw new Exception("ParallelLineUI.DialFinish - Unexpected edit type.");
                }

                // Note the offset (it SHOULD be defined)
                Observation offset = null;

                if (m_Offset != null)
                {
                    offset = m_Offset;
                }
                else if (m_OffsetPoint != null)
                {
                    offset = new OffsetPoint(m_OffsetPoint);
                }

                Debug.Assert(offset != null);

                // Remember the changes as part of the UI object (the original edit remains
                // unchanged for now)

                UpdateItemCollection changes = op.GetUpdateItems(m_Line, offset, m_TermLine1, m_TermLine2, m_IsReversed);
                if (!up.AddUpdate(op, changes))
                {
                    return(false);
                }
            }
            else
            {
                Observation offset = m_Offset;
                if (offset == null && m_OffsetPoint != null)
                {
                    offset = new OffsetPoint(m_OffsetPoint);
                }
                Debug.Assert(offset != null);

                // Execute the edit
                ParallelLineOperation op = null;

                try
                {
                    op = new ParallelLineOperation(m_Line, offset, m_TermLine1, m_TermLine2, m_IsReversed);
                    op.Execute();
                }

                catch (Exception ex)
                {
                    MessageBox.Show(ex.StackTrace, ex.Message);
                    return(false);
                }
            }

            // Destroy the dialog(s).
            KillDialogs();

            // Get the base class to finish up.
            return(FinishCommand());
        }
Esempio n. 40
0
        /// <summary>
        /// Draws the current state of the edit
        /// </summary>
        internal void Draw()
        {
            Debug.Assert(m_Line != null);
            ISpatialDisplay view = ActiveDisplay;

            // Figure out the positions for the ends of the parallel line (if any) ...

            // Assume we already know both terminals.
            IPosition start = m_Term1;
            IPosition end   = m_Term2;

            // If either one is undefined, but a dialog for it is active,
            // try to get the terminal from there instead.
            if (m_TermDial1 != null && start == null)
            {
                start = m_TermDial1.TerminalPosition;
            }

            if (m_TermDial2 != null && end == null)
            {
                end = m_TermDial2.TerminalPosition;
            }

            // If they weren't actually defined, use the parallel points instead.
            if (start == null)
            {
                start = m_Par1;
            }

            if (end == null)
            {
                end = m_Par2;
            }

            // If those weren't defined either, try to calculate them now.
            if (end == null && Calculate())
            {
                start = m_Par1;
                end   = m_Par2;
            }

            // Any offset point
            if (m_OffsetPoint != null)
            {
                m_OffsetPoint.Draw(view, Color.Green);
            }

            // Everything else should draw in usual command-style colour.
            IDrawStyle style       = EditingController.Current.Style(Color.Magenta);
            IDrawStyle dottedStyle = new DottedStyle();

            // If the reference line is a curve, get the curve info.
            ArcFeature arc = m_Line.GetArcBase();

            if (arc != null)
            {
                bool iscw = arc.IsClockwise;

                // Reverse the direction if necessary.
                if (m_IsReversed)
                {
                    iscw = !iscw;
                }

                // Draw the parallel line (the rest of the circle being dotted).
                if (start != null)
                {
                    CircularArcGeometry parArc = new CircularArcGeometry(arc.Circle, start, end, iscw);
                    style.Render(view, parArc);

                    parArc.IsClockwise = !parArc.IsClockwise;
                    dottedStyle.Render(view, parArc);
                }
            }
            else
            {
                // PARALLEL IS STRAIGHT

                // If we've got something, figure out positions for dotted portion.
                if (start != null)
                {
                    // What's the max length of a diagonal crossing the entire screen?
                    double maxdiag = this.MaxDiagonal;

                    // What's the bearing from the start to the end of the parallel?
                    double bearing = Geom.BearingInRadians(start, end);

                    // Project to a point before the start end of the parallel, as
                    // well as a point after the end.
                    IPosition before = Geom.Polar(start, bearing + Constants.PI, maxdiag);
                    IPosition after  = Geom.Polar(end, bearing, maxdiag);

                    LineSegmentGeometry.Render(before, start, view, dottedStyle);
                    LineSegmentGeometry.Render(start, end, view, style);
                    LineSegmentGeometry.Render(end, after, view, dottedStyle);
                }
            }

            // Draw terminal positions (if defined).

            if (m_Term1 != null)
            {
                style.Render(view, m_Term1);
            }

            if (m_Term2 != null)
            {
                style.Render(view, m_Term2);
            }

            // The terminal lines.

            if (m_TermLine1 != null)
            {
                m_TermLine1.Render(view, style);
            }

            if (m_TermLine2 != null)
            {
                m_TermLine2.Render(view, style);
            }

            // Do the active dialog last so their stuff draws on top.
            if (m_ParDial != null)
            {
                m_ParDial.Draw();
            }

            if (m_TermDial1 != null)
            {
                m_TermDial1.Draw();
            }

            if (m_TermDial2 != null)
            {
                m_TermDial2.Draw();
            }
        }
Esempio n. 41
0
        /// <summary>
        /// Returns the intersection of the parallel with a line.
        /// </summary>
        /// <param name="refline">The reference line.</param>
        /// <param name="parpos">Search position that coincides with the parallel.</param>
        /// <param name="line">The line to intersect with.</param>
        /// <returns>The intersection (if any). In cases where the line intersects the
        /// parallel more than once, you get the intersection that is closest to the
        /// search position.</returns>
        internal static IPosition GetIntersect(LineFeature refline, IPosition parpos, LineFeature line)
        {
            // Make sure the intersection is undefined.
            IPosition result = null;

            // Return if the parallel point is undefined.
            if (parpos == null)
            {
                return(null);
            }

            // If the reference line is a circular arc (or a section based on an arc), get the curve info.
            ArcFeature arc = refline.GetArcBase();

            if (arc != null)
            {
                Circle         circle = arc.Circle;
                double         radius = circle.Radius;
                IPointGeometry centre = circle.Center;
                bool           iscw   = arc.IsClockwise;

                // Construct a circle that passes through the search position
                double parrad = Geom.Distance(centre, parpos);

                // Intersect the circle with the line to intersect with.
                IntersectionResult xres = new IntersectionResult(line);
                uint nx = xres.Intersect(centre, parrad);
                if (nx == 0)
                {
                    return(null);
                }

                // If there is only one intersection, that's what we want.
                if (nx == 1)
                {
                    return(xres.Intersections[0].P1);
                }

                // Get the intersection that is closest to the search position.
                xres.GetClosest(parpos, out result, 0.0);
            }
            else
            {
                // Get the bearing from the start to the end of the reference line.
                IPosition spos    = refline.StartPoint;
                IPosition epos    = refline.EndPoint;
                double    bearing = Geom.BearingInRadians(spos, epos);

                // Project the parallel line to positions that are a long way away (but make sure we
                // don't end up with negative numbers).
                Window searchWindow = new Window(line.Extent);
                searchWindow.Union(refline.Extent);
                searchWindow.Union(parpos);
                double dist = Geom.Distance(searchWindow.Min, searchWindow.Max);

                IPosition start = Geom.Polar(parpos, bearing + Constants.PI, dist);
                IPosition end   = Geom.Polar(parpos, bearing, dist);

                // Intersect the line segment with the line to intersect with.
                IntersectionResult xres = new IntersectionResult(line);
                IPointGeometry     sg   = new PointGeometry(start);
                IPointGeometry     eg   = new PointGeometry(end);
                uint nx = xres.Intersect(sg, eg);
                if (nx == 0)
                {
                    return(null);
                }

                // If there is only one intersection, that's what we want.
                if (nx == 1)
                {
                    return(xres.Intersections[0].P1);
                }

                // Get the intersection that is closest to the search position
                xres.GetClosest(parpos, out result, 0.0);
            }

            return(result);
        }
Esempio n. 42
0
 public bool Update(IPosition value)
 {
     return(mapper.Update(value));
 }
Esempio n. 43
0
 /// <summary>
 /// Возвращает общую стоимость позиции на момент входа
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public static double GetPositionEntryValue(this IPosition pos)
 {
     return(pos.EntryPrice * pos.GetPositionSize());
 }
Esempio n. 44
0
        /// <summary>
        /// Calculates positions that are parallel to a line.
        /// </summary>
        /// <param name="line">The reference line.</param>
        /// <param name="offset">The offset to the parallel, in ground units. Signed to denote
        /// which side (less than zero means it's to the left of the reference line).</param>
        /// <param name="sres">The position of the start of the parallel.</param>
        /// <param name="eres">The position of the end of the parallel.</param>
        /// <returns>True if positions calculated ok</returns>
        static bool Calculate(LineFeature line, Distance offset, out IPosition sres, out IPosition eres)
        {
            // No result positions so far.
            sres = eres = null;

            // Get the ends of the reference line.
            IPosition spos = line.StartPoint;
            IPosition epos = line.EndPoint;

            ISpatialSystem sys = CadastralMapModel.Current.SpatialSystem;

            // If the reference line is a circular arc, get the curve info.
            ArcFeature arc = line.GetArcBase();

            if (arc != null)
            {
                Circle    circle = arc.Circle;
                double    radius = circle.Radius;
                IPosition centre = circle.Center;
                bool      iscw   = arc.IsClockwise;

                // Get the midpoint of the curve. The reduction of the
                // ground distance will be along the line that goes
                // from the centre of the circle & through this position.

                ILength   len     = line.Length;
                ILength   halfLen = new Length(len.Meters * 0.5);
                IPosition middle;
                line.LineGeometry.GetPosition(halfLen, out middle);

                // Get the bearing from the centre to the mid-position
                // and use that to reduce the offset to the mapping plane.
                double bearing = Geom.BearingInRadians(centre, middle);
                double offdist = offset.GetPlanarMetric(middle, bearing, sys);

                // No parallel if the offset exceeds the radius.
                // if ( offdist > radius ) return FALSE;

                // Calculate the parallel points.
                double sbear = Geom.BearingInRadians(centre, spos);
                sres = Geom.Polar(centre, sbear, offdist + radius);

                double ebear = Geom.BearingInRadians(centre, epos);
                eres = Geom.Polar(centre, ebear, offdist + radius);
            }
            else
            {
                // Get the bearing.of the line.
                double bearing = Geom.BearingInRadians(spos, epos);

                // Get the planar distance for a perpendicular line that passes
                // through the midpoint of the reference line. The planar distance
                // will have the same sign as the ground value.

                IPosition middle = Position.CreateMidpoint(spos, epos);
                bearing += Constants.PIDIV2;
                double offdist = offset.GetPlanarMetric(middle, bearing, sys);

                // Calculate the parallel points.
                sres = Geom.Polar(spos, bearing, offdist);
                eres = Geom.Polar(epos, bearing, offdist);
            }

            return(true);
        }
Esempio n. 45
0
        /// <summary>
        /// Defines the geometry for this leg.
        /// </summary>
        /// <param name="ctx">The context in which the geometry is being calculated</param>
        /// <param name="terminal">The position for the start of the leg. Updated to be
        /// the position for the end of the leg.</param>
        /// <param name="bearing">The bearing at the end of the previous leg. Updated for this leg.</param>
        /// <param name="sfac">Scale factor to apply to distances.</param>
        //abstract internal void CreateGeometry(EditingContext ctx, ref IPosition terminal, ref double bearing, double sfac);

        abstract internal bool Rollforward(ref PointFeature insert, PathOperation op,
                                           ref IPosition terminal, ref double bearing, double sfac);
Esempio n. 46
0
        /// <summary>
        /// Calculates positions that are parallel to a line.
        /// </summary>
        /// <param name="line">The reference line.</param>
        /// <param name="offpoint">The point the parallel must pass through.</param>
        /// <param name="sres">The position of the start of the parallel.</param>
        /// <param name="eres">The position of the end of the parallel.</param>
        /// <returns>True if positions calculated ok</returns>
        internal static bool Calculate(LineFeature refline, PointFeature offpoint, out IPosition sres, out IPosition eres)
        {
            // No result positions so far.
            sres = eres = null;

            // Get the ends of the reference line.
            IPosition spos = refline.StartPoint;
            IPosition epos = refline.EndPoint;

            // If the reference line is a circular arc
            ArcFeature arc = refline.GetArcBase();

            if (arc != null)
            {
                // Get the curve info
                Circle    circle = arc.Circle;
                double    radius = circle.Radius;
                IPosition centre = circle.Center;
                bool      iscw   = arc.IsClockwise;

                // Get the (planar) distance from the centre of the
                // circle to the offset point.
                double offdist = Geom.Distance(offpoint, centre);

                // Project the BC/EC radially.
                double sbear = Geom.BearingInRadians(centre, spos);
                sres = Geom.Polar(centre, sbear, offdist);

                double ebear = Geom.BearingInRadians(centre, epos);
                eres = Geom.Polar(centre, ebear, offdist);
            }
            else
            {
                double bearing = Geom.BearingInRadians(spos, epos);

                // Get the perpendicular distance (signed) from the offset point
                // to the reference line.
                double offdist = Geom.SignedDistance(spos.X, spos.Y, bearing, offpoint.X, offpoint.Y);

                // Calculate the parallel points.
                bearing += Constants.PIDIV2;
                sres     = Geom.Polar(spos, bearing, offdist);
                eres     = Geom.Polar(epos, bearing, offdist);
            }

            return(true);
        }
Esempio n. 47
0
 /// <summary>
 /// Obtains the geometry for spans along this leg (to be called only via implementations of <see cref="GetSections"/>).
 /// </summary>
 /// <param name="start">The position for the start of the leg.
 /// <param name="bearing">The bearing of the leg.</param>
 /// <param name="sfac">Scale factor to apply to distances.</param>
 /// <param name="spans">Information for the spans coinciding with this leg.</param>
 /// <returns>The sections along this leg</returns>
 abstract internal ILineGeometry[] GetSpanSections(IPosition start, double bearing, double sfac, SpanInfo[] spans);
Esempio n. 48
0
        /// <summary>
        /// Returns the intersection of the parallel with a line. A prior call to Calculate is required.
        /// </summary>
        /// <param name="line">The line to intersect with.</param>
        /// <param name="isEndParallel">Is the intersection biased towards the end of the parallel?</param>
        /// <returns>The intersection (if any). In cases where the line intersects the parallel
        /// more than once, you get an arbitrary intersection.</returns>
        internal IPosition GetIntersect(LineFeature line, bool isEndParallel)
        {
            // Make sure the intersection is undefined.
            IPosition result = null;

            // Return if the parallel points are undefined.
            if (m_Par1 == null || m_Par2 == null)
            {
                return(null);
            }

            // If the reference line is a circular arc, get the curve info.
            ArcFeature arc = m_Line.GetArcBase();

            if (arc != null)
            {
                Circle         circle = arc.Circle;
                double         radius = circle.Radius;
                IPointGeometry centre = circle.Center;
                bool           iscw   = arc.IsClockwise;

                // Construct a circle that passes through
                // the parallel points (assumed to have the same distance
                // with respect to the centre of the circle).
                double parrad = Geom.Distance(centre, m_Par1);

                // Intersect the circle with the line to intersect with.
                IntersectionResult xres = new IntersectionResult(line);
                uint nx = xres.Intersect(centre, parrad);
                if (nx == 0)
                {
                    return(null);
                }

                // If there is only one intersection, that's what we want.
                if (nx == 1)
                {
                    return(xres.Intersections[0].P1);
                }

                // Get the intersection that is closest to the parallel point
                // that has the bias.
                if (isEndParallel)
                {
                    xres.GetClosest(m_Par2, out result, 0.0);
                }
                else
                {
                    xres.GetClosest(m_Par1, out result, 0.0);
                }
            }
            else
            {
                // Get the bearing from the start to the end of the parallel.
                double bearing = Geom.BearingInRadians(m_Par1, m_Par2);

                // Get the ground dimension of a line that crosses the
                // extent of the draw window.
                double dist = MaxDiagonal;

                // Project the parallel line to positions that are well
                // beyond the draw extent.
                IPosition start = Geom.Polar(m_Par1, bearing + Constants.PI, dist);
                IPosition end   = Geom.Polar(m_Par2, bearing, dist);

                // Intersect the line segment with the line to intersect with.
                IntersectionResult xres = new IntersectionResult(line);
                IPointGeometry     sg   = PointGeometry.Create(start);
                IPointGeometry     eg   = PointGeometry.Create(end);
                uint nx = xres.Intersect(sg, eg);
                if (nx == 0)
                {
                    return(null);
                }

                // If there is only one intersection, that's what we want.
                if (nx == 1)
                {
                    return(xres.Intersections[0].P1);
                }

                // Get the intersection that is closest to the parallel point
                // that has the bias.
                if (isEndParallel)
                {
                    xres.GetClosest(m_Par2, out result, 0.0);
                }
                else
                {
                    xres.GetClosest(m_Par1, out result, 0.0);
                }
            }

            return(result);
        }
Esempio n. 49
0
        /// <summary>
        /// Intersects this direction with a circle. This may lead to 0, 1, or 2 intersections.
        /// If 2 intersections are found, the first intersection is defined as the one that is
        /// closer to the origin of the direction object.
        /// </summary>
        /// <param name="circle">The circle to intersect with.</param>
        /// <param name="x1">The 1st intersection (if any). Returned as null if no intersection.</param>
        /// <param name="x2">The 2nd intersection (if any). Returned as null if no intersection.</param>
        /// <returns>The number of intersections found.</returns>
        internal uint Intersect(ICircleGeometry circle, out IPosition x1, out IPosition x2)
        {
            // Initialize both intersections.
            x1 = x2 = null;

            // Get the origin of the direction & its bearing.
            IPosition start   = this.StartPosition;
            double    bearing = this.Bearing.Radians;

            // Get the centre of the circle & its radius.
            IPosition center = circle.Center;
            double    radius = circle.Radius;

            // The equation of each line is given in parametric form as:
            //
            //		x = xo + f * r
            //		y = yo + g * r
            //
            // where	xo,yo is the from point
            // and		f = sin(bearing)
            // and		g = cos(bearing)
            // and		r is the position ratio

            double g    = Math.Cos(bearing);
            double f    = Math.Sin(bearing);
            double fsq  = f * f;
            double gsq  = g * g;
            double fgsq = fsq + gsq;

            if (fgsq < Double.Epsilon)   // Should be impossible
            {
                return(0);
            }

            double startx = start.X;
            double starty = start.Y;
            double dx     = center.X - startx;
            double dy     = center.Y - starty;
            double fygx   = f * dy - g * dx;
            double root   = radius * radius * fgsq - fygx * fygx;

            // Check for no intersection.
            if (root < -Constants.TINY)
            {
                return(0);
            }

            // Check for tangential intersection (but don't count a
            // tangent if it precedes the start of the direction line).

            double fxgy = f * dx + g * dy;
            double prat;

            if (root < Constants.TINY)
            {
                prat = fxgy / fgsq;
                if (prat < 0.0)
                {
                    return(0);
                }
                x1 = new Position(startx + f * prat, starty + g * prat);
                return(1);
            }

            // We have two intersections, but one or both of them could
            // precede the start of the direction line.

            root = Math.Sqrt(root);
            double fginv = 1.0 / fgsq;
            double prat1 = (fxgy - root) * fginv;
            double prat2 = (fxgy + root) * fginv;

            // No intersections if both are prior to start of direction.
            if (prat1 < 0.0 && prat2 < 0.0)
            {
                return(0);
            }

            // If both intersections are valid ...
            prat = Math.Min(prat1, prat2);
            if (prat >= 0.0)
            {
                x1   = new Position(startx + f * prat, starty + g * prat);
                prat = Math.Max(prat1, prat2);
                x2   = new Position(startx + f * prat, starty + g * prat);
                return(2);
            }

            // So only one is valid ...
            prat = Math.Max(prat1, prat2);
            x1   = new Position(startx + f * prat, starty + g * prat);
            return(1);
        }
Esempio n. 50
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Point" /> class.
 /// </summary>
 /// <param name="coordinates">The Position.</param>
 public Point(IPosition coordinates)
 {
     Coordinates = coordinates ?? throw new ArgumentNullException(nameof(coordinates));
 }
Esempio n. 51
0
        /// <summary>
        /// Intersects this direction with a line.
        /// </summary>
        /// <param name="line">The line to intersect with.</param>
        /// <param name="closeTo">The point that the intersection should be closest to.
        /// Specify null if you don't care. In that case, if there are multiple intersections,
        /// you get the intersection that is closest to one of 3 points: the start of the
        /// direction line, the start of the line, or the end of the line.</param>
        /// <param name="xsect">The position of the intersection (if any). Null if not found.</param>
        /// <param name="closest">The default point that is closest to the intersection. Null if
        /// intersection wasn't found.</param>
        /// <returns>True if intersection was found.</returns>
        internal bool Intersect(LineFeature line
                                , PointFeature closeTo
                                , out IPosition xsect
                                , out PointFeature closest)
        {
            // Initialize results
            xsect   = null;
            closest = null;

            // Define the length of the direction line as the length
            // of a diagonal that crosses the map's extent.
            IWindow mapWin = SpatialController.Current.MapModel.Extent;

            Debug.Assert(mapWin != null);

            // If the window is currently undefined (e.g. during deserialization),
            // just use a really big distance.
            // TODO: This is a hack, but hopefully it may be shortlived, because
            // new logic is in the works for handling updates.
            double dist = (mapWin.IsEmpty ? 100000.0 : Geom.Distance(mapWin.Min, mapWin.Max));

            // Define the position of the direction line. DON'T use the from-
            // point, because there may be an offset to the direction.
            IPosition fromPos = this.StartPosition;
            IPosition toPos   = Geom.Polar(fromPos, this.Bearing.Radians, dist);

            // Construct a corresponding line segment.
            ITerminal       start = new FloatingTerminal(fromPos);
            ITerminal       end   = new FloatingTerminal(toPos);
            SegmentGeometry seg   = new SegmentGeometry(start, end);

            // Intersect the line segment with the other one.
            IntersectionResult xres = new IntersectionResult(line);
            uint nx = seg.Intersect(xres);

            if (nx == 0)
            {
                return(false);
            }

            // Determine which terminal point is the best. Start with the
            // ends of the intersected line.
            double mindsq = Double.MaxValue;

            if (xres.GetCloserPoint(line.StartPoint, ref mindsq, ref xsect))
            {
                closest = line.StartPoint;
            }

            if (xres.GetCloserPoint(line.EndPoint, ref mindsq, ref xsect))
            {
                closest = line.EndPoint;
            }

            // Check whether the direction from-point is any closer (the position may be
            // different from the start of the direction line, because the direction may
            // have an offset).

            if (xres.GetCloserPoint(this.From, ref mindsq, ref xsect))
            {
                closest = this.From;
            }

            // If a close-to point has been specified, that overrides
            // everything else (however, doing the above has the desired
            // effect of defining the best of the default points). In
            // this case, we allow an intersection that coincides with
            // the line being intersected.
            // -- actually, we don't, since GetClosest uses a > 0 test

            if (closeTo != null)
            {
                xres.GetClosest(closeTo, out xsect, 0.0);

                /*
                 * IPosition xCloseTo;
                 * xres.GetClosest(closeTo, out xCloseTo, 0.0);
                 *
                 * if (xCloseTo != null)
                 *  xsect = xCloseTo;
                 */
            }

            return(xsect != null);
        }
Esempio n. 52
0
 public PositionController(IPosition position)
 {
     _position = position;
 }
Esempio n. 53
0
 /// <summary>
 /// Constructor for creating a square window centered at a specific position
 /// </summary>
 /// <param name="center">The center of the extent</param>
 /// <param name="size">The width and height of the extent</param>
 public Window(IPosition center, double size)
     : this(center.X - size * 0.5, center.Y - size * 0.5, center.X + size * 0.5, center.Y + size * 0.5)
 {
 }
 public bool Intersects(IPosition other)
 {
     return(this.X == other.X && this.Y == other.Y);
 }
Esempio n. 55
0
 /// <summary>
 /// Creates a <c>Window</c> that coincides with the supplied positions
 /// </summary>
 /// <param name="p">The position the extent will cover</param>
 public Window(IPosition p)
     : this(p, p)
 {
 }
 // A new CDLL node is a one-element circular list
 public CDLL(IPosition val)
 {
     this.val = val; next = prev = this;
 }
Esempio n. 57
0
 public ICell[,] ChangeCellAtPosition(IPosition position, char cellChar)
 {
     this.cells[position.Row, position.Column].ValueChar = cellChar;
     return(this.cells);
 }
 private double Area2(IPosition p0, IPosition p1, IPosition p2)
 {
     return(p0.GetX() * (p1.GetY() - p2.GetY()) + p1.GetX() * (p2.GetY() - p0.GetY()) + p2.GetX() * (p0.GetY() - p1.GetY()));
 }
 private static void swap(IPosition[] arr, int s, int t)
 {
     IPosition tmp = arr[s]; arr[s] = arr[t]; arr[t] = tmp;
 }
Esempio n. 60
0
 private double ComissionDelegate(IPosition pos, double price, double shares, bool isEntry, bool isPart)
 {
     return(shares * Commission);
 }