public void ChangeInDefinitionUpdatesGeometry() { //v-shaped cs 100 wide var crossSectionDefinitionYZ = new CrossSectionDefinitionYZ(""); crossSectionDefinitionYZ.YZDataTable.AddCrossSectionYZRow(0, 100, 0); crossSectionDefinitionYZ.YZDataTable.AddCrossSectionYZRow(50, 0, 0); crossSectionDefinitionYZ.YZDataTable.AddCrossSectionYZRow(100, 100, 0); crossSectionDefinitionYZ.Thalweg = 50; //horizontal line var network = HydroNetworkHelper.GetSnakeHydroNetwork(new Point(0, 0), new Point(100, 0)); var branch = network.Channels.First(); ICrossSection crossSection = HydroNetworkHelper.AddCrossSectionDefinitionToBranch(branch, crossSectionDefinitionYZ, 50); var expectedGeometry = new LineString(new[] { new Coordinate(50, 50), new Coordinate(50, -50) }); //use equals exact because rounding errors occur Assert.IsTrue(expectedGeometry.EqualsExact(crossSection.Geometry, 0.0001)); //action : change the profile crossSectionDefinitionYZ.YZDataTable[0].Yq = -20; expectedGeometry = new LineString(new[] { new Coordinate(50, 70), new Coordinate(50, -50) }); Assert.IsTrue(expectedGeometry.EqualsExact(crossSection.Geometry, 0.0001)); //action: change the thalweg crossSectionDefinitionYZ.Thalweg = 40; expectedGeometry = new LineString(new[] { new Coordinate(50, 60), new Coordinate(50, -60) }); Assert.IsTrue(expectedGeometry.EqualsExact(crossSection.Geometry, 0.0001)); }
public void GetGeometryWidthYZDefinitionShouldBeFast() { var yz = new CrossSectionDefinitionYZ(""); yz.YZDataTable.AddCrossSectionYZRow(10, 100, 0); yz.YZDataTable.AddCrossSectionYZRow(9, 90, 0); yz.YZDataTable.AddCrossSectionYZRow(8, 80, 0); yz.YZDataTable.AddCrossSectionYZRow(7, 60, 0); yz.YZDataTable.AddCrossSectionYZRow(6, 70, 0); yz.YZDataTable.AddCrossSectionYZRow(5, 40, 0); yz.YZDataTable.AddCrossSectionYZRow(4, 40, 0); yz.YZDataTable.AddCrossSectionYZRow(3, 20, 0); var network = HydroNetworkHelper.GetSnakeHydroNetwork(1); var branch = network.Channels.First(); var crossSection = HydroNetworkHelper.AddCrossSectionDefinitionToBranch(branch, yz, 30); TestHelper.AssertIsFasterThan(50, () => { for (int i = 0; i < 10000; i++) { var geo = crossSection.Geometry; } }); }
public void CloneHydroNetworkWithLinkSources() { var network = HydroNetworkHelper.GetSnakeHydroNetwork(1); var catchment = new Catchment(); network.Catchments.Add(catchment); var wasteWaterTreatmentPlant = new WasteWaterTreatmentPlant(); network.WasteWaterTreatmentPlants.Add(wasteWaterTreatmentPlant); var lateral = new LateralSource(); network.Branches.First().BranchFeatures.Add(lateral); catchment.OutgoingLinks.Add(wasteWaterTreatmentPlant); catchment.OutgoingLinks.Add(lateral); wasteWaterTreatmentPlant.IncomingLinks.Add(catchment); lateral.IncomingLinks.Add(catchment); var clone = (HydroNetwork)network.Clone(); var links = TestReferenceHelper.SearchObjectInObjectGraph(catchment, clone); links.ForEach(Console.WriteLine); Assert.AreEqual(0, links.Count); Assert.AreEqual(2, clone.Catchments.First().OutgoingLinks.Count); Assert.AreEqual(1, clone.WasteWaterTreatmentPlants.First().IncomingLinks.Count); Assert.AreEqual(1, clone.LateralSources.First().IncomingLinks.Count); }
public void CloneHydroNetworkWithData() { var network = HydroNetworkHelper.GetSnakeHydroNetwork(1); var publicProperties = ReflectionTestHelper.GetPublicListProperties(network); foreach (var prop in publicProperties) { try { var value = prop.GetValue(network, null); if (value is IList) { var genericType = TypeUtils.GetFirstGenericTypeParameter(value.GetType()); var concreteType = genericType.Assembly.GetTypes().Where( t => genericType.IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract).FirstOrDefault(); var instance = Activator.CreateInstance(concreteType); (value as IList).Add(instance); } } catch (Exception) { Console.WriteLine(String.Format("Unable to set property: {0}", prop)); } } var clone = (HydroNetwork)network.Clone(); TestReferenceHelper.AssertStringRepresentationOfGraphIsEqual(network, clone); }
public void LateralSourceCheckGeometry() { var hydroNetwork = HydroNetworkHelper.GetSnakeHydroNetwork(new Point(0, 0), new Point(200, 0), new Point(200, 200)); var branch1 = hydroNetwork.Branches[0]; var lateralSource = new LateralSource { Name = "Source1", Offset = 10, }; branch1.BranchFeatures.Add(lateralSource); lateralSource.Branch = branch1; lateralSource.IsDiffuse = true; //needed here; this is actually done via LateralSourceProperties HydroNetworkEditorHelper.UpdateBranchFeatureGeometry(lateralSource, 40); var geometry = lateralSource.Geometry; Assert.AreEqual(typeof(LineString), geometry.GetType()); Assert.AreEqual(40.0, geometry.Length); lateralSource.IsDiffuse = false; HydroNetworkEditorHelper.UpdateBranchFeatureGeometry(lateralSource, 0); Assert.AreEqual(typeof(Point), lateralSource.Geometry.GetType()); }
public void CloneHydroNetworkWithProxyDefinitions() { var network = HydroNetworkHelper.GetSnakeHydroNetwork(1); var sharedDefinition = new CrossSectionDefinitionYZ(); network.SharedCrossSectionDefinitions.Add(sharedDefinition); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(network.Channels.First(), new CrossSectionDefinitionProxy(sharedDefinition), 10.0d); var clone = (HydroNetwork)network.Clone(); TestReferenceHelper.AssertStringRepresentationOfGraphIsEqual(network, clone); }
public void MakeDefinitionSharedCopiesDefinitionToNetwork() { var crossSectionDefinitionYZ = CrossSectionDefinitionYZ.CreateDefault(); var hydroNetwork = HydroNetworkHelper.GetSnakeHydroNetwork(1); var crossSection = new CrossSection(crossSectionDefinitionYZ) { Branch = hydroNetwork.Channels.First() }; Assert.AreEqual(0, hydroNetwork.SharedCrossSectionDefinitions.Count); crossSection.ShareDefinitionAndChangeToProxy(); Assert.AreEqual(1, hydroNetwork.SharedCrossSectionDefinitions.Count); Assert.AreEqual(crossSectionDefinitionYZ, hydroNetwork.SharedCrossSectionDefinitions.First()); }
public void CloneRewiresProxyDefinitions() { var network = HydroNetworkHelper.GetSnakeHydroNetwork(1); var sharedDefinition = new CrossSectionDefinitionYZ(); network.SharedCrossSectionDefinitions.Add(sharedDefinition); var crossSectionDefinitionProxy = new CrossSectionDefinitionProxy(sharedDefinition); HydroNetworkHelper.AddCrossSectionDefinitionToBranch(network.Branches.First(), crossSectionDefinitionProxy, 10.0); var clonedNetwork = (HydroNetwork)network.Clone(); Assert.AreEqual(1, clonedNetwork.SharedCrossSectionDefinitions.Count); //check the proxy got rewired var crossSectionClone = clonedNetwork.CrossSections.First(); var clonedProxyDefinition = (CrossSectionDefinitionProxy)crossSectionClone.Definition; Assert.AreEqual(clonedProxyDefinition.InnerDefinition, clonedNetwork.SharedCrossSectionDefinitions.First()); }
public void MakeDefinitionLocalCreatesAShiftedCopyOfInnerDefinition() { var innerDefinition = CrossSectionDefinitionYZ.CreateDefault(); //create a shifted proxy const double levelShift = 1.0; var proxy = new CrossSectionDefinitionProxy(innerDefinition) { LevelShift = levelShift }; var hydroNetwork = HydroNetworkHelper.GetSnakeHydroNetwork(1); var crossSection = new CrossSection(proxy) { Branch = hydroNetwork.Channels.First() }; crossSection.MakeDefinitionLocal(); Assert.IsFalse(crossSection.Definition.IsProxy); Assert.IsTrue(crossSection.Definition is CrossSectionDefinitionYZ); Assert.AreEqual(crossSection.Definition.Profile, innerDefinition.Profile.Select(c => new Coordinate(c.X, c.Y + levelShift)).ToList()); }