public Vector2d GetDegreePoint(long degree) { if (Points.Length == 1) { return(Points[0]); ; } else if (Points.Length <= 0) { return(Vector2d.zero); ; } if (Looped) { degree = degree.Mod(FixedMath.One); } else { if (degree < 0) { degree = 0; } if (degree > FixedMath.One) { degree = FixedMath.One; } } //TODO: Degree guards long degreeMag = TotalLength.Mul(degree); long distanceAcc = 0; for (int i = 0; i < PointDistances.Length; i++) { long curDistance = PointDistances [i]; long nextDistanceAcc = distanceAcc + curDistance; if (nextDistanceAcc >= degreeMag) { long fraction = (degreeMag - distanceAcc).Div(curDistance); long index1 = i; long index2 = i + 1; if (index2 >= Points.Length) { index2 = 0; } Vector2d ret = Points [index1].Lerped(Points [index2], fraction); return(ret + Offset); } distanceAcc = nextDistanceAcc; } throw new System.Exception(); }
/// <summary> /// [Pure] このDendriteの簡易的な統計量を出力する /// </summary> public string GetInfo() { StringBuilder sb = new StringBuilder(); sb.AppendLine("Num of nodes: " + idsum.ToString()); sb.AppendLine("Num of end nodes: " + edge.ToString()); sb.AppendLine("Num of branching nodes: " + branch.ToString()); sb.AppendLine("Max real distance: " + MaxRealDistance.ToString()); sb.AppendLine("Max electrical distance: " + MaxElectricalDistance.ToString()); sb.AppendLine("Total real distance: " + TotalLength.ToString()); sb.AppendLine("Total electrical distance: " + TotalElectricalLength.ToString()); return(sb.ToString()); }
public override int GetHashCode() { var hashCode = -889318115; hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(GID); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(TaskName); hashCode = hashCode * -1521134295 + Status.GetHashCode(); hashCode = hashCode * -1521134295 + TotalLength.GetHashCode(); hashCode = hashCode * -1521134295 + CompletedLength.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Link); return(hashCode); }
public async Task GetSequence_ChunkForExistingSequence_SequenceReturned() { var envelope1 = new RawInboundEnvelope( new byte[] { 0x01, 0x02, 0x03 }, new MessageHeaderCollection { { DefaultMessageHeaders.MessageId, "123" }, { DefaultMessageHeaders.ChunkIndex, "0" }, { DefaultMessageHeaders.ChunksCount, "4" } }, new TestConsumerEndpoint("test"), "test", new TestOffset()); var envelope2 = new RawInboundEnvelope( new byte[] { 0x04, 0x05, 0x06 }, new MessageHeaderCollection { { DefaultMessageHeaders.MessageId, "123" }, { DefaultMessageHeaders.ChunkIndex, "1" }, { DefaultMessageHeaders.ChunksCount, "4" } }, new TestConsumerEndpoint("test"), "test", new TestOffset()); var reader = new ChunkSequenceReader(); var context1 = ConsumerPipelineContextHelper.CreateSubstitute( envelope1, sequenceStore: _defaultSequenceStore); var sequence1 = await reader.GetSequenceAsync(context1); sequence1.Should().NotBeNull(); sequence1.Should().BeOfType <ChunkSequence>(); sequence1 !.TotalLength.Should().Be(4); sequence1.IsNew.Should().BeTrue(); var context2 = ConsumerPipelineContextHelper.CreateSubstitute( envelope2, sequenceStore: _defaultSequenceStore); var sequence2 = await reader.GetSequenceAsync(context2); sequence2.Should().NotBeNull(); sequence2.Should().BeSameAs(sequence1); sequence2 !.IsNew.Should().BeFalse(); }
public override string ToString() => $"\nSetId: {Id}\n" + $"RankedStatus: {RankedStatus}\n" + $"Artist: {Artist}\n" + $"Title: {Title}\n" + $"Creator: {Creator}\n" + $"Tags: [{Tags.Join(", ")}]\n" + $"Modes: [{Mode.Select(s => s.ToString()).Join(", ")}]\n" + $"DiffNames: [{DiffName.Join(", ")}]\n" + $"Cs: [{Cs.Select(s => s.ToString()).Join(", ")}]\n" + $"Ar: [{Ar.Select(s => s.ToString()).Join(", ")}]\n" + $"Od: [{Od.Select(s => s.ToString()).Join(", ")}]\n" + $"Hp: [{Hp.Select(s => s.ToString()).Join(", ")}]\n" + $"DifficultyRating: [{DifficultyRating.Select(s => s.ToString(CultureInfo.InvariantCulture)).Join(", ")}]\n" + $"Bpm: [{Bpm.Select(s => s.ToString()).Join(", ")}]\n" + $"TotalLength: [{TotalLength.Select(s => s.ToString()).Join(", ")}]\n" + $"Genre: {Genre}\n" + $"Language: {Language}\n" + $"DiffName: [{Mode.Select(s => s.ToString()).Join(", ")}]\n" + $"ApprovedDate: {ApprovedDate}";
public override byte[] ToArray() { TotalLength = Length; for (int i = 0; i < NumberOfInterfaces; i++) { TotalLength += InterfaceDescriptor[i].Length; for (int j = 0; j < InterfaceDescriptor[i].NumberOfEndpoints; j++) { TotalLength += InterfaceDescriptor[i].EndpointDescriptor[j].Length; } } var arr = new byte[TotalLength]; var offset = Length; arr[0x0] = Length; arr[0x1] = (byte)Type; arr[0x2] = TotalLength.LoByte(); arr[0x3] = TotalLength.HiByte(); arr[0x4] = NumberOfInterfaces; arr[0x5] = ConfigurationValue; arr[0x6] = ConfigurationIndex; arr[0x7] = Attributes; arr[0x8] = MaxPower; for (int i = 0; i < NumberOfInterfaces; i++) { InterfaceDescriptor[i].ToArray().CopyTo(arr, offset); offset += InterfaceDescriptor[i].Length; for (int j = 0; j < InterfaceDescriptor[i].NumberOfEndpoints; j++) { InterfaceDescriptor[i].EndpointDescriptor[j].ToArray().CopyTo(arr, offset); offset += InterfaceDescriptor[i].EndpointDescriptor[j].Length; } } return(arr); }
public async Task GetSequence_FirstChunk_SequenceReturned() { var envelope = new RawInboundEnvelope( new byte[] { 0x01, 0x02, 0x03 }, new MessageHeaderCollection { { DefaultMessageHeaders.MessageId, "123" }, { DefaultMessageHeaders.ChunkIndex, "0" }, { DefaultMessageHeaders.ChunksCount, "4" } }, new TestConsumerEndpoint("test"), "test", new TestOffset()); var context = ConsumerPipelineContextHelper.CreateSubstitute( envelope, sequenceStore: _defaultSequenceStore); var sequence = await new ChunkSequenceReader().GetSequenceAsync(context); sequence.Should().NotBeNull(); sequence !.TotalLength.Should().Be(4); sequence.IsNew.Should().BeTrue(); }
/// <summary cref="Packet.ToString(StringOutputType)" /> public override string ToString(StringOutputType outputFormat) { var buffer = new StringBuilder(); string color = ""; string colorEscape = ""; if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored) { color = Color; colorEscape = AnsiEscapeSequences.Reset; } if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored) { // build the output string buffer.AppendFormat("{0}[IPv4Packet: SourceAddress={2}, DestinationAddress={3}, HeaderLength={4}, Protocol={5}, TimeToLive={6}]{1}", color, colorEscape, SourceAddress, DestinationAddress, HeaderLength, Protocol, TimeToLive); } if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored) { // collect the properties and their value Dictionary <string, string> properties = new Dictionary <string, string>(); properties.Add("version", Version.ToString()); // FIXME: Header length output is incorrect properties.Add("header length", HeaderLength + " bytes"); string diffServices = Convert.ToString(DifferentiatedServices, 2).PadLeft(8, '0').Insert(4, " "); properties.Add("differentiated services", "0x" + DifferentiatedServices.ToString("x").PadLeft(2, '0')); properties.Add("", diffServices.Substring(0, 7) + ".. = [" + (DifferentiatedServices >> 2) + "] code point"); properties.Add(" ", ".... .." + diffServices[6] + ". = [" + diffServices[6] + "] ECN"); properties.Add(" ", ".... ..." + diffServices[7] + " = [" + diffServices[7] + "] ECE"); properties.Add("total length", TotalLength.ToString()); properties.Add("identification", "0x" + Id.ToString("x") + " (" + Id + ")"); string flags = Convert.ToString(FragmentFlags, 2).PadLeft(8, '0').Substring(5, 3); properties.Add("flags", "0x" + FragmentFlags.ToString("x").PadLeft(2, '0')); properties.Add(" ", flags[0] + ".. = [" + flags[0] + "] reserved"); properties.Add(" ", "." + flags[1] + ". = [" + flags[1] + "] don't fragment"); properties.Add(" ", ".." + flags[2] + " = [" + flags[2] + "] more fragments"); properties.Add("fragment offset", FragmentOffset.ToString()); properties.Add("time to live", TimeToLive.ToString()); properties.Add("protocol", Protocol.ToString() + " (0x" + Protocol.ToString("x") + ")"); properties.Add("header checksum", "0x" + Checksum.ToString("x") + " [" + (ValidChecksum ? "valid" : "invalid") + "]"); properties.Add("source", SourceAddress.ToString()); properties.Add("destination", DestinationAddress.ToString()); // calculate the padding needed to right-justify the property names int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys)); // build the output string buffer.AppendLine("IP: ******* IPv4 - \"Internet Protocol (Version 4)\" - offset=? length=" + TotalPacketLength); buffer.AppendLine("IP:"); foreach (var property in properties) { if (property.Key.Trim() != "") { buffer.AppendLine("IP: " + property.Key.PadLeft(padLength) + " = " + property.Value); } else { buffer.AppendLine("IP: " + property.Key.PadLeft(padLength) + " " + property.Value); } } buffer.AppendLine("IP:"); } // append the base class output buffer.Append(base.ToString(outputFormat)); return(buffer.ToString()); }
public void RefreshLength() { size.Text = string.Format("{0} Кб из {1} Кб", SelectedLength.ToString("#,#;0;0"), TotalLength.ToString("#,#;0;0")); }