public void TableMatchesGeometry() { var crossSection = new CrossSectionDefinitionXYZ(); crossSection.Geometry = new LineString(new ICoordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 2, -2), new Coordinate(4, 2, -2), new Coordinate(6, 0, 0) }); Assert.AreEqual(crossSection.Geometry.Coordinates.Length, crossSection.XYZDataTable.Rows.Count); var diag = 2.0 * Math.Sqrt(2); var expectedProfileY = new double[] { 0, diag, diag + 2, 2 * diag + 2 }; var expectedProfileZ = new double[] { 0, -2, -2, 0 }; var expectedStorageZ = new double[] { 0, 0, 0, 0 }; var rows = crossSection.XYZDataTable.Rows; for (int i = 0; i < expectedProfileY.Length; i++) { var xyzRow = rows[i] as CrossSectionDataSet.CrossSectionXYZRow; Assert.AreEqual(expectedProfileY[i], xyzRow.Yq, 0.001); //2d profile Assert.AreEqual(expectedProfileZ[i], xyzRow.Z, 0.001); Assert.AreEqual(expectedStorageZ[i], xyzRow.DeltaZStorage, 0.001); } }
public void CrossSectionWithXYZDefinitionCanNotShareDefiniton() { var crossSectionDefinitionXYZ = new CrossSectionDefinitionXYZ(); var crossSection = new CrossSection(crossSectionDefinitionXYZ); crossSection.ShareDefinitionAndChangeToProxy(); }
public void ConvertXYZCrossSectionToYz() { var crossSection = new CrossSectionDefinitionXYZ(); crossSection.Geometry = new LineString(new ICoordinate[] { new Coordinate(-3, 0, 0), new Coordinate(0, 4, -5), new Coordinate(3, 0, 0) }); crossSection.XYZDataTable[1].DeltaZStorage = 1; /*crossSection.SetWithHfswData(new[] * { * new HeightFlowStorageWidth(0, 10, 10), * new HeightFlowStorageWidth(10, 20, 16) * });*/ var yzCrossSection = CrossSectionConverter.ConvertToYz(crossSection); var yQ = new[] { 0, 5, 10 }; var z = new[] { 0, -5, 0 }; var deltaZStorage = new[] { 0, 1, 0 }; Assert.AreEqual(yQ, yzCrossSection.YZDataTable.Select(r => r.Yq).ToArray()); Assert.AreEqual(z, yzCrossSection.YZDataTable.Select(r => r.Z).ToArray()); Assert.AreEqual(deltaZStorage, yzCrossSection.YZDataTable.Select(r => r.DeltaZStorage).ToArray()); }
public void SetGeometry() { var crossSection = new CrossSectionDefinitionXYZ(); crossSection.Geometry = new LineString(new ICoordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 2, -2), new Coordinate(4, 2, -2), new Coordinate(6, 0, 0) }); //xyz var diag = 2.0 * Math.Sqrt(2); var expectedProfileY = new double[] { 0, diag, diag + 2, 2 * diag + 2 }; var expectedProfileZ = new double[] { 0, -2, -2, 0 }; var profileY = crossSection.Profile.Select(p => p.X).ToList(); var profileZ = crossSection.Profile.Select(p => p.Y).ToList(); for (int i = 0; i < expectedProfileY.Length; i++) { Assert.AreEqual(expectedProfileY[i], profileY[i], 0.001); //2d profile Assert.AreEqual(expectedProfileZ[i], profileZ[i], 0.001); } }
public void CloneHydroNetworkWithVariousBranchFeatures() { var network = new HydroNetwork(); var from = new HydroNode(); var to = new HydroNode(); network.Nodes.Add(from); network.Nodes.Add(to); var channel = new Channel { Source = from, Target = to }; network.Branches.Add(channel); var compositeBranchStructure = new CompositeBranchStructure(); NetworkHelper.AddBranchFeatureToBranch(compositeBranchStructure, channel, 0); HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Weir()); HydroNetworkHelper.AddStructureToComposite(compositeBranchStructure, new Pump()); var crossSectionXYZ = new CrossSectionDefinitionXYZ { Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) }) }; HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0); var clonedHydroNetwork = (IHydroNetwork)network.Clone(); clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1); clonedHydroNetwork.CompositeBranchStructures.Should().Have.Count.EqualTo(1); clonedHydroNetwork.Weirs.Should().Have.Count.EqualTo(1); clonedHydroNetwork.Pumps.Should().Have.Count.EqualTo(1); }
private HydroNetwork GetNetwork() { var network = new HydroNetwork(); var crossSectionSectionType = new CrossSectionSectionType { Name = "Jan" }; network.CrossSectionSectionTypes.Add(crossSectionSectionType); crossSectionSectionType.Id = 666;//debug easy by idd var from = new HydroNode(); var to = new HydroNode(); network.Nodes.Add(from); network.Nodes.Add(to); var channel = new Channel { Source = from, Target = to }; network.Branches.Add(channel); var crossSectionXYZ = new CrossSectionDefinitionXYZ { Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) }) }; crossSectionXYZ.Sections.Add(new CrossSectionSection { SectionType = crossSectionSectionType }); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0); return(network); }
public void CopyFrom() { var source = new CrossSectionDefinitionXYZ { Geometry = new LineString(new ICoordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 0, -2), new Coordinate(4, 0, 0), }) }; const int deltaZStorage = 1; source.XYZDataTable[1].DeltaZStorage = deltaZStorage; var target = new CrossSectionDefinitionXYZ(); //action! target.CopyFrom(source); //for now we just expect the same geometry Assert.AreEqual(source.Geometry, target.Geometry); Assert.AreEqual(deltaZStorage, target.XYZDataTable[1].DeltaZStorage); Assert.AreEqual(typeof(FastXYZDataTable), target.XYZDataTable.GetType()); }
public void EmptyProfiles() { var crossSection = new CrossSectionDefinitionXYZ(); crossSection.Geometry = new LineString(new ICoordinate[] {}); var profile = crossSection.Profile; var flowProfile = crossSection.FlowProfile; Assert.AreEqual(0, profile.Count()); Assert.AreEqual(0, flowProfile.Count()); }
public void AddToDataTableFails() { var crossSection = new CrossSectionDefinitionXYZ(); crossSection.Geometry = new LineString(new ICoordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 2, -2), new Coordinate(4, 2, -2), new Coordinate(6, 0, 0) }); crossSection.XYZDataTable.AddCrossSectionXYZRow(3, 0, 0); }
public void BranchCrossSectionShouldRaiseCollectionChangedEvent() { var crossSection = new CrossSectionDefinitionXYZ(); var branch = new Channel(new HydroNode("from"), new HydroNode("To")); int count = 0; Post.Cast <Channel, INotifyCollectionChange>(branch).CollectionChanged += delegate { count++; }; HydroNetworkHelper.AddCrossSectionDefinitionToBranch(branch, crossSection, 0.0); Assert.AreEqual(1, count); branch.BranchFeatures.Clear(); Assert.AreEqual(2, count); }
public void ChangingGeometryChangesTable() { var crossSection = new CrossSectionDefinitionXYZ(); crossSection.Geometry = new LineString(new ICoordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 2, -2), new Coordinate(4, 2, -2), new Coordinate(6, 0, 0) }); crossSection.Geometry.Coordinates[1].Z = -1; crossSection.Geometry = crossSection.Geometry; Assert.AreEqual(-1, crossSection.XYZDataTable[1].Z); }
public void CloneHydroNetworkWithCrossSectionSectionTypes() { var network = new HydroNetwork(); var crossSectionSectionType = new CrossSectionSectionType { Name = "Jan" }; network.CrossSectionSectionTypes.Add(crossSectionSectionType); crossSectionSectionType.Id = 666;//debug easy by idd var from = new HydroNode(); var to = new HydroNode(); network.Nodes.Add(from); network.Nodes.Add(to); var channel = new Channel { Source = from, Target = to }; network.Branches.Add(channel); var crossSectionXYZ = new CrossSectionDefinitionXYZ { Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) }) }; crossSectionXYZ.Sections.Add(new CrossSectionSection { SectionType = crossSectionSectionType }); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0); var clonedHydroNetwork = (IHydroNetwork)network.Clone(); clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1); var cloneCrossSection = clonedHydroNetwork.CrossSections.FirstOrDefault(); var clonedType = clonedHydroNetwork.CrossSectionSectionTypes.FirstOrDefault(t => t.Name == "Jan"); //the type should be cloned Assert.AreNotEqual(clonedType, crossSectionSectionType); //the crosssection reference should be updated to use the cloned type Assert.AreEqual(clonedType, cloneCrossSection.Definition.Sections[0].SectionType); }
public void ChangeInStorageDoesNotChangeProfile() { var crossSection = new CrossSectionDefinitionXYZ(); var coordinates = new[] { new Coordinate(0, 0), new Coordinate(2, 0), new Coordinate(4, -10), new Coordinate(6, -10), new Coordinate(8, 0), new Coordinate(10, 0) }; //make geometry on the y/z plane crossSection.Geometry = new LineString(coordinates.Select(c => new Coordinate(0, c.X, c.Y)).ToArray()); //since the profile is defined on the y/z plane we can ignore the x values Assert.AreEqual(coordinates, crossSection.Profile); }
public void Clone() { var crossSection = new CrossSectionDefinitionXYZ { Geometry = new LineString(new ICoordinate[] { new Coordinate(0, 0, 0), new Coordinate(2, 2, -2), new Coordinate(4, 2, -2), new Coordinate(6, 0, 0) }) }; crossSection.XYZDataTable[0].DeltaZStorage = 2; var clone = (CrossSectionDefinitionXYZ)crossSection.Clone(); Assert.AreEqual(crossSection.Geometry, clone.Geometry); Assert.AreEqual(typeof(FastXYZDataTable), clone.XYZDataTable.GetType()); Assert.AreEqual(2, clone.XYZDataTable[0].DeltaZStorage); }
public void AddDefaultZToGeometry() { var crossSection = new CrossSectionDefinitionXYZ(); // just a horizontal line from 10 to 40. Now just set z to 0 to make it work. // could be something more fancy. var coordinates = new List <ICoordinate> { new Coordinate(0, 0), new Coordinate(10, 0), new Coordinate(20, 0), new Coordinate(30, 0), new Coordinate(40, 0) }; crossSection.Geometry = new LineString(coordinates.ToArray()); CrossSectionHelper.AddDefaultZToGeometry(crossSection); Assert.AreEqual(10.0, crossSection.Geometry.Coordinates[0].Z); Assert.AreEqual(5.0, crossSection.Geometry.Coordinates[1].Z); Assert.AreEqual(0.0, crossSection.Geometry.Coordinates[2].Z); Assert.AreEqual(5.0, crossSection.Geometry.Coordinates[3].Z); Assert.AreEqual(10.0, crossSection.Geometry.Coordinates[4].Z); }
public void CloneHydroNetworkWithCrossSection() { var network = new HydroNetwork(); var from = new HydroNode(); var to = new HydroNode(); network.Nodes.Add(from); network.Nodes.Add(to); var channel = new Channel { Source = from, Target = to }; network.Branches.Add(channel); var crossSectionXYZ = new CrossSectionDefinitionXYZ { Geometry = new LineString(new[] { new Coordinate(0, 0), new Coordinate(10, 0) }) }; HydroNetworkHelper.AddCrossSectionDefinitionToBranch(channel, crossSectionXYZ, 0); var clonedHydroNetwork = (IHydroNetwork)network.Clone(); clonedHydroNetwork.CrossSections.Should().Have.Count.EqualTo(1); }
public void SetReferenceLevelGeometry() { var crossSection = new CrossSectionDefinitionXYZ(); var coordinates = new List <ICoordinate> { new Coordinate(0, 0, 0), new Coordinate(10, 0, 0), new Coordinate(30, 0, 0), new Coordinate(40, 0, 0) }; crossSection.Geometry = new LineString(coordinates.ToArray()); Assert.AreEqual(0.0, crossSection.LowestPoint, 1.0e-6); Assert.AreEqual(0.0, crossSection.HighestPoint, 1.0e-6); crossSection.ShiftLevel(111); Assert.AreEqual(111.0, crossSection.Geometry.Coordinates[0].Z, 1.0e-6); Assert.AreEqual(111.0, crossSection.Geometry.Coordinates[0].Z, 1.0e-6); Assert.AreEqual(111.0, crossSection.LowestPoint, 1.0e-6); Assert.AreEqual(111.0, crossSection.HighestPoint, 1.0e-6); }
public void SetDifferentGeometries() { var crossSection = new CrossSectionDefinitionXYZ(); var coordinates = new List <ICoordinate> { new Coordinate(0, 0, 0), new Coordinate(2, 2, -2), new Coordinate(4, 2, -2), new Coordinate(6, 0, 0) }; var geometry1 = new LineString(coordinates.ToArray()); coordinates.Insert(2, new Coordinate(3, 2, -2)); var geometry2 = new LineString(coordinates.Select(c => c.Clone() as ICoordinate).ToArray()); //full clone coordinates.RemoveAt(1); var geometry3 = new LineString(coordinates.Select(c => c.Clone() as ICoordinate).ToArray()); coordinates = coordinates.Select(c => new Coordinate(c.X + 10, c.Y, c.Z)).OfType <ICoordinate>().ToList(); var geometry4 = new LineString(coordinates.Select(c => c.Clone() as ICoordinate).ToArray()); crossSection.Geometry = geometry1; int count = 4; //define some storage for (int i = 0; i < count; i++) { crossSection.XYZDataTable[i].DeltaZStorage = i; } geometry1[2].X = 5; //move a point for (int i = 0; i < count; i++) { Assert.AreEqual(crossSection.XYZDataTable[i].DeltaZStorage, i); //expect no changes } int j = 0; crossSection.Geometry = geometry2; //add a point for (int i = 0; i < count + 1; i++) { if (i != 2) { Assert.AreEqual(crossSection.XYZDataTable[i].DeltaZStorage, j); j++; } } crossSection.Geometry = geometry3; //remove a point double[] expected = { 0.0, 0.0, 2.0, 3.0 }; for (int i = 0; i < count; i++) { Assert.AreEqual(crossSection.XYZDataTable[i].DeltaZStorage, expected[i]); } crossSection.Geometry = geometry4; //move all points for (int i = 0; i < count; i++) { Assert.AreEqual(crossSection.XYZDataTable[i].DeltaZStorage, expected[i]); } }