/// <summary> /// Gets an integer based on the settings. Sets up temporary new boundaries so that an interval /// of e.g. 0.8 to 3.7 will become 1.0 to 3.0 allowing integers 1 and 2 only. /// </summary> public int GetInt() { CRandomNumber Num = new CRandomNumber(Math.Ceiling(Min), Math.Floor(Max) + 1.0); double dRes = Num.Get(); if (dRes == (int)Num.GetMax()) return (int) (dRes - 1); else return (int) dRes; }
/// <summary> /// Gets an integer based on the settings. Sets up temporary new boundaries so that an interval /// of e.g. 0.8 to 3.7 will become 1.0 to 3.0 allowing integers 1 and 2 only. /// </summary> public int GetInt() { var Num = new CRandomNumber(Math.Ceiling(Min), Math.Floor(Max) + 1.0); var dRes = Num.Get(); if (dRes == (int)Num.GetMax()) { return((int)(dRes - 1)); } else { return((int)dRes); } }
/// <summary> /// Moves this by a tiny random amount. /// </summary> public void RandomPerturb() { C2DPoint pt = BoundingRect.GetPointFurthestFromOrigin(); var dMinEq = Math.Max(pt.x, pt.y) * Constants.conEqualityTolerance; var rn = new CRandomNumber(dMinEq * 10, dMinEq * 100); var cVector = new C2DVector(rn.Get(), rn.Get()); if (rn.GetBool()) { cVector.i = -cVector.i; } if (rn.GetBool()) { cVector.j = -cVector.j; } Move(cVector); }
/// <summary> /// Creates a random shape. /// </summary> /// <param name="cBoundary">The boundary.</param> /// <param name="nMinPoints">The minimum points.</param> /// <param name="nMaxPoints">The maximum points.</param> public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints) { C2DPolygon Poly = new C2DPolygon(); if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints)) { return(false); } CRandomNumber rCenOnRight = new CRandomNumber(0, 1); this.Set(Poly); for (int i = 0; i < Lines.Count; i++) { C2DLineBase pLine = Lines[i]; bool bCenOnRight = (rCenOnRight.GetInt() > 0); double dLength = pLine.GetLength(); CRandomNumber Radius = new CRandomNumber(dLength, dLength * 3); C2DArc pNew = new C2DArc(pLine.GetPointFrom(), pLine.GetPointTo(), Radius.Get(), bCenOnRight, !bCenOnRight); if (!this.Crosses(pNew)) { Lines[i] = pNew; pNew.GetBoundingRect(LineRects[i]); BoundingRect.ExpandToInclude(LineRects[i]); } } // this.MakeLineRects(); // this.MakeBoundingRect(); return(true); }
/// <summary> /// Creates a random shape. /// </summary> /// <param name="cBoundary">The boundary.</param> /// <param name="nMinPoints">The minimum points.</param> /// <param name="nMaxPoints">The maximum points.</param> public bool CreateRandom(C2DRect cBoundary, int nMinPoints, int nMaxPoints) { C2DPolygon Poly = new C2DPolygon(); if (!Poly.CreateRandom(cBoundary, nMinPoints, nMaxPoints)) return false; CRandomNumber rCenOnRight = new CRandomNumber(0, 1); this.Set( Poly ); for (int i = 0 ; i < Lines.Count; i ++) { C2DLineBase pLine = Lines[i]; bool bCenOnRight = (rCenOnRight.GetInt() > 0 ); double dLength = pLine.GetLength(); CRandomNumber Radius = new CRandomNumber(dLength , dLength * 3); C2DArc pNew = new C2DArc( pLine.GetPointFrom(), pLine.GetPointTo(), Radius.Get(), bCenOnRight, !bCenOnRight); if (!this.Crosses( pNew )) { Lines[i] = pNew; pNew.GetBoundingRect(LineRects[i]); BoundingRect.ExpandToInclude(LineRects[i]); } } // this.MakeLineRects(); // this.MakeBoundingRect(); return true; }
/// <summary> /// Moves this by a small random amount. /// </summary> public void RandomPerturb() { C2DPoint pt = _Rim.BoundingRect.GetPointFurthestFromOrigin(); double dMinEq = Math.Max(pt.x, pt.y) * Constants.conEqualityTolerance; CRandomNumber rn = new CRandomNumber(dMinEq * 10, dMinEq * 100); C2DVector cVector = new C2DVector( rn.Get(), rn.Get() ); if (rn.GetBool()) cVector.i = - cVector.i ; if (rn.GetBool()) cVector.j = - cVector.j ; Move( cVector ); }