/// <summary> /// Initialize a CA with the specified values. compileDelta() must be run before the CA is usable. /// </summary> /// <param name="n">The number of states of this CA</param> /// <param name="d">The default state of this CA. Must be between 0 and /// n (will be adjusted otherwise).</param> /// <param name="neighbors">Array of points representing the neighborhood set of this CA, if applicable</param> /// <param name="delta">A string representing the delta function to be compiled</param> public CA(int n, uint d, CPoint[] neighbors, string delta) { numStates = n; defaultState = (d < 0) ? 0 : ((d >= n) ? (uint)n-1 : d); neighborhood = neighbors; deltaStr = delta; reverseNeighborhood(); }
void LeftButtonDblClk(UINT nFlags, CPoint point) { CShowBatterDlg dlg; dlg.m_pBatter = m_pSlot->m_pBatter; dlg.DoModal(); }
// create a building object of a specific type public Building CreateBuilding(BuildingType type, CPoint position) { if (type > BuildingType.CONVERSION) return CreateConversionBuilding(type, position); else if (type > BuildingType.PRODUCTION) return CreateProductionBuilding(type, position); else return null; }
public ConstructionHandler(BuildingType type, ResourceType[] costTypes, uint[] costAmounts, float constructionTime, CPoint position) { this.Location = new ConstructionBuilding(this, costTypes, costAmounts, constructionTime, position); this.BuildingType = type; // request required resources for (int i = 0; i < costTypes.Length; i++) BunkaGame.ResourceManager.RequestResource(costTypes[i], costAmounts[i], this.Location); }
void iMouseHandler.wheel(int x, int y, int delta, eMouseButtonsState bs) { CPoint point = new CPoint(x, y); foreach (var kvp in wheelHandlers) { kvp.Key.wheel(point, delta, bs); } }
// get the boundary rectangle for each object, this called automatically as an internal function // when generate new object from the data. private void _CalcRectangle() { if (list.Count != 0) { RC = CPoint.GetBoundingRect(this.list); return; } RC = new Rectangle(); }
public CMouse(IntPtr hwnd) { this.hwnd = hwnd; this.oldPoint = new CPoint(0, 0); this.leave = false; this.MAX_X = (Console.WindowWidth << 3) - 1; this.MAX_Y = Console.WindowHeight << 4; }
/// <summary> /// 注释 /// </summary> public bool Select() { if (this.PParser.GetSelectPartPoint == null || this.PParser.GetSelectPartPoint[0].Y == this.PParser.GetSelectPartPoint[1].Y) { var ls = this.PParser.GetLineString; return(this.SelectLine(ls)); } else { this.DeleteSeelctPuckerLineStringAndY = new List <PuckerLineStringAndID>(); int indexY = this.PParser.GetSelectPartPoint[0].Y / FontContainer.FontHeight; var startIndexY = indexY; int puckerLength = 0; int width = this.PParser.GetLsWidth(this.PParser.PLineString[indexY]); var endY = this.PParser.GetSelectPartPoint[1].Y; for (var lineY = this.PParser.GetSelectPartPoint[0].Y; lineY <= endY; lineY += FontContainer.FontHeight) { var ls = this.PParser.PLineString[lineY / FontContainer.FontHeight]; this.GetHidePuckerID(ref indexY, ref puckerLength, ls, this.DeleteSeelctPuckerLineStringAndY); indexY++; } this.PuckerShowAndComment(); this.CommentAllLine(startIndexY, indexY - startIndexY); if (this.PCommentStartWidth == -1) { return(false); } #region 设置选择坐标 indexY--; var startLs = this.PParser.PLineString[startIndexY]; var cpoint = new CPoint(); cpoint.X = this.PParser.GetLeftSpace; cpoint.Y = startIndexY * FontContainer.FontHeight; cpoint.LineWidth = width + (!string.IsNullOrWhiteSpace(startLs.Text) ? this.PCommentStartWidth : 0); cpoint.LineStringIndex = -1; this.PParser.SetBgStartPoint(cpoint); var lastLS = this.PParser.PLineString[indexY]; width = this.PParser.GetLsWidth(lastLS); cpoint = new CPoint(); cpoint.X = this.PParser.GetLeftSpace + width; cpoint.Y = indexY * FontContainer.FontHeight; cpoint.LineWidth = width - (string.IsNullOrWhiteSpace(startLs.Text) ? this.PCommentStartWidth : 0); cpoint.LineStringIndex = lastLS.Length - 1; this.PParser.SetBgEndPoint(cpoint); this.SetSelectBg(); #endregion #region 赋值 this.SetPuckerArrayID(); #endregion } return(true); }
public void SetDrawBgLocal(CPoint[] points) { if (points != null) { var startPoint = points[0]; var endPoint = points[1]; this.PStartForExecuteAfterShowSelectPoint = new CPoint(startPoint.X, startPoint.Y, startPoint.LineWidth, startPoint.LineStringIndex); this.PEndForExecuteAfterShowSelectPoint = new CPoint(endPoint.X, endPoint.Y, endPoint.LineWidth, endPoint.LineStringIndex); } }
protected override void handleSyncro(eSynchroEvent synchroEvent) { if (synchroEvent != eSynchroEvent.Report || position == prevPosition) { return; } // ConsoleLogger.logDebug( "RawMouse.handleSyncro, updated" ); handler.mouseMove(position.x, position.y, buttonsState); prevPosition = position; }
public void SetDrawBg() { if (this.PParser.GetSelectPartPoint != null) { var startPoint = this.PParser.GetSelectPartPoint[0]; var endPoint = this.PParser.GetSelectPartPoint[1]; this.PActionOperation.PStartForExecuteAfterShowSelectPoint = new CPoint(startPoint.X, startPoint.Y, startPoint.LineWidth, startPoint.LineStringIndex); this.PActionOperation.PEndForExecuteAfterShowSelectPoint = new CPoint(endPoint.X, endPoint.Y, endPoint.LineWidth, endPoint.LineStringIndex); } }
public CCorrCpts(int intID, CPoint frcpt, CPoint tocpt) { frcpt.PairCorrCpt = this; tocpt.PairCorrCpt = this; this.intID = intID; this.FrCpt = frcpt; this.ToCpt = tocpt; //this.pMoveVector = CGeoFunc.CalMoveVector(frcpt, tocpt); }
/// <summary> /// VI方法获取对应点,此函数为LI方法的入口函数(仅对一对对应线段处理的时候从此处调用) /// </summary> /// <param name="CFrPolyline">大比例尺线段</param> /// <param name="CToPolyline">小比例尺线段</param> /// <param name="ResultPtLt">结果数组</param> /// <remarks>应注意这样一种情况:每一对对应线段的第一个点都在上一轮中处理过了</remarks> public List<CPoint> CVI(CPolyline CFrPolyline, CPolyline CToPolyline) { List<CPoint> ResultPtLt = new List<CPoint>(); CPoint cfrpt0 = CFrPolyline.CptLt[0]; cfrpt0.CorrespondingPtLt = new List<CPoint>(); cfrpt0.CorrespondingPtLt.Add(CToPolyline.CptLt[0]); ResultPtLt.Add(cfrpt0); VI(CFrPolyline, CToPolyline, ref ResultPtLt); return ResultPtLt; }
void iButtonHandler.buttonDown(CPoint pos, eMouseButton changedButtons, eMouseButtonsState bs) { if (changedButtons == eMouseButton.Left) { anim.cancelDelta(this); prevMouse = pos; mouseVelocity.reset(); mouseVelocity.add(pos, timeSource.messageTime); } }
public void SetSelectBgLocal(CPoint startPoint, CPoint endPoint) { if (startPoint != null) { this.PStartBgPoint = new CPoint(startPoint.X, startPoint.Y, startPoint.LineWidth, startPoint.LineStringIndex); } if (endPoint != null) { this.PEndBgPoint = new CPoint(endPoint.X, endPoint.Y, endPoint.LineWidth, endPoint.LineStringIndex); } }
public ConstructionBuilding(ConstructionHandler handler, ResourceType[] costTypes, uint[] costAmounts, float constructionTime, CPoint position) : base(BuildingType.Construction, position) { BunkaGame.MapManager[position] = this; this.ConstructionHandler = handler; this.ConstructionTime = constructionTime; this.costs = new Dictionary<ResourceType, uint>(); for (int i = 0; i < costTypes.Length; i++) this.costs.Add(costTypes[i], costAmounts[i]); }
public void setBlockProp(CPoint point, string strMaterial, double dMeshsize, string strCircuit, double dMagnetAngle, EMMoving emMoving, int nTurns) { string strCommand; try { /// mode 변경 없이도 동작은 한다. strCommand = "mi_seteditmode(\"blocks\")"; sendCommand(strCommand); strCommand = "mi_addblocklabel(" + point.m_dX + "," + point.m_dY + ")"; sendCommand(strCommand); strCommand = "mi_selectlabel(" + point.m_dX + "," + point.m_dY + ")"; sendCommand(strCommand); int nGroup; if (emMoving == EMMoving.MOVING) { nGroup = MOVING_GROUP_NUM; } else { nGroup = 0; } strMaterial = "\"" + strMaterial + "\""; strCircuit = "\"" + strCircuit + "\""; strCommand = "mi_setblockprop(" + strMaterial + ",0," + dMeshsize.ToString() + "," + strCircuit + "," + dMagnetAngle.ToString() + "," + nGroup.ToString() + "," + nTurns.ToString() + ")"; sendCommand(strCommand); strCommand = "mi_clearselected()"; sendCommand(strCommand); // editmode 를 group 으로 바꾸어서 FEMM 마우스 동작을 막는다. lockEdit(); } catch (Exception ex) { CNotice.printTrace(ex.Message); return; } }
public bool Contains(CPoint pt) { var d1 = sign(pt, this.P1, this.P2); var d2 = sign(pt, this.P2, this.P3); var d3 = sign(pt, this.P3, this.P1); var n = (d1 < 0) || (d2 < 0) || (d3 < 0); var p = (d1 > 0) || (d2 > 0) || (d3 > 0); var aContains = !(n && p); return(aContains); }
protected virtual Color GetPointColor(CPoint point) { var rgPoint = point.RGPoint; if (rgPoint.G < 0) { return(Config.GNegativeFillColor); } return(Config.GPositiveFillColor); }
public static int CmpCptXY(CPoint cpt1, CPoint cpt2, bool blnVerySmall = true) { IComparer <double> cmp = null; if (blnVerySmall == true) { cmp = CCmpDbl_CoordVerySmall.sComparer; } return(CmpDual(cpt1, cpt2, cpt => cpt.X, cpt => cpt.Y, cmp, cmp)); }
public void AnimateTo(CPoint to, TimeSpan runtime, Action animationCompletedAction) { if (Animation != null) { throw new InvalidOperationException("Piece animate now"); } Animation = new CPointAnimator <CVirtualPiece>(this, Position, to, runtime); Animation.AnimationCompleted += ResetAnimationToDefault; Animation.AnimationCompleted += animationCompletedAction; AnimationStartTime = DateTime.UtcNow; Animation.BeginAnimation(); }
void iMouseHandler.mouseMove(int x, int y, eMouseButtonsState bs) { CPoint point = new CPoint(x, y); foreach (var kvp in moveHandlers) { kvp.Key.mouseMove(point, bs); } // In addition to user handlers, also update position in the context, to render it. context?.setMouseCursorPosition(point); }
private static void FillPoint(Color clr, CPoint cp1, Graphics gr, int radius = 3) { var i1 = Correct((cp1.C0 - X) / OnePixelX, Sz); var j1 = Correct((cp1.C1 - Y) / OnePixelY, Sz); var brush = new SolidBrush(clr); lock (gr) { gr.FillEllipse(brush, (float)(i1 - radius), (float)(j1 - radius), 2 * radius, 2 * radius); } }
public CCorrCpts(CPoint frcpt, double dblMoveX, double dblMoveY) { CPoint tocpt = new CPoint(frcpt.ID, frcpt.X + dblMoveX, frcpt.Y + dblMoveY); frcpt.PairCorrCpt = this; tocpt.PairCorrCpt = this; this.intID = frcpt.ID; this.FrCpt = frcpt; this.ToCpt = tocpt; this.pMoveVector = new CMoveVector(frcpt.ID, dblMoveX, dblMoveY); }
/// <summary>计算距离值(Translation指标值)</summary> /// <param name="frcpl">大比例尺线段,可以只有一个顶点</param> /// <param name="tocpl">小比例尺线段,可以只有一个顶点</param> /// <returns>距离值</returns> public double CalTDistance(CPolyline frcpl, CPolyline tocpl, CPoint StandardVetorCpt) { //List<CPoint> cresultptlt = _LinearInterpolationA.CLI(frcpl, tocpl); //每次都相当于处理新的线段,因此使用CLI ////_Translation = new CTranslation(); ////double dblTranslation = _Translation.CalTranslation(cresultptlt); ////return dblTranslation; //double dblDeflection = _Deflection.CalDeflection(cresultptlt, StandardVetorCpt); //return dblDeflection; return(0); }
//private CPolyline _FrCPl; //private CPolyline _ToCPl; //private CPolyline _InterFrCPl; //private CPolyline _InterToCPl; //private List<CPoint> _CResultPtLt; //private /// <summary> /// LI方法获取对应点,此函数为LI方法的入口函数(仅对一对对应线段处理的时候从此处调用,因为该函数顾及了线段的第一个顶点) /// </summary> /// <param name="CFrPolyline">大比例尺线段,可以只有一个顶点</param> /// <param name="CToPolyline">小比例尺线段,可以只有一个顶点</param> /// <param name="ResultPtLt">结果数组</param> /// <remarks></remarks> public List <CPoint> CLI(CPolyline CFrPolyline, CPolyline CToPolyline) { List <CPoint> ResultPtLt = new List <CPoint>(CFrPolyline.CptLt.Count + CToPolyline.CptLt.Count - 1); //please consider the special case: one segment corresponds to one point CPoint cfrpt0 = CFrPolyline.CptLt[0]; cfrpt0.CorrespondingPtLt = new List <CPoint>(); //CToPolyline.CptLt[0].isCtrl = true; //标记为控制点 cfrpt0.CorrespondingPtLt.Add(CToPolyline.CptLt[0]); ResultPtLt.Add(cfrpt0); LI(CFrPolyline, CToPolyline, ref ResultPtLt); return(ResultPtLt); }
public void emitGlyph(int advance, short lsbDelta, short rsbDelta, short spriteLeft, short spriteTop, ushort sx, ushort sy, uint uvTopLeft, uint uvBottomRight, byte layer) { glyphLayout.adjustPosition(lsbDelta, rsbDelta); if (firstCharacterInWord == int.MinValue) { firstCharacterInWord = glyphLayout.currentPositionPixels; } Span <sGlyphVertex> destSpan = buffer.appendGlyph(); glyphLayout.emitGlyph(destSpan, 0, id | layer, spriteLeft, spriteTop, sx, sy, uvTopLeft, uvBottomRight); glyphLayout.advance(advance); var ba = lineBreaker.glyph(glyphLayout.currentPositionPixels); switch (ba) { case eBreakAction.None: return; case eBreakAction.LineFeed: newline(); return; case eBreakAction.MoveLastWord: break; default: throw new ApplicationException(); } CPoint offsetToNextLine = new CPoint(); int xMovingFrom = firstCharacterInWord; int xMovingTo = lineStartPosition; offsetToNextLine.x = lineStartPosition - firstCharacterInWord; // We want this to be negative number, because moving left. offsetToNextLine.y = lineHeight; var destSlice = finalDestSpan.Slice(destOffset); buffer.copyWithOffset(destSlice, offsetToNextLine); destOffset += buffer.length; buffer.clear(); int movedWidth = glyphLayout.currentPositionPixels - firstCharacterInWord; glyphLayout.newLine(lineStartPosition + movedWidth, lineHeight, true); // True to keep the damn RSB delta }
public void SinglePoint_Test() { var decoder = new VectorDecoder(); var p = new CPoint( new Complex(1 / sqrt2, 0), new Complex(-1 / sqrt2, 0) ); var r = decoder.Solve(new[] { p.X, p.Y }); Assert.AreEqual(p, r[0]); }
public ConsoleBlock(Span <sGlyphVertex> destSpan, CPoint start, ref sScaledMetrics metrics, uint id, int width) { glyphLayout = new GlyphLayout(start); lineStartPosition = glyphLayout.currentPositionPixels; lineHeight = (ushort)metrics.lineHeight; characterWidth = (ushort)metrics.maxAdvancePixels; this.id = id; this.destSpan = destSpan; nextGlyphVertexOffset = 0; x = 0; this.width = width; }
void iButtonHandler.buttonDown(CPoint point, eMouseButton button, eMouseButtonsState bs) { switch (button) { case eMouseButton.Left: playPause(); return; case eMouseButton.Middle: mediaEngine.muted = !mediaEngine.muted; return; } }
public CLine Paralell(double dist) { var p1 = this.P1; var p2 = this.P2; var d = p2 - p1; var l = Math.Sqrt(Math.Pow(p2.x - p1.x, 2) + Math.Pow(p2.y - p1.y, 2)); var ud = new CPoint(d.x / l, d.y / l); var p = new CPoint(-ud.y, ud.x); var n = new CPoint(p1.x - ud.y * dist, p1.y + ud.x * dist); var s = n + d; return(new CLine(n, s)); }
private double CaInterLSubIntegral(CPoint frfrcpt, CPoint frtocpt, CPoint tofrcpt, CPoint totocpt, CPoint StandardVectorCpt, double dbInterLSmallDis, double dblVerySamll) { CPoint newfrfrcpt = new CPoint(0, frfrcpt.X + StandardVectorCpt.X, frfrcpt.Y + StandardVectorCpt.Y); CPoint newfrtocpt = new CPoint(0, frtocpt.X + StandardVectorCpt.X, frtocpt.Y + StandardVectorCpt.Y); CEdge frcedge = new CEdge(newfrfrcpt, newfrtocpt); CEdge tocedge = new CEdge(tofrcpt, totocpt); frcedge.SetLength(); tocedge.SetLength(); if (CCmpMethods.CmpCEdgeCoord(frcedge, tocedge, true) == 0 || (frcedge.dblLength == 0 && tocedge.dblLength == 0)) //为了应付刚开始时有重合的对应点 { return(0); } double dblLength = frcedge.dblLength; if (frcedge.dblLength < tocedge.dblLength) { dblLength = tocedge.dblLength; } int intSegmentNum = Convert.ToInt32(dblLength / dbInterLSmallDis) + 1; double frlength = frcedge.dblLength / intSegmentNum; double tolength = tocedge.dblLength / intSegmentNum; //梯形面积(因为所有的上底和下底都相同,因此可以先将各个梯形的高相加,再在循环外乘以高、除以2) double dbledgelength = 0; double dblRatio = 1 / Convert.ToDouble(intSegmentNum); double dblCurrentRatio = 0; for (int k = 0; k < intSegmentNum; k++) { double dblfrx = (1 - dblCurrentRatio) * newfrfrcpt.X + dblCurrentRatio * newfrtocpt.X; double dblfry = (1 - dblCurrentRatio) * newfrfrcpt.Y + dblCurrentRatio * newfrtocpt.Y; double dbltox = (1 - dblCurrentRatio) * tofrcpt.X + dblCurrentRatio * totocpt.X; double dbltoy = (1 - dblCurrentRatio) * tofrcpt.Y + dblCurrentRatio * totocpt.Y; dbledgelength += CGeoFunc.CalDis(dblfrx, dblfry, dbltox, dbltoy); dblCurrentRatio += dblRatio; } double dbInterLSubIntegral = dbledgelength * (frlength + tolength) / 2; return(dbInterLSubIntegral); }
public static void Main() { SPoint sp1 = new SPoint(1, 1); CPoint cp1 = new CPoint(1, 2); SPoint sp2 = sp1; // 객체 2개. 객체 자체를 복사 CPoint cp2 = cp1; // 참조(주소)복사, 객체 한개 sp2.x = 10; Console.WriteLine(sp1.x); // 1 cp2.x = 10; Console.WriteLine(cp1.x); // 10 }
private CPoint RSComputeEndCpt(CPoint cpt, SortedDictionary <CPoint, CPoint> CptSD) { CPoint outcpt; bool blnContainsKey = CptSD.TryGetValue(cpt, out outcpt); if (blnContainsKey == true) { return(outcpt.PairCorrCpt.ToCpt); } else { return(RSComputeCpt(cpt, CptSD)); } }
///// <summary> ///// 从Excel中读入数据 ///// </summary> ///// <param name="strPath">文件路径</param> ///// <returns>pParameterResult:较大比例尺线状要素上、较小比例尺线状要素、对应点列</returns> ///// <remarks >数据格式:第一行为表头,即各列的名称; ///// 第一列为数据序号; ///// 第二列为时间; ///// 第三、四、五列分别为X、Y、Z坐标</remarks> //public static CPolyline InputDataXYZT(string strPath) //{ // Excel.Application pExcelAPP = new Excel.Application(); // pExcelAPP.Visible = false; // Workbook pWorkBook = pExcelAPP.Workbooks.Open(strPath); // Worksheet pWorksheet = pWorkBook.Worksheets[1] as Worksheet; // int intRow = pWorksheet.UsedRange.Rows.Count; // System.Array values = (System.Array)pWorksheet.UsedRange.Formula; // List<CPoint> cptlt = new List<CPoint>(); // for (int i = 0; i < intRow - 1; i++) // { // CPoint cpt = new CPoint(i, Convert.ToDouble(values.GetValue(i + 2, 3)), // Convert.ToDouble(values.GetValue(i + 2, 4)), Convert.ToDouble(values.GetValue(i + 2, 5))); // cpt.dblTime = Convert.ToDouble(values.GetValue(i + 2, 2)); // cptlt.Add(cpt); // } // pExcelAPP.Quit(); // CPolyline cpl = new CPolyline(0, cptlt); // return cpl; //} /// <summary> /// 从Excel中读入数据 /// </summary> /// <param name="strPath">文件路径</param> /// <returns>pParameterResult:较大比例尺线状要素上、较小比例尺线状要素、对应点列</returns> /// <remarks >数据格式:第一行为表头,即各列的名称; /// 第一列为数据序号; /// 第二列为时间; /// 第三、四、五列分别为X、Y、Z坐标</remarks> public static List <CPolyline> InputDataLtXYZT(string strPath) { Excel.Application pExcelAPP = new Excel.Application(); pExcelAPP.Visible = false; Workbook pWorkBook = pExcelAPP.Workbooks.Open(strPath); Worksheet pWorksheet = pWorkBook.Worksheets[1] as Worksheet; //读取所有数据 int intRow = pWorksheet.UsedRange.Rows.Count; System.Array values = (System.Array)pWorksheet.UsedRange.Formula; List <CPoint> cptlt = new List <CPoint>(); for (int i = 0; i < intRow - 1; i++) { CPoint cpt = new CPoint(i, Convert.ToDouble(values.GetValue(i + 2, 3)), Convert.ToDouble(values.GetValue(i + 2, 4)), Convert.ToDouble(values.GetValue(i + 2, 5))); cpt.intTrajectory = Convert.ToInt32(values.GetValue(i + 2, 1)); cpt.dblTime = Convert.ToDouble(values.GetValue(i + 2, 2)); cptlt.Add(cpt); } pExcelAPP.Quit(); //以序号为依据生成线状要素 List <CPolyline> cpllt = new List <CPolyline>(); int intLastTrajectory = cptlt[0].intTrajectory; List <CPoint> subcptlt = new List <CPoint>(); subcptlt.Add(cptlt[0]); for (int i = 1; i < cptlt.Count; i++) { if (intLastTrajectory == cptlt[i].intTrajectory) { subcptlt.Add(cptlt[i]); } else { cpllt.Add(new CPolyline(intLastTrajectory, subcptlt)); intLastTrajectory = cptlt[i].intTrajectory; subcptlt = new List <CPoint>(); subcptlt.Add(cptlt[i]); } } //注意:最后一个线段并没有添加,因此在此处添加 cpllt.Add(new CPolyline(intLastTrajectory, subcptlt)); //返回 return(cpllt); }
public static void Main() { CPoint cp1; // 객체 생성 아님. 참조 변수 생성 CPoint cp2 = new CPoint(); // 객체 생성. SPoint sp1; // 객체 생성 SPoint sp2 = new SPoint(); // 객체 생성, initobj sp1.x = 10; xp2.x = 10; Console.WriteLine($"{sp1.x}"); Console.WriteLine($"{sp2.x}"); }
// create a constructionhandler for a specific building public ConstructionHandler CreateConstructionRequest(BuildingType type, CPoint position) { List<string[]> building = this.buildings[type]; // offset for buildings that have more lines preceding the construction information int offset = type > BuildingType.CONVERSION ? 2 : 0; int constructionTime = int.Parse(building[3 + offset][1]); string[] iTypes = building[4 + offset][1].Split(','); string[] iAmounts = building[5 + offset][1].Split(','); // parse construction cost types ResourceType[] costTypes = new ResourceType[iTypes.Length]; for (int i = 0; i < iTypes.Length; i++) costTypes[i] = (ResourceType)(Enum.Parse(typeof(ResourceType), iTypes[i])); // parse construction cost amounts uint[] costAmounts = new uint[iAmounts.Length]; for (int i = 0; i < iAmounts.Length; i++) costAmounts[i] = uint.Parse(iAmounts[i]); // create construction request return new ConstructionHandler(type, costTypes, costAmounts, constructionTime, position); }
/// <summary> /// Given coordinates relative to a specified center point, return the equivalent absolute coords on the grid. /// </summary> private CPoint getAbsoluteCoords(CPoint center, CPoint relative) { int absoluteX = wrap(center.X + relative.X, true); int absoluteY = wrap(center.Y + relative.Y, false); return new CPoint(absoluteX, absoluteY); }
/// <summary> /// Set the specified cell to be in the specified state in the next iteration; this adds the modification to a /// set of cells to modify at the end of this iteration. /// /// If a neighborhood set has been specified and optimization is possible, any cell modifications are caught and /// handled here. Cells within the reverse neighborhood set of the changed cell are added to the list of cells /// to check in the next iteration. /// </summary> public void setCellState(CPoint cell, uint state) { if (ca == null) return; CPoint modifiedPoint = new CPoint(wrap(cell.X, true), wrap(cell.Y, false)); toUpdate.Enqueue(new Cell(modifiedPoint, state)); foreach (CPoint p in ca.RNeighborhood) lock (toCheck) toCheck.Add(getAbsoluteCoords(modifiedPoint, p)); }
/// <summary> /// Get the number of neighbors with the specified state that are neighboring the specified cell. To be used as /// a shortcut for CAs in which only the number of neighboring cells of a given state is relevant, and not their /// arrangement. /// </summary> public int getNumNeighbors(CPoint cell, int state) { if (ca == null) return 0; // Iterate through each neighbor and test if it is in the specified state int relativeX, relativeY, neighborX, neighborY, count = 0; for (int i = 0; i < ca.Neighborhood.Length; i++) { lock (ca) { relativeX = ca.Neighborhood[i].X; relativeY = ca.Neighborhood[i].Y; } if (!(relativeX == 0 && relativeY == 0)) { neighborX = wrap(cell.X + relativeX, true); neighborY = wrap(cell.Y + relativeY, false); lock (grid) { if (grid[neighborX][neighborY] == state) count++; } } } return count; }
void getCentroid(CPoint c) { int nelts; nelts = this.nPoints; double sumx, sumy, sumz; double norm; sumx = sumy = sumz = 0.0; for(int i=0; i<nelts; i++){ sumx += ((CPoint) input[i]).x_in; sumy += ((CPoint) input[i]).y_in; sumz += ((CPoint) input[i]).z_in; } norm = sumx * sumx; norm += sumy * sumy; norm += sumz * sumz; norm = Math.Sqrt(norm); if (norm > Cartesian.Epsilon){ sumx /= norm; sumy /= norm; sumz /= norm; } else { sumx = sumy = sumz = 0.0; } c.x_in = sumx; c.y_in = sumy; c.z_in = sumz; return; }
protected Building(BuildingType type, CPoint position) { BunkaGame.MapManager[position] = this; this.BuildingType = type; this.Position = position; }
public void FindPath(CPoint start, CPoint end) { this.path = Pathfinder.GetPath(start, end); }
void addPoint(double ax, double ay, double az){ CPoint p = new CPoint(); p.keeper = false; p.x_in = ax; p.y_in = ay; p.z_in = az; input.Add(p); }
// // creates a rotation matrix and saves it in the // instance's internal variables private void makeRotator(CPoint v) { double theta, phi; double m00, m01, m02, m10, m11, m12, m20, m21, m22; double n00, n01, n02, n10, n11, n12, n20, n21, n22; // WA: theta = acos(v.x_in / sqrt(norm)); theta = Math.Atan2(v.y_in, v.x_in); phi = Math.Acos(v.z_in); m00 = m11 = Cartesian.Cos(theta); m10 = -(m01 = Math.Sin(theta)); m02 = m12 = m20 = m21 = 0.0; m22 = 1.0; n00 = n22 = v.z_in; // cos(phi); n02 = -(n20 = Math.Sin(phi)); n01 = n10 = n21 = n12 = 0.0; n11 = 1.0; // Multiply n.m for the rotator rot00 = n00*m00 + n01*m10 + n02*m20; rot01 = n00*m01 + n01*m11 + n02*m21; rot02 = n00*m02 + n01*m12 + n02*m22; rot10 = n10*m00 + n11*m10 + n12*m20; rot11 = n10*m01 + n11*m11 + n12*m21; rot12 = n10*m02 + n11*m12 + n12*m22; rot20 = n20*m00 + n21*m10 + n22*m20; rot21 = n20*m01 + n21*m11 + n22*m21; rot22 = n20*m02 + n21*m12 + n22*m22; // use this code if you need to check the determinant // it should be 1 for a rigid rotation // { // double det; // det = rot00 * (rot11 * rot22 - rot21 * rot12); // det -= rot01 * (rot10 * rot22 - rot20 * rot12); // det += rot02 * (rot10 * rot21 - rot11 * rot20); // write the determinant // } return; }
public Building this[CPoint index] { get { return this[index.X, index.Y]; } set { this[index.X, index.Y] = value; } }
public List<CPoint> Neighbours(CPoint cell) { List<CPoint> result = new List<CPoint>(); CPoint[] possibles = { new CPoint(cell.X - 1, cell.Y), new CPoint(cell.X + 1, cell.Y), new CPoint(cell.X, cell.Y - 1), new CPoint(cell.X, cell.Y + 1) }; foreach (CPoint p in possibles) if (IsValidIndex(p)) result.Add(p); return result; }
public int ManhattanDistance(CPoint from, CPoint to) { return Math.Abs(from.X - to.X) + Math.Abs(from.Y - to.Y); }
public bool IsValidIndex(CPoint p) { return IsValidIndex(p.X, p.Y); }
public Vector2 IndexToCellCentre(CPoint p) { return IndexToCellCentre(p.X, p.Y); }
public List<CPoint> FreeNeighbours(CPoint cell) { List<CPoint> possibles = Neighbours(cell); List<CPoint> result = new List<CPoint>(); foreach (CPoint p in possibles) if (this[p] == null) result.Add(p); return result; }
/// <summary> /// Get the state of the specified cell /// </summary> public uint getCellState(CPoint cell) { lock (grid) { return grid[wrap(cell.X, true)][wrap(cell.Y, false)]; } }
public ConstructionRequest(BuildingType type, CPoint position) : this() { this.BuildingType = type; this.Position = position; }
public bool addConvex(double[] x, double[] y, double[] z, int len){ // // All the input points are in x,y,z... // To make a convex hull, follow these steps: // 1. add all the points to the internal array // 2. compute the centroid // 3. make the rotation matrix, that rotates the centroid to (x,y,0) // 4. rotate the points (call xform, returns error if more than hemisphere) // 5. sort (by x,y) // 6. compute the convex hull, result is a polygon // 7. Call the polygoner to make the convex // todo: encapsulate Polygon into Chull, or use inheritance? // if (_reg == null) return true; CPoint centroid = new CPoint(); for(int i=0; i<len; i++){ addPoint(x[i], y[i], z[i]); } this.nPoints = len; this.getCentroid( centroid); this.makeRotator(centroid); if (this.xform()){ this.sort(); nrKept = this.chainHull_2D(); // output has it all // allmost like Polygon, except first point is included at end // We can now make a polygon out of it. Luckily it takes // care of the winding error // // First, move over the x,y,z points to double arrays; // double[] xa, ya, za; CPoint p; xa = new double[nrKept]; ya = new double[nrKept]; za = new double[nrKept]; for(int i=0; i<nrKept; i++){ p = (CPoint) output[i]; xa[i] = p.x_in; ya[i] = p.y_in; za[i] = p.z_in; } Polygon poly = new Polygon(this._reg); poly.add(xa, ya, za, nrKept-1); // because first connects to last } else { // // Error, points were more than a hemisphere // return false; } return true; }
/// <summary> /// Attempt to compile delta function code entered. Any compiler /// messages are displayed. /// </summary> private void compile(object sender, RoutedEventArgs e) { // Gather information entered string deltaStr = deltaInputBox.Text; int numStates = (numStatesInputBox.Text == "") ? 1 : int.Parse(numStatesInputBox.Text); uint defaultState = (defaultStateInputBox.Text == "") ? 0 : uint.Parse(defaultStateInputBox.Text); CPoint[] neighbors = new CPoint[Neighborhood.Count]; int i = 0; foreach (OPoint p in Neighborhood) { neighbors[i] = new CPoint(p.X, p.Y); i++; } // Attempt to compile a new CA with the entered information ca = new CA(numStates, defaultState, neighbors, deltaStr); compileMesseageOutputBox.Text = ca.compileDelta(); }
double CalculatePathingCostMultiplyer(CLayerPart pActor, CPoint StartPoint, CPoint EndPoint, CCollideProcessingState pCollideProcessingState) { CFPoint PolyDelta, NormalPos, CenterPos; pActor.GetCollisionCenterPosition(&CenterPos); pActor.GetPosition(&NormalPos); PolyDelta.Minus(CenterPos, NormalPos); CFPoint FPolyStartPoint, FPolyEndPoint; FPolyStartPoint.Set(StartPoint); FPolyEndPoint.Set(EndPoint); FPolyStartPoint -= PolyDelta; FPolyEndPoint -= PolyDelta; CCollideInputs CollideInputs(&FPolyStartPoint, &FPolyEndPoint); uint IsTempExcluded = pActor.GetFlag(CLayerPart::IsTemporarilyExcluded); const_cast<CLayerPart*>(pActor).OrInFlags(CLayerPart::IsTemporarilyExcluded); // <WIP> pEntityMovable should not require a const cast here (many changes would have to be made) pCollideProcessingState.ResetPathingCostMultiplyer(); bool Collision = pActor.GetLayer().SaveData.CheckCollide(pActor.GetpPolygon(0), &FPolyStartPoint, &CollideInputs, pCollideProcessingState, null, null, const_cast<CLayerPart*>(pActor), 0, 0); const_cast<CLayerPart*>(pActor).ClearFlags(CLayerPart::IsTemporarilyExcluded); const_cast<CLayerPart*>(pActor).OrInFlags(IsTempExcluded); if (Collision) { return CCollideOutputs::MIN_COST_RATIO_TO_TREAT_AS_IMPASSABLE; } else { return pCollideProcessingState.GetAndResetPathingCostMultiplyer(); } }
public int getHull(double[] x, double[] y, double[] z, int len, double[] ox, double[] oy, double[] oz){ // // All the input points are in x,y,z... // To make a convex hull, follow these steps: // 1. add all the points to the internal array // 2. compute the centroid // 3. make the rotation matrix, that rotates the centroid to (x,y,0) // 4. rotate the points (call xform, returns error if more than hemisphere) // 5. sort (by x,y) // 6. compute the convex hull, result is a polygon // 7. Call the polygoner to make the convex // todo: encapsulate Polygon into Chull, or use inheritance? // CPoint centroid = new CPoint(); for(int i=0; i<len; i++){ addPoint(x[i], y[i], z[i]); } this.nPoints = len; this.getCentroid( centroid); this.makeRotator(centroid); if (this.xform()){ this.sort(); nrKept = this.chainHull_2D(); CPoint p; for(int i=0; i<nrKept; i++){ p = (CPoint) output[i]; ox[i] = p.x_in; oy[i] = p.y_in; oz[i] = p.z_in; } } else { // // Error, points were more than a hemisphere // nrKept = 0; } return nPoints; }
////////////////// // METHODS // ////////////////// public void ConstructBuilding(BuildingType type, CPoint position) { if (BunkaGame.MapManager.IsValidIndex(position) && BunkaGame.MapManager[position] == null) this.collect.Add(BunkaGame.BuildingManager.BuildingLoader.CreateConstructionRequest(type, position)); }
void rotate(CPoint p){ p.x = rot00 * p.x_in + rot01 * p.y_in + rot02 * p.z_in; p.y = rot10 * p.x_in + rot11 * p.y_in + rot12 * p.z_in; p.z = rot20 * p.x_in + rot21 * p.y_in + rot22 * p.z_in; return; }
/// <summary> /// 获取鼠标坐标 /// </summary> /// <returns></returns> private CPoint GetMousePoint() { CPoint point; //获取鼠标在屏幕的位置 if (GetCursorPos(out point)) { if (hwnd != IntPtr.Zero) { //把屏幕位置转换成控制台工作区位置 ScreenToClient(hwnd, out point); if ((point.X >= 0 && point.Y <= MAX_X) && point.Y >= 0 && point.Y <= MAX_Y) { this.oldPoint = point; this.leave = false; } else { leave = true; } } } return oldPoint; }