public void LineOverlapCalculatedCorrectly1(float min1, float max1, float min2, float max2, float overlap) { var line1 = new Line1D(min1, max1); var line2 = new Line1D(min2, max2); var calculatedOverlap = line1.OverlapSize(line2); Assert.That(calculatedOverlap, Is.EqualTo(overlap)); }
public HorizontalLineModel Intersect(Line1D line) { var j1 = Math.Max(J1, line.J1); var j2 = Math.Min(J2, line.J2); return(j1 <= j2 ? new HorizontalLineModel { I = I, J1 = j1, J2 = j2 } : null); }
public void BuildDutyCycle(ref BRetiredProfileSample[] samples, uint numSamples, bool bGPU) { if ((mSegmentList.Count != 0) || (samples.Length == 0)) { return; } BRetiredProfileSample s = null; Line1D currentLine = null; uint sampleStart; uint sampleEnd; for (int sampleID = 0; sampleID < numSamples; sampleID++) { s = samples[sampleID]; if (bGPU == true) { sampleStart = s.mGPUStartTime; sampleEnd = s.mGPUEndTime; if ((sampleStart == sampleEnd) || (sampleEnd == 0)) { continue; } } else { sampleStart = s.mCPUStartTime; sampleEnd = s.mCPUEndTime; } if (currentLine == null) { currentLine = new Line1D(sampleStart, sampleEnd); mSegmentList.Add(currentLine); } else if (currentLine.Contains(sampleStart) == 0) { if (currentLine.Contains(sampleEnd) == 0) { continue; } else { currentLine.mEnd = sampleEnd; continue; } } else { if (currentLine.Contains(sampleStart) < 0) { mOutOfOrderCount++; //throw new Exception("samples out of order"); } mUnusedTime += (sampleStart - currentLine.mEnd); currentLine = new Line1D(sampleStart, sampleEnd); mSegmentList.Add(currentLine); } } }
//hmm should use strong types here?... //uint offset could make this difficult to used do to ordering constraints static public ArrayList MergeDutyCycle(ArrayList a, ArrayList b, uint offset) { ArrayList mergedList = new ArrayList(); int bIndex = 0; int aIndex = 0; Line1D bLine = null; Line1D aLine = null; Line1D currentLine = null; bool bReprocessCurrentLine = false; while (aIndex < a.Count && bIndex < b.Count) { if (((a[aIndex] as Line1D).mStart) < ((b[bIndex] as Line1D).mStart + offset)) { currentLine = new Line1D((a[aIndex] as Line1D).mStart, (a[aIndex] as Line1D).mEnd); aIndex++; } else if ((currentLine == null) || ((b[bIndex] as Line1D).mEnd + offset > currentLine.mEnd)) { currentLine = new Line1D((b[bIndex] as Line1D).mStart + offset, (b[bIndex] as Line1D).mEnd + offset); bIndex++; } else { bReprocessCurrentLine = true; } while (bIndex < b.Count) { bLine = (b[bIndex] as Line1D); if (currentLine.Contains(bLine.mStart + offset) == 0) { if (currentLine.Contains(bLine.mEnd + offset) != 0) { currentLine.mEnd = bLine.mEnd + offset; } bIndex++; } else { //CLM If this item isn't found, we break, causing an infite loop here... so increment bIndex bIndex++; break; } } while (aIndex < a.Count) { aLine = (a[aIndex] as Line1D); if (currentLine.Contains(aLine.mStart) == 0) { if (currentLine.Contains(aLine.mEnd) != 0) { currentLine.mEnd = aLine.mEnd; } aIndex++; } else { //CLM If this item isn't found, we break, causing an infite loop here... so increment aIndex aIndex++; break; } } if (!bReprocessCurrentLine) { mergedList.Add(currentLine); } bReprocessCurrentLine = false; } while (aIndex < a.Count) { mergedList.Add(new Line1D((a[aIndex] as Line1D).mStart, (a[aIndex] as Line1D).mEnd)); aIndex++; } while (bIndex < b.Count) { mergedList.Add(new Line1D((b[bIndex] as Line1D).mStart + offset, (b[bIndex] as Line1D).mEnd + offset)); bIndex++; } return(mergedList); }
public bool Contains(Line1D line) => J1 <= line.J1 && line.J2 <= J2;