public static void Main() { var pointInputed = ConsoleLogic.ReadInput(); var directionsInputed = ConsoleLogic.ReadInput(); IMovable point = new MovingPoint(); var startingPoint = point.GetStartingPoint(pointInputed); var resultPointAfterMoving = point.Move(startingPoint, directionsInputed); ConsoleLogic.WriteAnswer(resultPointAfterMoving.X,resultPointAfterMoving.Y); }
public void Move(MovingPoint x, Size areaSize, double interval) { if (x.Position.X > areaSize.Width && x.Speed.X > 0) x.Speed.X = -x.Speed.X; if (x.Position.Y > areaSize.Height && x.Speed.Y > 0) x.Speed.Y = -x.Speed.Y; if (x.Position.X < 0 && x.Speed.X < 0) x.Speed.X = -x.Speed.X; if (x.Position.Y < 0 && x.Speed.Y < 0) x.Speed.Y = -x.Speed.Y; x.Position.X += x.Speed.X * interval; x.Position.Y += x.Speed.Y * interval; }
public void Move(MovingPoint x, Size areaSize, double interval) { if (x.Position.X > areaSize.Width && x.Speed.X > 0) { x.Speed.X = -x.Speed.X; } if (x.Position.Y > areaSize.Height && x.Speed.Y > 0) { x.Speed.Y = -x.Speed.Y; } if (x.Position.X < 0 && x.Speed.X < 0) { x.Speed.X = -x.Speed.X; } if (x.Position.Y < 0 && x.Speed.Y < 0) { x.Speed.Y = -x.Speed.Y; } x.Position.X += x.Speed.X * interval; x.Position.Y += x.Speed.Y * interval; }
private void UpdateMovingPoint(MovingPoint p, double elapsedMs) { var maxX = ViewportWidth(); var maxY = ViewportHeight(); if (p.Loc.X > maxX) { p.Loc = new Point(maxX, p.Loc.Y); } if (p.Loc.Y > maxY) { p.Loc = new Point(p.Loc.X, maxY); } var newLoc = p.Loc + p.Speed * (elapsedMs / 1000) * p.Direction; var hitBounds = false; if (newLoc.X < 0 || newLoc.X > maxX) { p.Direction = new Vector(-p.Direction.X, p.Direction.Y); hitBounds = true; } if (newLoc.Y < 0 || newLoc.Y > maxY) { p.Direction = new Vector(p.Direction.X, -p.Direction.Y); hitBounds = true; } if (hitBounds) { p.Loc = p.Loc + p.Speed * (elapsedMs / 1000) * p.Direction; } else { p.Loc = newLoc; } }
public void SetRandom(MovingPoint point, Size areaSize) { Assert.Assigned(point); SetRandomPosition(ref point.Position, areaSize); SetRandomSpeed(ref point.Speed, areaSize); }
public void ResizeObjects(Point dest) { Point offset; offset = new Point(dest.X - MovingPoint.X, dest.Y - MovingPoint.Y); foreach (DrawableObject obj in SelectedObjects) { obj.ResizeCheck(ref offset, ResizingType); } foreach (DrawableObject obj in SelectedObjects) { if (obj is Transition) { PreviousObject = OnObject; OnObject = draw.GetOnObject(dest); OnTransition = (Transition)obj; if (OnObject == null) { offset = new Point(dest.X - MovingPoint.X, dest.Y - MovingPoint.Y); OnTransition.Resize(offset, ResizingType); if (ResizingType == ResizingTypes.Spline0) { OnTransition.StartObject = null; } else if (ResizingType == ResizingTypes.Spline3) { OnTransition.EndObject = null; } } else if (ResizingType == ResizingTypes.Spline0) { if ((obj is Transition && (OnObject is End || OnObject is Abort || OnObject is Relation)) || (obj is SuperTransition && (OnObject is Alias || OnObject is SimpleState || OnObject is StateAlias)) || (OnObject is Origin && OnObject.OutTransitions.Length != 0 && OnTransition != OnObject.OutTransitions.First())) { OnObject = null; return; } else { double angle; OnObject.Intersect(dest, ref StartDrawPoint, ref OnTransition.StartAngle); offset = new Point(StartDrawPoint.X - MovingPoint.X, StartDrawPoint.Y - MovingPoint.Y); OnTransition.Resize(offset, ResizingType); OnTransition.OutDir(OnObject.OutDir(StartDrawPoint, out angle), 1); } if (PreviousObject != OnObject) { OnTransition.StartObject = OnObject; } } else if (ResizingType == ResizingTypes.Spline3) { if (OnObject is Origin || OnObject is Relation) { OnObject = null; return; } else { double angle; OnObject.Intersect(dest, ref StartDrawPoint, ref OnTransition.EndAngle); offset = new Point(StartDrawPoint.X - MovingPoint.X, StartDrawPoint.Y - MovingPoint.Y); OnTransition.Resize(offset, ResizingType); OnTransition.OutDir(OnObject.OutDir(StartDrawPoint, out angle), 2); } if (PreviousObject != OnObject) { OnTransition.EndObject = OnObject; } } } else if (obj is SimpleState || obj is StateAlias) { State oState = (State)obj; obj.Resize(offset, ResizingType); foreach (Transition oTransition in oState.InTransitions) { oTransition.MoveEndTo(oState.PointFromAngle(oTransition.EndAngle)); } foreach (Transition oTransition in oState.OutTransitions) { oTransition.MoveStartTo(oState.PointFromAngle(oTransition.StartAngle)); } } else if (obj is SuperState) { SuperState oState = (SuperState)obj; obj.Resize(offset, ResizingType); foreach (Transition oTransition in oState.InTransitions) { oTransition.MoveEndTo(oState.PointFromOffset(ResizingType, oTransition.EndPoint, oTransition.EndAngle)); } foreach (Transition oTransition in oState.OutTransitions) { oTransition.MoveStartTo(oState.PointFromOffset(ResizingType, oTransition.StartPoint, oTransition.StartAngle)); } } else if (obj is Nested) { Nested oState = (Nested)obj; obj.Resize(offset, ResizingType); foreach (Transition oTransition in oState.InTransitions) { oTransition.MoveEndTo(oState.PointFromOffset(ResizingType, oTransition.EndPoint, oTransition.EndAngle)); } foreach (Transition oTransition in oState.OutTransitions) { oTransition.MoveStartTo(oState.PointFromOffset(ResizingType, oTransition.StartPoint, oTransition.StartAngle)); } } else { obj.Resize(offset, ResizingType); } } MovingPoint.Offset(offset); }
private void AddLiveCursorPoint(Point position) { _lastCursorPoint = new MovingPoint(position); _lastCursorPointIdx = _points.Count; _points.Add(_lastCursorPoint); }