public static SegmentCollection GetRegions(string code) { MatchCollection mc = regexRegion.Matches(code); SegmentCollection segments = new SegmentCollection(); string segment; int position = 0; foreach(Match m in mc) { segment = code.Substring(position, m.Index - position); //截取到时标志位前的内容 position = m.Index + m.Length; segments.Add(new Segment(segment)); //添加正文片断 string content = m.Groups["Template"].Value; //除去起始标签的内容部分 string nameTag = m.Groups["Name"].Value; //起始标签的标识名; 例如: <!--!Title--> , 结果: Title string matchResult = m.Value; //匹配后的整个结果; 例如: 最后结果<!--!Title-->Category: {CategoryName}<!--Title!--> segments.Add(new Region(nameTag, matchResult, content)); //添加要替换部分的信息 } segment = code.Substring(position, code.Length - position); //获取最后剩余的内容部分 segments.Add(new Segment(segment)); return segments; /*example: * content: <title><!--!Title-->Category: {CategoryName}<!--Title!--> Of Northwind</title> * result: * [0] : <title> -- segment * [1] : <!--!Title-->Category: {CategoryName}<!--Title!--> -- region * [0]: Category: -- segment * [1]: {CategoryName} -- field * [2]: "" -- segment * [2] : of Northwind</title> -- segment */ }
// Creates a polyline with two paths in the shape of an 'X' centered at the given point private Polyline CreatePolylineX(MapPoint center, double length) { var halfLen = length / 2.0; LineSegment segment = new LineSegment( new MapPoint(center.X - halfLen, center.Y + halfLen, MyMapView.SpatialReference), new MapPoint(center.X + halfLen, center.Y - halfLen, MyMapView.SpatialReference)); LineSegment segment2 = new LineSegment( new MapPoint(center.X + halfLen, center.Y + halfLen, MyMapView.SpatialReference), new MapPoint(center.X - halfLen, center.Y - halfLen, MyMapView.SpatialReference)); var segmentCollection = new SegmentCollection(MyMapView.SpatialReference) { segment }; var segmentCollection2 = new SegmentCollection(MyMapView.SpatialReference) { segment2 }; return(new Polyline(new [] { segmentCollection, segmentCollection2 }, MyMapView.SpatialReference)); }
public void TestVertexCollection() { var vertexCollection1 = new VertexUnsortedCollection(new StackListQueue <int> { 1, 2, 3, 4, 6 }); var vertexCollection2 = new VertexUnsortedCollection(new StackListQueue <int> { 1, 2, 3, 4, 5 }); var vertexCollection3 = new VertexUnsortedCollection(new StackListQueue <int> { 5, 1, 2, 3, 4 }); var vertexCollection4 = new VertexUnsortedCollection(new StackListQueue <int> { 5, 4, 3, 2, 1 }); var circle1 = new Circle(new VertexUnsortedCollection(new StackListQueue <int> { 2, 3, 4, 6, 1 })); var circle2 = new Circle(new VertexUnsortedCollection(new StackListQueue <int> { 6, 4, 3, 2, 1 })); var segment1 = new Segment(new VertexUnsortedCollection(new StackListQueue <int> { 6, 1 })); var segment2 = new Segment(new VertexUnsortedCollection(new StackListQueue <int> { 6, 1 })); var segmentCollection1 = new SegmentCollection { segment1 }; var segmentCollection2 = new SegmentCollection { segment2 }; }
public Region(string name, string code, string template) { this.name = name; this.code = code; this.template = template; this.segments = TemplateParser.GetFields(this.template); }
public void InsertSegmentCollectionThenFindTest() { SegmentCollection segs1 = new SegmentCollection(); SegmentCollection segs2 = new SegmentCollection(); Segment s1, s2, s3, s4; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf2, 6, 8); s3 = new Segment(buf2, 0, 5); s4 = new Segment(buf1, 6, 8); segs1.Append(s1); segs1.Append(s2); segs2.Append(s3); segs2.Append(s4); segs1.Insert(segs2, 4); long map; List <Segment> .Node n; //segs1.List.Display(); Assert.AreSame(s1, segs1.FindSegment(3, out map, out n), "s1"); Assert.AreEqual(0, map); Assert.AreSame(s3, segs1.FindSegment(7, out map, out n), "s3"); Assert.AreEqual(4, map); Assert.AreSame(s4, segs1.FindSegment(12, out map, out n), "s4"); Assert.AreEqual(10, map); Segment s5 = segs1.FindSegment(13, out map, out n); Assert.AreEqual(13, map); Assert.IsTrue(s5.End == s5.Start + 1, "s1'"); Assert.AreSame(s2, segs1.FindSegment(15, out map, out n), "s2"); Assert.AreEqual(15, map); }
public void InsertSegmentCollectionTest2() { SegmentCollection segs1 = new SegmentCollection(); SegmentCollection segs2 = new SegmentCollection(); Segment s1, s2, s3, s4; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf2, 6, 8); s3 = new Segment(buf2, 0, 5); s4 = new Segment(buf1, 6, 8); segs1.Append(s1); segs1.Append(s2); segs2.Append(s3); segs2.Append(s4); segs1.Insert(segs2, 4); Assert.IsTrue(s1.End == 3); Assert.AreSame(s1, segs1.List[0]); Assert.AreSame(s3, segs1.List[1]); Assert.AreSame(s4, segs1.List[2]); Assert.AreSame(s2, segs1.List[4]); Assert.IsTrue(((Segment)segs1.List[3]).Start == 4); Assert.IsTrue(((Segment)segs1.List[3]).Buffer == buf1); Assert.IsTrue(((Segment)segs1.List[3]).End == 5); //Assert.IsNull(segs[1]); }
public static LIN AddLIN(this SegmentCollection doc) { var l = new LIN(); doc.Add(l); return(l); }
public void ParseTemplate() { if(string.IsNullOrEmpty(this.template)) { throw new Exception("No template was assigned."); } this.segments = TemplateParser.GetRegions(this.template); }
public void SetUp() { _raster = new Mock <IRaster>(MockBehavior.Strict); _raster.Setup(raster => raster.NumberOfBands).Returns(4); _raster.Setup(raster => raster.NumberOfColumns).Returns(20); _raster.Setup(raster => raster.NumberOfRows).Returns(15); _raster.Setup(raster => raster.GetValues(It.IsAny <Int32>(), It.IsAny <Int32>())).Returns(new UInt32[4]); _raster.Setup(raster => raster.GetFloatValues(It.IsAny <Int32>(), It.IsAny <Int32>())).Returns(new Double[4]); _collection = new SegmentCollection(_raster.Object); }
private void InitEmbedded() { string codeWithComments = GetContentFromPath(FilePath); code = CommentRemover.GetCodeWithoutComments(codeWithComments); _segmentCollection = new SegmentCollection(code); string extension = Path.GetExtension(FilePath); ShaderStageFlags shaderStage = Constants.FileExtensionToShaderStageConverter.Convert(extension); ShaderStage = shaderStage; }
public void AppendSegmentsTest1() { SegmentCollection segs = new SegmentCollection(); Segment s1, s2; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf2, 6, 5); segs.Append(s1); segs.Append(s2); Assert.AreSame(s1, segs.List[0]); Assert.AreSame(s2, segs.List[1]); }
/// <summary> /// Returns the raster factory of the collection. /// </summary> /// <param name="segments">The segments.</param> /// <returns>The raster factory of the collection.</returns> /// <exception cref="System.ArgumentNullException">The segment collection is null.</exception> /// <exception cref="System.ArgumentException">The segment collection has no raster.</exception> private IRasterFactory GetFactory(SegmentCollection segments) { if (segments == null) { throw new ArgumentNullException(nameof(segments), "The segment collection is null."); } if (segments.Raster == null) { throw new ArgumentException("The segment collection has no raster.", nameof(segments)); } return(segments.Raster.Factory); }
public void AppendSegmentsTest2() { SegmentCollection segs = new SegmentCollection(); Segment s1, s2; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf1, 6, 8); segs.Append(s1); segs.Append(s2); Assert.AreSame(s1, segs.List[0]); Assert.IsTrue(s1.Start == 0); Assert.IsTrue(s1.End == 8); //Assert.IsNull(segs[1]); }
public void DeleteFromSegmentCollectionTest4() { SegmentCollection segs1 = new SegmentCollection(); Segment s1; s1 = new Segment(buf1, 0, 8); segs1.Append(s1); SegmentCollection del = segs1.DeleteRange(0, 8); Assert.AreEqual(0, segs1.List.Count, "#0"); Assert.AreEqual(1, del.List.Count, "#5"); Assert.AreEqual(0, ((Segment)del.List[0]).Start, "#6"); Assert.AreEqual(8, ((Segment)del.List[0]).End, "#7"); }
public Uri GetUri() { StringBuilder builder = new StringBuilder(Url); SegmentCollection segments = new SegmentCollection(); segments.Add(this.Version); segments.Add(this.Server); segments.Add(this.Ting); foreach (var segment in segments) { builder.Append(string.Format("/{0}", segment.Name)); } builder.Append("?"); builder.Append(Parameters.ToString()); return(new Uri(builder.ToString())); }
public static SegmentCollection GetFields(string code) { MatchCollection mc = regexField.Matches(code); SegmentCollection segments = new SegmentCollection(); string name; string format; string length; int len = 0; string segment; int position = 0; foreach(Match m in mc) { segment = code.Substring(position, m.Index - position); segments.Add(new Segment(segment)); //添加正文片断 position = m.Index + m.Length; name = m.Groups["Name"].Value; format = m.Groups["Format"].Value; length = m.Groups["Length"].Value; if(string.IsNullOrEmpty(name)) { name = string.Empty; } if(string.IsNullOrEmpty(format)) { format = string.Empty; } else { format = format.Substring(2); format = format.Substring(0, format.Length - 1); } if(!string.IsNullOrEmpty(length)) { int.TryParse(length.Substring(1), out len); } segments.Add(new Field(m.Value, name, len, format)); } segment = code.Substring(position, code.Length - position); segments.Add(new Segment(segment)); return segments; }
public void InsertInEmptyCollection() { SegmentCollection segs1 = new SegmentCollection(); SegmentCollection segs2 = new SegmentCollection(); Segment s1 = new Segment(buf1, 0, 4); Segment s2 = new Segment(buf2, 7, 9); segs2.Append(s1); segs2.Append(s2); segs1.Insert(segs2, 0); Assert.AreEqual(2, segs1.List.Count, "#1"); Assert.AreEqual(4, (segs1.List[0] as Segment).End, "#2"); Assert.AreEqual(7, (segs1.List[1] as Segment).Start, "#3"); Assert.AreEqual(9, (segs1.List[1] as Segment).End, "#4"); }
IEnumerable <Segment> GetControlSums(SegmentCollection segments) { decimal ControlQuantity = segments.Where(s => s.Tag == "QTY").Sum(qty => Helpers.SegmentHelpers.GetQtyValue(qty)); int LineCount = segments.Where(s => s.Tag == "LIN").Count(); int SegmentCount = segments.Count(); for (int i = SegmentCount - 1; i > 0; --i) { if (segments[i].Tag == "BGM") { SegmentCount -= i; break; } } return(Helpers.Interchange.GetMessageTrailer(ControlQuantity, LineCount)); }
public void DeleteFromSegmentCollectionTest1() { SegmentCollection segs1 = new SegmentCollection(); Segment s1, s2, s3, s4; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf2, 6, 8); s3 = new Segment(buf2, 0, 5); s4 = new Segment(buf1, 6, 8); segs1.Append(s1); segs1.Append(s2); segs1.Append(s3); segs1.Append(s4); segs1.DeleteRange(7, 15); Assert.AreEqual(3, segs1.List.Count, "#1"); Assert.AreEqual(6, ((Segment)segs1.List[0]).Size, "#2"); Assert.AreEqual(6, ((Segment)segs1.List[1]).Start, "#3"); Assert.AreEqual(6, ((Segment)segs1.List[1]).End, "#4"); Assert.AreEqual(7, ((Segment)segs1.List[2]).Start, "#5"); Assert.AreEqual(8, ((Segment)segs1.List[2]).End, "#6"); }
/// <summary> /// Initializes a new instance of the <see cref="ReferenceMatchingClassification" /> class. /// </summary> /// <param name="source">The source.</param> /// <param name="target">The target.</param> /// <param name="parameters">The parameters.</param> /// <exception cref="System.ArgumentNullException"> /// The source is null. /// or /// The method requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The parameters do not contain a required parameter value. /// or /// The type of a parameter does not match the type specified by the method. /// or /// The value of a parameter is not within the expected range. /// or /// The specified source and result are the same objects, but the method does not support in-place operations. /// or /// The source geometry does not contain raster data. /// or /// The parameter value does not satisfy the conditions of the parameter. /// </exception> public ReferenceMatchingClassification(ISpectralGeometry source, ISpectralGeometry target, IDictionary <OperationParameter, Object> parameters) : base(source, target, SpectralOperationMethods.ReferenceMatchingClassification, parameters) { _referenceGeometry = ResolveParameter <ISpectralGeometry>(SpectralOperationParameters.ClassificationReferenceGeometry); _segmentCollection = ResolveParameter <SegmentCollection>(SpectralOperationParameters.SegmentCollection); if (_segmentCollection == null) { ISegmentedRaster raster = source.Raster as ISegmentedRaster; if (raster != null) { _segmentCollection = raster.Segments; } else { throw new ArgumentException($"No {SpectralOperationParameters.SegmentCollection.Name} was provided!"); } } else if (_segmentCollection.Raster != Source.Raster) { throw new ArgumentException($"The parameter value ({SpectralOperationParameters.SegmentCollection.Name}) does not satisfy the conditions of the parameter."); } }
public void SegmentCollectionConstructorTest() { // create using raster SegmentCollection collection = new SegmentCollection(_raster.Object); Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, collection.Count); Assert.AreEqual(_raster.Object, collection.Raster); // create using copy constructor SegmentCollection cloneCollection = new SegmentCollection(collection); Assert.AreEqual(collection.Count, cloneCollection.Count); Assert.AreEqual(collection.Raster, cloneCollection.Raster); // exceptions Assert.Throws <ArgumentNullException>(() => collection = new SegmentCollection((IRaster)null)); Assert.Throws <ArgumentNullException>(() => collection = new SegmentCollection((SegmentCollection)null)); }
public void FindSegmentTest() { SegmentCollection segs1 = new SegmentCollection(); Segment s1, s2, s3, s4; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf2, 6, 8); s3 = new Segment(buf2, 0, 5); s4 = new Segment(buf1, 6, 8); segs1.Append(s1); segs1.Append(s2); segs1.Append(s3); segs1.Append(s4); long map; List <Segment> .Node n; Assert.AreSame(s1, segs1.FindSegment(4, out map, out n)); Assert.AreEqual(0, map); Assert.AreSame(s3, segs1.FindSegment(10, out map, out n)); Assert.AreEqual(9, map); }
public void InsertToSegmentCollectionThenDeleteTest() { SegmentCollection segs1 = new SegmentCollection(); Segment s1, s2; s1 = new Segment(buf1, 0, 2); s2 = new Segment(buf1, 3, 5); segs1.Append(s1); SegmentCollection segs2 = new SegmentCollection(); segs2.Append(s2); segs1.Insert(segs2, 2); segs1.DeleteRange(2, 4); long map; List <Segment> .Node n; Segment s = segs1.FindSegment(0, out map, out n); Assert.IsNotNull(s, "#1"); Assert.AreEqual(0, map, "#2"); Assert.AreEqual(0, s.Start, "#3"); }
public void ReplaceAtEnd() { SegmentCollection segs1 = new SegmentCollection(); Segment s1, s2, s3; s1 = new Segment(buf1, 0, 4); s2 = new Segment(buf2, 7, 7); s3 = new Segment(buf2, 8, 8); segs1.Append(s1); //segs1.List.Display(); segs1.DeleteRange(4, 4); //segs1.List.Display(); segs1.Append(s2); //segs1.List.Display(); segs1.DeleteRange(4, 4); //segs1.List.Display(); segs1.Append(s3); //segs1.List.Display(); Assert.AreEqual(2, segs1.List.Count, "#1"); Assert.AreEqual(3, (segs1.List[0] as Segment).End, "#2"); Assert.AreEqual(8, (segs1.List[1] as Segment).Start, "#3"); Assert.AreEqual(8, (segs1.List[1] as Segment).End, "#4"); }
public void InsertSegmentCollectionTest1() { SegmentCollection segs1 = new SegmentCollection(); SegmentCollection segs2 = new SegmentCollection(); Segment s1, s2, s3, s4; s1 = new Segment(buf1, 0, 5); s2 = new Segment(buf2, 6, 8); s3 = new Segment(buf2, 0, 5); s4 = new Segment(buf1, 6, 8); segs1.Append(s1); segs1.Append(s2); segs2.Append(s3); segs2.Append(s4); segs1.Insert(segs2, 6); Assert.AreSame(s1, segs1.List[0]); Assert.AreSame(s3, segs1.List[1]); Assert.AreSame(s4, segs1.List[2]); Assert.AreSame(s2, segs1.List[3]); //Assert.IsNull(segs[1]); }
/// <summary> /// Creates a segmented raster. /// </summary> /// <param name="segments">The segment collection.</param> /// <returns>The produced raster.</returns> /// <exception cref="System.ArgumentNullException">The segment collection is null.</exception> /// <exception cref="System.ArgumentException">The segment collection has no raster.</exception> public IRaster CreateSegmentedRaster(SegmentCollection segments) { return(new SegmentedRaster(segments)); }
IEnumerator getOrders() { var _request = UnityWebRequest.Get("http://192.168.2.177/api/plant/lucasnuelle/"); yield return(_request.SendWebRequest()); if (_request.isNetworkError) { Debug.Log("Error: " + _request.error); } else { var result = _request.downloadHandler.text; Debug.Log("Received " + result); parseData = JsonUtility.FromJson <SegmentCollection>(result); Debug.Log("size: " + parseData.segments.Length); //get the length of the all segments :8 for (int i = 0; i < parseData.segments.Length; i++) { if (parseData.segments[i].identifier.Contains("IMS1")) { string IMS3StateOutput = parseData.segments[i].state_name; string IMS3IdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS3IdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS3StateOutput); //display the state name gameObject.GetComponent <demoIoT>().IMS3Valtext = IMS3StateOutput; gameObject.GetComponent <demoIoT>().IMS3StationValtext = IMS3IdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS3A")) { string IMS3AStateOutput = parseData.segments[i].state_name; string IMS3AIdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS3AIdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS3AStateOutput); gameObject.GetComponent <demoIoT>().IMS3AValtext = IMS3AStateOutput; gameObject.GetComponent <demoIoT>().IMS3AStationValtext = IMS3AIdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS3B")) { string IMS3BStateOutput = parseData.segments[i].state_name; string IMS3BIdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS3BIdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS3BStateOutput); gameObject.GetComponent <demoIoT>().IMS3BValtext = IMS3BStateOutput; gameObject.GetComponent <demoIoT>().IMS3BStationValtext = IMS3BIdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS4A")) { string IMS4AStateOutput = parseData.segments[i].state_name; string IMS4AIdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS4AIdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS4AStateOutput); gameObject.GetComponent <demoIoT>().IMS4AValtext = IMS4AStateOutput; gameObject.GetComponent <demoIoT>().IMS4AStationValtext = IMS4AIdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS4B")) { string IMS4BStateOutput = parseData.segments[i].state_name; string IMS4BIdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS4BIdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS4BStateOutput); gameObject.GetComponent <demoIoT>().IMS4BValtext = IMS4BStateOutput; gameObject.GetComponent <demoIoT>().IMS4BStationValtext = IMS4BIdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS5A")) { string IMS5AStateOutput = parseData.segments[i].state_name; string IMS5AIdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS5AIdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS5AStateOutput); gameObject.GetComponent <demoIoT>().IMS5AValtext = IMS5AStateOutput; gameObject.GetComponent <demoIoT>().IMS5AStationValtext = IMS5AIdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS5B")) { string IMS5BStateOutput = parseData.segments[i].state_name; string IMS5BIdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS5BIdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS5BStateOutput); gameObject.GetComponent <demoIoT>().IMS5BValtext = IMS5BStateOutput; gameObject.GetComponent <demoIoT>().IMS5BStationValtext = IMS5BIdentifierOutput; } if (parseData.segments[i].identifier.Contains("IMS7")) { string IMS7StateOutput = parseData.segments[i].state_name; string IMS7IdentifierOutput = parseData.segments[i].identifier; Debug.Log("State Name: " + IMS7IdentifierOutput); //display the identifier Debug.Log("Machine state: " + IMS7StateOutput); gameObject.GetComponent <demoIoT>().IMS7Valtext = IMS7StateOutput; gameObject.GetComponent <demoIoT>().IMS7StationValtext = IMS7IdentifierOutput; } } } }
public Segment(SegmentCollection parent) { _parent = parent; }
// Creates a polyline with two paths in the shape of an 'X' centered at the given point private Polyline CreatePolylineX(MapPoint center, double length) { var halfLen = length / 2.0; LineSegment segment = new LineSegment( new MapPoint(center.X - halfLen, center.Y + halfLen, MyMapView.SpatialReference), new MapPoint(center.X + halfLen, center.Y - halfLen, MyMapView.SpatialReference)); LineSegment segment2 = new LineSegment( new MapPoint(center.X + halfLen, center.Y + halfLen, MyMapView.SpatialReference), new MapPoint(center.X - halfLen, center.Y - halfLen, MyMapView.SpatialReference)); var segmentCollection = new SegmentCollection(MyMapView.SpatialReference) { segment }; var segmentCollection2 = new SegmentCollection(MyMapView.SpatialReference) { segment2 }; return new Polyline(new [] { segmentCollection, segmentCollection2}, MyMapView.SpatialReference); }
/// <summary> /// Initializes a new instance of the <see cref="SegmentBasedClassification" /> class. /// </summary> /// <param name="source">The source.</param> /// <param name="target">The target.</param> /// <param name="parameters">The parameters.</param> /// <exception cref="System.ArgumentNullException"> /// The source is null. /// or /// The method requires parameters which are not specified. /// </exception> /// <exception cref="System.ArgumentException"> /// The parameters do not contain a required parameter value. /// or /// The type of a parameter does not match the type specified by the method. /// or /// The value of a parameter is not within the expected range. /// or /// The specified source and result are the same objects, but the method does not support in-place operations. /// or /// The source geometry does not contain raster data. /// or /// The raster format of the source is not supported by the method. /// </exception> public SegmentBasedClassification(ISpectralGeometry source, ISpectralGeometry target, IDictionary <OperationParameter, Object> parameters) : base(source, target, SpectralOperationMethods.SegmentBasedClassification, parameters) { _segmentCollection = ResolveParameter <SegmentCollection>(SpectralOperationParameters.SegmentCollection); }
public BooleanVector GetVector(Circle circle) { Debug.Assert(circle.Any()); int count = circle.Count; var collection = new SegmentCollection(); for (int i = 0; i < count; i++) { collection.Add(new Segment(circle[i], circle[(i + 1) % count])); } Debug.Assert(collection.All(Contains)); List <int> indexes; if (Settings.EnableCudafy) { try { IEnumerable <IEnumerable <int> > list1 = collection.Select(GetInts); IEnumerable <IEnumerable <int> > list2 = this.Select(GetInts); int[,] matrix; lock (CudafySequencies.Semaphore) { CudafySequencies.SetSequencies( list1.Select(item => item.ToArray()).ToArray(), list2.Select(item => item.ToArray()).ToArray() ); CudafySequencies.Execute("Compare"); matrix = CudafySequencies.GetMatrix(); } lock (CudafyMatrix.Semaphore) { CudafyMatrix.SetMatrix(matrix); CudafyMatrix.ExecuteRepeatZeroIndexOfZero(); indexes = CudafyMatrix.GetIndexes().ToList(); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); indexes = collection.Select(segment => IndexOf(segment)).ToList(); } } else { indexes = collection.Select(segment => IndexOf(segment)).ToList(); } indexes.Sort(); var booleanVector = new BooleanVector(); if (indexes[0] > 0) { booleanVector.AddRange(Enumerable.Repeat(false, indexes[0])); } booleanVector.Add(true); for (int i = 1; i < indexes.Count; i++) { if (indexes[i] - indexes[i - 1] > 1) { booleanVector.AddRange(Enumerable.Repeat(false, indexes[i] - indexes[i - 1] - 1)); } booleanVector.Add(true); } return(booleanVector); }
public void SegmentCollectionMergeSegmentsTest() { // merge using segments SegmentCollection collection = new SegmentCollection(_raster.Object); Segment segment = collection.GetSegment(0, 0); Int32 count = collection.Count; for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++) { for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++) { Segment otherSegment = collection.GetSegment(rowIndex, columnIndex); collection.MergeSegments(segment, otherSegment); Assert.IsFalse(segment != otherSegment && collection.Contains(segment) && collection.Contains(otherSegment)); segment = collection.GetSegment(rowIndex, columnIndex); Assert.AreEqual(count, collection.Count); count--; } } Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, segment.Count); // merge using segment and indices collection = new SegmentCollection(_raster.Object); segment = collection.GetSegment(0, 0); count = collection.Count; for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++) { for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++) { collection.MergeSegments(segment, rowIndex, columnIndex); Segment otherSegment = collection.GetSegment(rowIndex, columnIndex); Assert.AreEqual(segment, otherSegment); Assert.AreEqual(count, collection.Count); count--; } } Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, segment.Count); // merge using indices collection = new SegmentCollection(_raster.Object); segment = collection.GetSegment(0, 0); count = collection.Count; for (Int32 rowIndex = 0; rowIndex < _raster.Object.NumberOfRows; rowIndex++) { for (Int32 columnIndex = 0; columnIndex < _raster.Object.NumberOfColumns; columnIndex++) { collection.MergeSegments(0, 0, rowIndex, columnIndex); Segment otherSegment = collection.GetSegment(rowIndex, columnIndex); Assert.AreEqual(segment, otherSegment); Assert.AreEqual(count, collection.Count); count--; } } Assert.AreEqual(_raster.Object.NumberOfColumns * _raster.Object.NumberOfRows, segment.Count); }
/// <summary> /// Parse the Seats Json into List of Seats /// </summary> /// <param name="htmlTask"></param> /// <returns></returns> public async Task<List<Seat>> ParseSeatsInfoJson(string htmlTask) { await Task.Delay(4); SegmentCollection objSegmentCollection = new SegmentCollection(); var seats = new List<Seat>(); //var html = htmlTask.Result; var html = htmlTask; if (!string.IsNullOrEmpty(html)) { var seatString = Regex.Match(html, @"""pages"":\[.*\}]", RegexOptions.IgnoreCase).Value; objSegmentCollection = JsonConvert.DeserializeObject<SegmentCollection>("{" + seatString + "}"); if (objSegmentCollection != null && objSegmentCollection.pages != null && objSegmentCollection.pages.Count > 0) { foreach (var segments in objSegmentCollection.pages.First().segments) { //For Standing Seat if (segments.generalAdmission.HasValue && ((bool)segments.generalAdmission)) { var seatData = new Seat() { Id = segments.id, Name = segments.name, IsStanding = true }; seats.Add(seatData); continue; } //Check section existance if (segments.segments != null) { //For Normal Seat //Parallel.ForEach(segments.segments, section => foreach (var section in segments.segments) { //Check rows existance if (section.segments != null) { foreach (var rows in section.segments) { //Check seat existance if (rows.placesNoKeys != null) { int Counter = 0; foreach (var seat in rows.placesNoKeys) { Counter++; if (seat.Count > 1) { var seatData = new Seat() { Id = Convert.ToString(seat[0]), Name = Convert.ToString(seat[1]), Row = rows.name, Section = section.name }; seats.Add(seatData); } if (Counter % 2 == 0) { Thread.Sleep(1); } } } } } Thread.Sleep(10); } } } } } return seats; }
/// <summary> /// Initializes a new instance of the <see cref="SegmentedRaster"/> class. /// </summary> /// <param name="segments">The collection of segments.</param> /// <exception cref="System.ArgumentNullException">The segment collection is null.</exception> /// <exception cref="System.ArgumentException">The segment collection has no raster.</exception> public SegmentedRaster(SegmentCollection segments) : base(segments.Raster.Factory, segments.Raster.Dimensions, segments.Raster.Mapper) { Segments = segments; }
private static Result <Message> CreateMessageFromSegmentCollection(SegmentCollection segment) => CreateMessageFromSegmentCollections(new List <SegmentCollection> { segment });