public T GetRandom(bool remove = false) { int elementIndex = 0; float val = (float)(Random.NextDouble() * Accumulated); foreach (StartEnd startEnd in ElementStartEnd) { if (val < startEnd.end) { break; } elementIndex++; } T item = Elements[elementIndex]; if (remove) { float elementWeight = ElementStartEnd[elementIndex].end - ElementStartEnd[elementIndex].start; for (int i = elementIndex; i < ElementStartEnd.Count; i++) { //Modify each ElementStartEnd[i] = new StartEnd(ElementStartEnd[i].start - elementWeight, ElementStartEnd[i].end - elementWeight); } Accumulated -= elementWeight; Elements.RemoveAt(elementIndex); ElementStartEnd.RemoveAt(elementIndex); } return(item); }
public ICollection <string> GetAllElements() { StartEnd?.Invoke("Stard Search"); GetFolderElements(startPath); StartEnd?.Invoke("End Search"); return(filesFolders); }
protected void PrepareStartEndPar() { // assess parameters which define start and end of loop loopStart = GetStartEnd(DefPar.Loop.First_Pol, DefPar.Loop.First_Func, DefPar.Loop.Start_After_Pol, DefPar.Loop.Start_After_Func, true); loopEnd = GetStartEnd(DefPar.Loop.Last_Pol, DefPar.Loop.Last_Func, DefPar.Loop.Stop_Before_Pol, DefPar.Loop.Stop_Before_Func, false); StartEnd GetStartEnd(string parNamePol, string parNameFun, string parNameNeighbourPol, string parNameNeighbourFun, bool start) { ParBase parPol = GetUniquePar <ParBase>(parNamePol); ParBase parFun = GetUniquePar <ParBase>(parNameFun); ParBase parNeighbourPol = GetUniquePar <ParBase>(parNameNeighbourPol); ParBase parNeighbourFun = GetUniquePar <ParBase>(parNameNeighbourFun); StartEnd se = new StartEnd() { infoStore = infoStore, description = description, isStart = start }; int defCnt = 0; if (parPol != null) { se.ident = parPol.xmlValue; se.isFun = false; se.isNeighbour = false; ++defCnt; } if (parFun != null) { se.ident = parFun.xmlValue; se.isFun = true; se.isNeighbour = false; ++defCnt; } if (parNeighbourPol != null) { se.ident = parNeighbourPol.xmlValue; se.isFun = false; se.isNeighbour = true; ++defCnt; } if (parNeighbourFun != null) { se.ident = parNeighbourFun.xmlValue; se.isFun = true; se.isNeighbour = true; ++defCnt; } string sse = parNamePol == DefPar.Loop.First_Pol ? "start" : "end"; if (defCnt > 1) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: over-definition for loop {sse}" }); } if (defCnt == 0) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: missing definition for loop {sse}" }); } return(se); } }
public void AddShadowCaster(List <ShadowLayer> shadows, Bounds shadowBounds, int physicsStartX, int physicsEndX, Position position, Position shadowOffset, bool flipX, Color color, int layer) { // NOTE: Right now we take physicsStartX/physicsEndX for character physics // If we start doing shadows with heightmap physics, we'll need to take a heightmap as well StartEnd xBounds = flipX ? new StartEnd { start = shadowBounds.startX, end = shadowBounds.endX } : new StartEnd { start = -(shadowBounds.endX - 1), end = -(shadowBounds.startX - 1) }; xBounds.start += position.X + shadowOffset.X; xBounds.end += position.X + shadowOffset.X; ShadowCaster shadowCaster = new ShadowCaster { shadows = shadows, physicsStartX = physicsStartX, physicsEndX = physicsEndX, position = position, shadowOffset = shadowOffset, flipX = flipX, color = color, }; if (flipX) { shadowCaster.shadowOffset.X = -shadowCaster.shadowOffset.X; } // Determine insertion point: int i; for (i = shadowLayers.Count; i > 0; --i) { if (shadowLayers[i - 1] <= layer) { break; } } shadowLayers.Insert(i, layer); shadowCasterXBounds.Insert(i, xBounds); shadowCasters.Insert(i, shadowCaster); }
private StartEnd ConvertDynamicX(int current, int max) { var stEnd = new StartEnd() { Start = Camera.main.ScreenToWorldPoint( new Vector3(Screen.width, 0, 0)).x / max * current * -1, End = Camera.main.ScreenToWorldPoint( new Vector3(Screen.width, 0, 0)).x / max * current }; return(stEnd); }
public SemanticModel semanticModel => document.GetSemanticModelAsync().Result; //only first time slow /// <summary> /// Initializes all fields except document. /// For <b>sci</b> uses <b>Panels.Editor.ZActiveDoc</b>. /// </summary> /// <param name="pos">If -1, gets current position. If -2, gets selection start.</param> public Context(int pos) { Debug.Assert(Environment.CurrentManagedThreadId == 1); sci = Panels.Editor.ZActiveDoc; code = sci.zText; this.pos = pos switch { -1 => sci.zCurrentPos16, -2 => sci.zSelectionStart16, _ => pos }; if (isCodeFile = sci.ZFile.IsCodeFile) { meta = MetaComments.FindMetaComments(code); } }
private StartEnd ConvertStartEndY() { var stEnd = new StartEnd() { Start = Camera.main.ScreenToWorldPoint( new Vector3(0, 0, Screen.height)).y * -1, End = Camera.main.ScreenToWorldPoint( new Vector3(0, 0, Screen.height)).y }; return(stEnd); }
private StartEnd ConvertStartEndX() { var stEnd = new StartEnd() { Start = Camera.main.ScreenToWorldPoint( new Vector3(Screen.width, 0, 0)).x * -1, End = Camera.main.ScreenToWorldPoint( new Vector3(Screen.width, 0, 0)).x }; return(stEnd); }
public static bool CompareTextRange(Range ran1, Range ran2) { List <StartEnd> startEnds1 = new List <StartEnd>(); List <StartEnd> startEnds2 = new List <StartEnd>(); StartEnd oriStartEnd1 = new StartEnd(ran1.Start, ran1.End); StartEnd oriStartEnd2 = new StartEnd(ran2.Start, ran2.End); classifyRange(ran1, ran1.Start, ran1.End, startEnds1); classifyRange(ran2, ran2.Start, ran2.End, startEnds2); if (startEnds1.Count == startEnds2.Count) { for (int i = 0; i < startEnds1.Count; i++) { if (startEnds1[i].start == startEnds2[i].start && startEnds1[i].end == startEnds2[i].end) { ran1.Start = startEnds1[i].start; ran1.End = startEnds1[i].end; ran2.Start = startEnds2[i].start; ran2.End = startEnds2[i].end; ABIW_Font font1 = new ABIW_Font(ran1.Font); ABIW_Font font2 = new ABIW_Font(ran2.Font); if (font1.Compare(font2).Result == ComparisonResultIndicate.equal) { ran1.Start = oriStartEnd1.start; ran1.End = oriStartEnd1.end; ran2.Start = oriStartEnd2.start; ran2.End = oriStartEnd2.end; continue; } else { return(false); } } else { return(false); } } return(true); } else { return(false); } }
// give at least a useful error message if users try to use DefTU or DefIL functions or the policies containing them as reference // (the implementation tries to not change the existing code too much and therefore is a bit circuitous) private bool HandleInaptRefs(List <FunBase> spineFuns, StartEnd startEnd) { foreach (FunBase f in infoStore.spine.Values) { bool isDefTuIl = f.description.GetFunName().ToLower() == DefFun.DefIl.ToLower() || f.description.GetFunName().ToLower() == DefFun.DefTu.ToLower(); bool isRefFun = startEnd.isFun && f.description.funID.ToLower() == startEnd.ident.ToLower(); bool isRefPol = !startEnd.isFun && f.description.pol.name.ToLower() == startEnd.ident.ToLower(); if (isDefTuIl && (isRefFun || isRefPol)) { infoStore.communicator.ReportError(new Communicator.ErrorInfo() { isWarning = false, message = $"{description.Get()}: functions {DefFun.DefIl} and {DefFun.DefTu} and the policies containing them cannot be used as loop-start or -end" }); return(true); } } return(false); // another problem }
public static void classifyRange(Range range, int start, int end, List <StartEnd> startEnds) { Range customRange = range; customRange.Start = start; customRange.End = end; int threshold = (int)((end - start) / 2); if (checkRange(customRange)) { StartEnd se = new StartEnd(start, end); startEnds.Add(se); return; } else { classifyRange(range, start, start + threshold, startEnds); classifyRange(range, start + threshold, end, startEnds); return; } }
public void DrawShadowReceiver(DrawContext context, Sprite whitemask, ShadowReceiver shadowReceiver, Position shadowReceiverPosition, bool shadowReceiverFlipX) { Bounds receiverBounds = new Bounds(whitemask.WorldSpaceBounds).MaybeFlipX(shadowReceiverFlipX) + shadowReceiverPosition.ToWorldZero; bool startedReceivingShadows = false; // For each shadow caster: Debug.Assert(shadowCasterXBounds.Count == shadowCasters.Count); for (int i = 0; i < shadowCasterXBounds.Count; i++) { StartEnd casterWorldXBounds = shadowCasterXBounds[i]; if (casterWorldXBounds.start >= receiverBounds.endX || receiverBounds.startX >= casterWorldXBounds.end) { continue; // Horizontally out of range } var shadowCaster = shadowCasters[i]; // Determine the ground height of the shadow: int groundHeight; if (shadowReceiver.heightmap.HasData) { var heightmapView = new HeightmapView(shadowReceiver.heightmap, shadowReceiverPosition, shadowReceiverFlipX); int startX = shadowCaster.position.X + shadowCaster.physicsStartX; int endX = shadowCaster.position.X + shadowCaster.physicsEndX; if (endX <= startX) { endX = startX + 1; // <- whoops our shadow caster has no width... quick fix-up for now... } groundHeight = heightmapView.GetHeightForShadow(startX, endX, shadowCaster.position.Z, shadowReceiver.heightmapExtendDirection); } else { groundHeight = shadowReceiver.heightmap.DefaultHeight + shadowReceiverPosition.Y; } int shadowDifference = shadowCaster.position.Y - groundHeight; // NOTE: shadowOffset is pre-flipped Position shadowPosition = new Position(shadowCaster.position.X, groundHeight, shadowCaster.position.Z) + shadowCaster.shadowOffset; if (shadowCaster.shadows[0].startHeight > shadowDifference) { continue; // Out of range } int shadowIndex = 0; while (shadowIndex + 1 < shadowCaster.shadows.Count) { if (shadowCaster.shadows[shadowIndex + 1].startHeight > shadowDifference) { break; } shadowIndex++; } Sprite shadowSprite; if (!shadowCaster.shadows[shadowIndex].shadowSpriteRef.ResolveBestEffort(out shadowSprite)) { continue; } // Determine whether the shadow overlaps the whitemask Bounds shadowBounds = new Bounds(shadowSprite.WorldSpaceBounds).MaybeFlipX(shadowCaster.flipX) + shadowPosition.ToWorldZero; Bounds worldZeroDrawBounds = Bounds.Intersection(receiverBounds, shadowBounds); if (!worldZeroDrawBounds.HasPositiveArea) { continue; } if (!startedReceivingShadows) { startedReceivingShadows = true; context.SetupShadowReceiver(whitemask, shadowReceiver, shadowReceiverPosition, shadowReceiverFlipX); } // Drawing with clipping: { Rectangle clipRect = new Rectangle // <- Region within the source rectangle (NOTE: initially with Y+ up, we fix later) { X = worldZeroDrawBounds.startX - shadowBounds.startX, Y = worldZeroDrawBounds.startY - shadowBounds.startY, Width = worldZeroDrawBounds.endX - worldZeroDrawBounds.startX, Height = worldZeroDrawBounds.endY - worldZeroDrawBounds.startY, }; // Flipping: if (shadowCaster.flipX) { clipRect.X = shadowSprite.sourceRectangle.Width - (clipRect.X + clipRect.Width); // RegionFlipX } // IMPORTANT: Convert clipRect from Y+ Up coordinates to correct Texel coordinates clipRect.Y = shadowSprite.sourceRectangle.Height - (clipRect.Y + clipRect.Height); // RegionFlipY // Turn it into a source rectangle within the texture: clipRect.X += shadowSprite.sourceRectangle.X; clipRect.Y += shadowSprite.sourceRectangle.Y; Vector2 displayPosition = new Vector2(worldZeroDrawBounds.startX, -(worldZeroDrawBounds.startY + clipRect.Height)); // NOTE: don't need to consider origin, because it's built into the draw bounds context.SpriteBatch.Draw(shadowSprite.texture, displayPosition, clipRect, shadowCaster.color, 0f, Vector2.Zero, 1, shadowCaster.flipX ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0); } } if (startedReceivingShadows) { context.TeardownShadowReceiver(); } }
public PunchType(String label, StartEnd startOrEnd, Category punchCategory) { Label = label; StartorEnd = startOrEnd; PunchCategory = punchCategory; }