/// <summary> /// Initializes the new map. /// </summary> /// <param name="mapping">The mapping.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <remarks> /// - Requires not null IPointToAreaMapping. /// - Requires that mapping has a number of dest points. /// - Requires that at least one dest point points to not empty source area. /// - Discards all the previous settings made by other methods. /// </remarks> public IArea2DMapBuilder InitNewMap(IAreasMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } var areas = mapping.AssociatedAreasAsc; var destArea = Area2D.Empty; var sourceArea = Area2D.Empty; foreach (var area in areas) { destArea = destArea.Join(area.Item1); sourceArea = sourceArea.Join(area.Item2); } _destArea = destArea; _sourceArea = sourceArea; _associatedAreas.Clear(); _associatedAreas.AddRange(areas); _isInitialized = true; return(this); }
/// <summary> /// Adds all the associated areas from the mapping. /// </summary> /// <param name="mapping">The mapping.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> /// <remarks> /// - Can not be executed before InitNewMap method. /// </remarks> public IArea2DMapBuilder AddMapping(IAreasMapping mapping) { if (!_isInitialized) { throw new MapIsNotInitializedException(); } if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } var areas = mapping.AssociatedAreasAsc; var destArea = _destArea; var sourceArea = _sourceArea; foreach (var area in areas) { destArea = destArea.Join(area.Item1); sourceArea = sourceArea.Join(area.Item2); } _destArea = destArea; _sourceArea = sourceArea; _associatedAreas.AddRange(areas); return(this); }
public void Should_Throw_ArgumentNullException_When_Mapping_Is_Null() { var mock = new Mock <IArea2DMapBuilder>(); var mapBuilder = mock.Object; var inpaintingMapBuilder = new InpaintMapBuilder(mapBuilder); IAreasMapping mapping = null; Should.Throw <ArgumentNullException>(() => inpaintingMapBuilder.InitNewMap(mapping)); }
public void Should_Throw_ArgumentNullException_When_Mapping_Is_Null() { var mocks = new MockRepository(); var mapBuilder = mocks.Stub <IArea2DMapBuilder>(); var inpaintingMapBuilder = new InpaintMapBuilder(mapBuilder); IAreasMapping mapping = null; Assert.Throws <ArgumentNullException>(() => inpaintingMapBuilder.InitNewMap(mapping)); }
/// <summary> /// Initializes the new map. /// </summary> /// <param name="mapping">The mapping.</param> /// <remarks> /// - Requires not null IPointToAreaMapping. /// - Requires that mapping has a number of dest points. /// - Requires that at least one dest point points to not empty source area. /// - Discards all the previous settings made by other methods. /// </remarks> public InpaintMapBuilder InitNewMap(IAreasMapping mapping) { if (mapping == null) { throw new ArgumentNullException(nameof(mapping)); } _sourceArea = mapping.AssociatedAreasAsc.Aggregate(Area2D.Empty, (current, area) => current.Join(area.Item2)); _mapBuilder.InitNewMap(mapping); _isInitialized = true; _donors.Clear(); _inpaintArea = null; return(this); }
internal static MappedAreasInfo[] ExtractMappedAreasInfo(this IAreasMapping map, int destImageWidth, int srcImageWidth, bool forward = true) { var areaAssociations = map.AssociatedAreasAsc.Reverse().ToArray(); var mapping = new MappedAreasInfo[areaAssociations.Length]; for (int i = 0; i < areaAssociations.Length; i++) { var areaAssociation = areaAssociations[i]; var ass = new MappedAreasInfo { DestAreaPointsIndexes = new int[areaAssociation.Item1.ElementsCount], SrcAreaPointsIndexes = new int[areaAssociation.Item2.ElementsCount], SrcBound = areaAssociation.Item2.Bound }; areaAssociation.Item1.FillMappedPointsIndexes(ass.DestAreaPointsIndexes, destImageWidth, forward); areaAssociation.Item2.FillMappedPointsIndexes(ass.SrcAreaPointsIndexes, srcImageWidth, forward); mapping[i] = ass; } return(mapping); }
public void Should_Throw_ArgumentNullException_When_Mapping_Is_Null() { IAreasMapping mapping = null; Should.Throw <ArgumentNullException>(() => _mapBuilder.InitNewMap(mapping)); }