public void AssertThat_RangeWithContinuousInclude_IsNotInterrupted() { var range = new FloorRangeSpec(new[] { new FloorRangeIncludeSpec("id", new NormallyDistributedValue(20, 20, 20, 10), false, true, new[] { new KeyValuePair <float, KeyValuePair <string, string>[]>(1, new [] { new KeyValuePair <string, string>("key", "continuous") }) }, new ConstantValue(1)), new FloorRangeIncludeSpec("id", new NormallyDistributedValue(20, 30, 40, 10), false, false, new[] { new KeyValuePair <float, KeyValuePair <string, string>[]>(1, new [] { new KeyValuePair <string, string>("key", "interrupt") }) }, new ConstantValue(1)) }); var r = new Random(); var d = new NamedBoxCollection(); var selected = range.Select(r.NextDouble, d, (a, b) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", a))).ToArray(); //Flatten runs into floors var floors = selected.SelectMany(a => a.Selection); //Find the first continuous floor, then check that the next 20 floors are all "continuous" Assert.IsTrue(floors.SkipWhile(a => a.Script.Name != "continuous").Take(20).All(a => a.Script.Name == "continuous")); }
public void TestMethod1() { var b = BuildingDesigner.Deserialize(new StringReader(@" !Building Aliases: - &residential_floor_count !NormalValue Min: 5 Max: 10 - &FloorHeight !UniformValue Min: 2 Max: 5 Vary: true Facades: # Penthouse facade - Tags: { 1: { tag: BlankFacade } } Bottom: !Id { Id: Penthouse } Top: !Id { Id: Penthouse, Inclusive: true } # Skylobby facades - Tags: { 1: { tag: BlankFacade } } Bottom: !Id { Id: Skylobby } Top: !Id { Id: Skylobby, Inclusive: true, Search: Up, Filter: First } # Residential facades - Tags: { 1: { tag: BlankFacade } } Bottom: !Id { Id: Residential } Top: !Id { Id: Residential, Inclusive: true, Search: Up, Filter: Longest, NonOverlapping: true } # Ground entrances - Tags: { 1: { tag: BlankFacade } } Bottom: !Num { N: 0 } Top: !Num { N: 0, Inclusive: true } #Constraints: [ !Access { Type: Road } ] - Tags: { 1: { tag: BlankFacade } } Bottom: !Num { N: 0 } Top: !Num { N: 0 } Verticals: # First lift from ground->lowest skylobby - Tags: { 1: { tag: HollowVertical } } Bottom: !Num { N: 0 } Top: !Num { N: 5 } Floors: - !Floor Id: Penthouse Tags: { 50: { tag: SolidFloor }, 50: null } - !Footprint - !Shrink { Distance: 5 } - !Twist { Angle: 15 } - !Clip {} - !Repeat Count: !NormalValue Min: 1 Max: 5 Items: - !Footprint - !Shrink { Distance: 5 } - !Twist { Angle: 15 } - !Clip {} - !Floor Id: Skylobby Tags: { 1: { tag: SolidFloor } } - !Repeat Count: *residential_floor_count Vary: true Items: - !Floor Tags: { 1: { tag: SolidFloor } } Id: Residential - !Footprint - !Shrink { Distance: 1 } - !Twist { Angle: 15 } - !Clip {} - !Floor Tags: { 1: { tag: SolidFloor } } Height: *FloorHeight - !Ground [] ")); Assert.IsNotNull(b); Func <IEnumerable <KeyValuePair <string, string> >, Type[], ScriptReference> finder = (tags, types) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", tags)); var lot = new Vector2[] { new Vector2(-30, -30), new Vector2(-30, 30f), new Vector2(30, 30f), new Vector2(30, -30f) }; Random r = new Random(10); var d = new NamedBoxCollection(); var selection = b.Internals(r.NextDouble, d, finder).Externals(r.NextDouble, d, finder, new BuildingSideInfo[] { new BuildingSideInfo(lot[0], lot[1], new BuildingSideInfo.NeighbourInfo[0]), new BuildingSideInfo(lot[1], lot[2], new BuildingSideInfo.NeighbourInfo[0]), new BuildingSideInfo(lot[2], lot[3], new BuildingSideInfo.NeighbourInfo[0]), new BuildingSideInfo(lot[3], lot[0], new BuildingSideInfo.NeighbourInfo[0]), }); Assert.AreEqual(selection.Floors.Count(), selection.Floors.GroupBy(a => a.Index).Count()); var v = selection.Verticals; Func <int, string> prefix = (floor) => new string(v.Select(a => a.Bottom <= floor && a.Top >= floor ? '|' : ' ').ToArray()); foreach (var item in selection.Floors.OrderByDescending(a => a.Index)) { var pre = prefix(item.Index); Console.WriteLine("{0} {1} {2:##.##}m", pre, item.Script.Name, item.Height); } }
public void AssertThat_RangeWithSingleInclude_OutputsNothing_WhenIncludeIsNull() { var range = new FloorRangeSpec(new[] { new FloorRangeIncludeSpec("id", new NormallyDistributedValue(2, 3, 4, 1), false, true, new[] { new KeyValuePair <float, KeyValuePair <string, string>[]>(1, null) }, new ConstantValue(1)) }); var selected = range.Select(() => 0.5, new NamedBoxCollection(), (a, b) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", a))); //Flatten runs into floors var floors = selected.SelectMany(a => a.Selection); Assert.AreEqual(0, floors.Count()); }
public void AssertThat_RangeWithSingleInclude_RepeatsSingleItemInIncludeCorrectNumberOfTimes() { var range = new FloorRangeSpec(new[] { new FloorRangeIncludeSpec("id", new NormallyDistributedValue(2, 3, 4, 1), false, true, new[] { new KeyValuePair <float, KeyValuePair <string, string>[]>(1, new [] { new KeyValuePair <string, string>("tag", "tag") }) }, new ConstantValue(1)) }); var selected = range.Select(() => 0.5, new NamedBoxCollection(), (a, b) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", a))); //Flatten runs into floors var floors = selected.SelectMany(a => a.Selection); Assert.IsTrue(2 <= floors.Count() && floors.Count() <= 3); }
public void AssertThat_BlockSpec_SelectsTightestConstraintsForParcel() { Parcel p = new Parcel(new Parcel.Edge[] { new Parcel.Edge { Start = new Vector2(0, 0), End = new Vector2(100, 0), Resources = new [] { "road" } }, new Parcel.Edge { Start = new Vector2(100, 0), End = new Vector2(100, -100), Resources = new [] { "road" } }, new Parcel.Edge { Start = new Vector2(100, -100), End = new Vector2(0, -100), Resources = new [] { "road" } }, new Parcel.Edge { Start = new Vector2(0, -100), End = new Vector2(0, 0), Resources = new [] { "road" } }, }); var selected = _spec.SelectLot(p, () => 1, new NamedBoxCollection(), (a, b) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", a))); Assert.AreEqual("[a, c]", selected.Name); }
public void TestMethod1() { var rnd = new Random(3); var random = (Func <double>)rnd.NextDouble; var metadata = new NamedBoxCollection(); var designer = FloorDesigner.Deserialize(new StringReader(@" # root node !Floorplan # tags for this floorplan Tags: Type: Residential Style: None # Aliases block is just a list of items, not used by the system. Handy place to define objects which will be used later in the markup Aliases: # A single room, with a set of constraints - &office !Room Id: Office Walkthrough: false Tags: 1: { Office } # Constraints: [] # - { Strength: 1, Req: !ExteriorWindow { } } # - { Strength: 0.5, Req: !ExteriorDoor { Deny: true } } # - { Strength: 0.5, Req: !Area { Min: 11 } } # A group of rooms - &office_group !Group Id: Offices Children: - *office - *office GrowthParameters: SeedSpacing: !NormalValue { Min: 2.5, Mean: 5, Max: 6.5, Vary: true } SeedChance: 0.75 IntersectionContinuationChance: 0.3 ParallelCheck: Length: 1 Width: 3.5 Angle: 15 MergeParameters: AngularDeviation: Weight: 0.4 Threshold: 0.5 Convexity: Weight: 0.3 Threshold: 0.5 Area: Weight: 0.3 Threshold: 45 Cutoff: 5 CorridorParameters: Width: 1 Spaces: - !Repeat Count: !NormalValue { Min: 1, Max: 100 } Space: *office_group ")); Func <IEnumerable <KeyValuePair <string, string> >, Type[], ScriptReference> finder = (tags, types) => { var tagsClean = from tag in tags let k = string.IsNullOrEmpty(tag.Key) let v = string.IsNullOrEmpty(tag.Value) where !k || !v select(!k && !v) ? (tag.Key + ":" + tag.Value) : (k ? tag.Value : tag.Key); return(ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", tagsClean))); }; ////Corner shape //var shape = new[] { // new Vector2(9, 5), new Vector2(9, -6), new Vector2(0, -6), new Vector2(0, 0), new Vector2(-4, 0), new Vector2(-4, 5) //}; //var sections = new[] { // new Subsection[] { new Subsection(0, 1, Subsection.Types.Window) }, // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[] { new Subsection(0, 1, Subsection.Types.Window) }, // new Subsection[0] //}; //Diagonal bend shape var shape = new[] { new Vector2(10, 10), new Vector2(20, 0), new Vector2(23, 0), new Vector2(33, 10), new Vector2(43, 0), new Vector2(28, -15), new Vector2(15, -15), new Vector2(0, 0) }; var sections = new[] { new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0], new Subsection[0] }; var verticals = new Vector2[][] { }; ////Actual office floorplan //var shape = new[] { // new Vector2(-25, 17), // new Vector2(0, 17), // new Vector2(3, 15), // new Vector2(33, 15), // new Vector2(38, 0), // new Vector2(-25, -25) //}; //var sections = new[] { // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0] //}; //var verticals = new[] { // new[] { // new Vector2(0, 0), // new Vector2(7, 0), // new Vector2(7, -7), // new Vector2(0, -7), // } //}; ////rectangle //var shape = new[] { // new Vector2(9, 0), // new Vector2(9, -6), // new Vector2(0, -6), // new Vector2(0, 0) //}; //var sections = new[] { // new Subsection[0], // new Subsection[0], // new Subsection[0], // new Subsection[0], //}; var plan = new GeometricFloorplan(shape); designer.Design(random, metadata, finder, plan, sections, 0.175f, verticals, new List <ConstrainedVerticalSelection>()); Console.WriteLine(SvgRoomVisualiser.FloorplanToSvg(plan, 55, basic: false)); }
public void AssertThat_FloorSpec_SelectsNothing_FromNull() { FloorSpec spec = new FloorSpec(new[] { new KeyValuePair <float, KeyValuePair <string, string>[]>(1, null) }, new NormallyDistributedValue(1, 2, 3, 1).Transform(vary: false)); var selected = spec.Select(() => 0.5, new NamedBoxCollection(), (a, b) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", a))); var floors = selected.SelectMany(a => a.Selection); Assert.AreEqual(0, floors.Count()); }
public void AssertThat_FloorSpec_SelectsSingleItem_FromSingleChoice() { FloorSpec spec = new FloorSpec(new[] { new KeyValuePair <float, KeyValuePair <string, string>[]>(1, new [] { new KeyValuePair <string, string>("key", "tag") }) }, new NormallyDistributedValue(1, 2, 3, 1).Transform(vary: false)); var selected = spec.Select(() => 0.5, new NamedBoxCollection(), (a, b) => ScriptReferenceFactory.Create(typeof(TestScript), Guid.NewGuid(), string.Join(",", a.Select(t => t.Value)))); Assert.AreEqual(1, selected.Count()); Assert.AreEqual("tag", selected.Single().Selection.Single().Script.Name); }