public void ExpandToArea() { var polygon = new Polygon ( new[] { new Vector3(), new Vector3(4, 0), new Vector3(4, 4), new Vector3(0, 4) } ); var within = new Polygon ( new[] { new Vector3(-5, -5), new Vector3(20, -5), new Vector3(20, 30), new Vector3(-5, 30) } ); var among = new List <Polygon> { new Polygon( new [] { new Vector3(3, 1), new Vector3(7, 1), new Vector3(7, 5), new Vector3(3, 5) }), new Polygon( new[] { new Vector3(1, 3), new Vector3(2, 3), new Vector3(2, 6), new Vector3(1, 6), }) }; var coordGrid = new CoordGrid(within); polygon = Shaper.ExpandtoArea(polygon, 20, within, among); Debug.WriteLine(polygon.Area); var spaces = new List <Space> { new Space(polygon, 0, 2, new Material("blue", Palette.Blue)), new Space(within, 0, 0.1, new Material("aqua", Palette.Aqua)), new Space(among[0], 0, 2, new Material("yellow", Palette.Yellow)), new Space(among[1], 0, 2, new Material("green", Palette.Green)) }; var model = new Model(); foreach (Space space in spaces) { model.AddElement(space); } model.SaveGlb("expandToArea.glb"); }
public void AvailableRandom() { var perimeter = new Polygon ( new[] { new Vector3(0, 0), new Vector3(60, 0), new Vector3(60, 36), new Vector3(0, 36) } ); var grid = new CoordGrid(perimeter); var allocate = new Polygon ( new[] { new Vector3(10, 10), new Vector3(20, 10), new Vector3(20, 20), new Vector3(10, 20) } ); grid.Allocate(allocate); var point = grid.AvailableRandom(); Assert.Contains(point, grid.Available); Assert.Equal(42.0, point.X); Assert.Equal(8.0, point.Y); }
public void Allocate() { var perimeter = new Polygon ( new[] { new Vector3(0, 0), new Vector3(60, 0), new Vector3(60, 36), new Vector3(0, 36) } ); var grid = new CoordGrid(perimeter); Assert.Equal(2257, grid.Available.Count); var allocate = new Polygon ( new[] { new Vector3(10, 10), new Vector3(20, 10), new Vector3(20, 20), new Vector3(10, 20) } ); grid.Allocate(allocate); Assert.Equal(2136, grid.Available.Count); }
public void DrawPointArray(int id, Color color) { Vector2 point, point2; DrawTools.LineColor = color; IEnumerator <PriceFluctuation> it = visibleFluctuations.GetEnumerator(); while (it.MoveNext() && (!it.Current.ExtraData.ContainsKey(id) || !(it.Current.ExtraData[id] is float))) { ; } if (!it.Current.ExtraData.ContainsKey(id)) { return; } point = cam.WorldToScreenPoint(new Vector2(CoordGrid.FromDateToXAxis(it.Current.PeriodBegin), CoordGrid.FromPriceToYAxis((float)it.Current.ExtraData[id]))); while (it.MoveNext()) { if (it.Current.ExtraData[id] is float) { point2 = cam.WorldToScreenPoint(new Vector2(CoordGrid.FromDateToXAxis(it.Current.PeriodBegin), CoordGrid.FromPriceToYAxis((float)it.Current.ExtraData[id]))); DrawTools.DrawLine(point, point2, false); point = point2; } } }
//System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); private void ScaleChart() { if (!IsSettingsSet) { return; } double highestPriceOnScreen = CoordGrid.FromYAxisToPrice(worldPointInRightUpCorner.y); double lowestPriceOnScreen = CoordGrid.FromYAxisToPrice(worldPointInLeftDownCorner.y); double highestPrice = visibleFluctuations.Max(f => f.High); double lowestPrice = visibleFluctuations.Min(f => f.Low); double priceRange = highestPrice - lowestPrice; float new_y = CoordGrid.FromPriceToYAxis((float)(lowestPrice + priceRange / 2)); if (Math.Abs(new_y / cam.transform.position.y - 1) > 1e-4) { cam.transform.position = new Vector3(cam.transform.position.x, new_y, cam.transform.position.z); } if (highestPrice != lowestPrice) { CoordGrid.Scale *= (1 - chartOffsetFromVerticalBorders) * (float)((highestPriceOnScreen - lowestPriceOnScreen) / priceRange); } }
private IEnumerable <decimal> GetVisiblePricesList() { //Вывод цен на экран decimal lowestPrice = (decimal)CoordGrid.FromYAxisToPrice(worldPointInLeftDownCorner.y); decimal highestPrice = (decimal)CoordGrid.FromYAxisToPrice(worldPointInRightUpCorner.y); List <decimal> pricesList = Ariphmetic.DividePriceRangeByKeyPoints(lowestPrice, highestPrice, priceTextPool.FieldsAmount); return(pricesList); }
public void AllocatedNearTo() { var perimeter = new Polygon ( new[] { new Vector3(0, 0), new Vector3(60, 0), new Vector3(60, 36), new Vector3(0, 36) } ); var allocated = new List <Polygon> { new Polygon ( new [] { new Vector3(), new Vector3(8, 0), new Vector3(8, 9), new Vector3(0, 9) } ), new Polygon ( new [] { new Vector3(52, 0), new Vector3(60, 0), new Vector3(60, 6), new Vector3(52, 6) } ), new Polygon ( new [] { new Vector3(24, 33), new Vector3(32, 33), new Vector3(32, 36), new Vector3(24, 36) } ) }; var grid = new CoordGrid(perimeter); foreach (Polygon polygon in allocated) { grid.Allocate(polygon); } var nearPoint = grid.AllocatedNearTo(new Vector3(26.6, 34.1)); Assert.Equal(27, nearPoint.X); Assert.Equal(36, nearPoint.Y); }
public void DrawGrid(IEnumerable <DateTime> dateList, IEnumerable <decimal> pricesList) { if (!IsSettingsSet) { return; } DrawTools.LineColor = gridColor; DrawTools.dashLength = 0.05f; DrawTools.gap = 0.07f; priceTextPool.CleanPool(); float yPoint; foreach (var price in pricesList) { yPoint = CoordGrid.FromPriceToYAxis((float)price); yPoint = cam.WorldToScreenPoint(new Vector2(0, yPoint)).y; priceTextPool.SetText( price.ToString("F8"), yPoint, TextPoolManager.ShiftBy.Vertical ); Vector2 pricePoint1 = new Vector2(cam.WorldToScreenPoint(worldPointInLeftDownCorner).x, yPoint); Vector2 pricePoint2 = new Vector2(cam.WorldToScreenPoint(worldPointInRightUpCorner).x, yPoint); DrawTools.DrawOnePixelLine(pricePoint1, pricePoint2, true); } dateTextPool.CleanPool(); foreach (var date in dateList) { float dateLine = CoordGrid.FromDateToXAxis(date); dateLine = cam.WorldToScreenPoint(new Vector2(dateLine, 0)).x; dateTextPool.SetText( date.ChartStringFormat(), dateLine, TextPoolManager.ShiftBy.Horizontal ); Vector2 datePoint1 = new Vector2(dateLine, cam.pixelRect.min.y); Vector2 datePoint2 = new Vector2(dateLine, cam.pixelRect.max.y); DrawTools.DrawOnePixelLine(datePoint1, datePoint2, true); } }
private IEnumerable <DateTime> GetVisibleDatesList() { //Вычисляем точки на временнОй сетке и отрисовываем их DateTime dt0 = CoordGrid.FromXAxisToDate(worldPointInLeftDownCorner.x); DateTime dt1 = CoordGrid.FromXAxisToDate(worldPointInRightUpCorner.x); if (CoordGrid is CoordinateGrid) { dt0 = (CoordGrid as CoordinateGrid).DateCorrection(dt0, dt1); } IEnumerable <DateTime> dateList = DateTimeTools.DividePeriodByKeyPoints(dt0, dt1, dateTextPool.FieldsAmount); return(dateList); }
public bool CanMoveFurther(Vector3 fromPoint, Vector3 byStep) { float x0 = CoordGrid.FromDateToXAxis(ChartDataManager.WorkBeginTime); float x1 = CoordGrid.FromDateToXAxis(ChartDataManager.WorkEndTime); Vector3 nextpoint = fromPoint + byStep; if ((nextpoint.x > x0 && nextpoint.x < x1) || (nextpoint.x <= x0 && byStep.x >= 0) || (nextpoint.x >= x1 && byStep.x <= 0)) { return(true); } return(false); }
public void CoordGrid() { var perimeter = new Polygon ( new[] { new Vector3(0, 0), new Vector3(60, 0), new Vector3(60, 36), new Vector3(0, 36) } ); var grid = new CoordGrid(perimeter); Assert.Equal(2257, grid.Available.Count); }
public void Update() { Vector3 pointerWorldPos; Vector2 pointerScreenPos; ChartDrawer.Instance.GetWorldPointerPosition(out pointerScreenPos, out pointerWorldPos); if (cachedXPos != Mathf.Round(pointerWorldPos.x)) { cachedXPos = Mathf.Round(pointerWorldPos.x); DateTime fluctuationDate = CoordGrid.FromXAxisToDate(cachedXPos); if (OnFluctuationSelect != null) { OnFluctuationSelect(ChartDataManager.GetPriceFluctuation(fluctuationDate)); } } }
public void AvailableNearTo() { var perimeter = new Polygon ( new[] { new Vector3(0, 0), new Vector3(60, 0), new Vector3(60, 36), new Vector3(0, 36) } ); var grid = new CoordGrid(perimeter); var nearPoint = grid.AvailableNearTo(new Vector3(50.6, 40.1)); Assert.Equal(51, nearPoint.X); Assert.Equal(36, nearPoint.Y); }
public void AvailableMin() { var perimeter = new Polygon ( new[] { new Vector3(5, 5), new Vector3(60, 5), new Vector3(60, 36), new Vector3(5, 36) } ); var grid = new CoordGrid(perimeter); var min = grid.AvailableMin(); Assert.Equal(5, min.X); Assert.Equal(5, min.Y); }
public void AvailableMax() { var perimeter = new Polygon ( new[] { new Vector3(5, 5), new Vector3(60, 5), new Vector3(60, 36), new Vector3(5, 36) } ); var grid = new CoordGrid(perimeter); var max = grid.AvailableMax(); Assert.Equal(60, max.X); Assert.Equal(36, max.Y); }
void Update() { worldPointInLeftDownCorner = cam.ViewportToWorldPoint(cachedZero); worldPointInRightUpCorner = cam.ViewportToWorldPoint(cachedOne); visibleStartDate = CoordGrid.FromXAxisToDate(worldPointInLeftDownCorner.x).FloorToTimeFrame(chartDataManager.TFrame); if (visibleStartDate < chartDataManager.WorkBeginTime) { visibleStartDate = chartDataManager.WorkBeginTime; } visibleEndDate = CoordGrid.FromXAxisToDate(worldPointInRightUpCorner.x).UpToNextFrame(chartDataManager.TFrame); if (visibleEndDate > chartDataManager.WorkEndTime) { visibleEndDate = chartDataManager.WorkEndTime; } if (visibleStartDate != cachedStart || visibleEndDate != cachedEnd) { visibleFluctuations = chartDataManager.GetPriceFluctuationsByTimeFrame(visibleStartDate, visibleEndDate); } cachedStart = visibleStartDate; cachedEnd = visibleEndDate; if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow)) { autoscaleToggle.isOn = false; } if (NeedToBeUpdated)//Оптимизация { if (Autoscale) { ScaleChart(); } datesList = GetVisibleDatesList(); pricesList = GetVisiblePricesList(); DrawChart(); } }
internal Vector3 GetLastPoint() { if (!IsSettingsSet) { return(Vector3.zero); } float x = CoordGrid.FromDateToXAxis(chartDataManager.WorkEndTime); float y; if (ChartDrawer.Instance.Autoscale) { y = cameraTransform.position.y; } else { y = CoordGrid.FromPriceToYAxis((float)chartDataManager.GetPriceFluctuation(chartDataManager.WorkEndTime).Close); } return(new Vector3(x, y)); }
public void DrawVolume(Rect camRect) { if (!IsSettingsSet) { return; } float worldRealToScreen = (CoordGrid.FromDateToXAxis(visibleEndDate) - CoordGrid.FromDateToXAxis(visibleStartDate)) / (worldPointInRightUpCorner.x - worldPointInLeftDownCorner.x); int count = DateTimeTools.CountFramesInPeriod(chartDataManager.TFrame, visibleStartDate, visibleEndDate, TimeSpan.Zero); float pixelLenghtFrame = camRect.width * worldRealToScreen / count; float maxVolume = (float)visibleFluctuations.Max(x => x.Volume); //Если свечка видна только частично, то необходимо смещать отрисовку объёма на равную долю видимости float diff = (worldPointInLeftDownCorner.x - CoordGrid.FromDateToXAxis(visibleStartDate)) * camRect.width / (worldPointInRightUpCorner.x - worldPointInLeftDownCorner.x); Vector2 barLeftDownCorner = camRect.min - new Vector2(diff + pixelLenghtFrame / 2, 0); Vector2 barRightUpCorner; Vector2 bordersOffset = new Vector2((20 / count < 1 ? 1 : 20 / count), 0); if (chartDataManager.WorkBeginTime > visibleStartDate) { int shift = DateTimeTools.CountFramesInPeriod(chartDataManager.TFrame, visibleStartDate, chartDataManager.WorkBeginTime, TimeSpan.Zero); barLeftDownCorner += new Vector2(shift * pixelLenghtFrame, 0); } foreach (var fluctuation in visibleFluctuations) { float pixelHeightFrame = (float)fluctuation.Volume / maxVolume * camRect.height; barRightUpCorner = barLeftDownCorner + new Vector2(pixelLenghtFrame, pixelHeightFrame); DrawTools.DrawRectangle(barLeftDownCorner + bordersOffset, barRightUpCorner - bordersOffset, fluctuation.Close - fluctuation.Open > 0 ? volumeUpColor : volumeDownColor); barLeftDownCorner = new Vector2(barRightUpCorner.x, camRect.min.y); } }