public MainLayer() : base(CCColor4B.AliceBlue) { _canvasNode = new CCDrawNode(); _recognizerCanvasNode = new CCDrawNode(); _lineRecognizer = new LineRecognizer(); _shapeNode = new CCDrawNode(); AddChild(_shapeNode); AddChild(_canvasNode); AddChild(_recognizerCanvasNode); if (_drawDebug) { _lineRecognizer.LineFound = (line) => _recognizerCanvasNode.DrawLine(line.P1.ToCCPoint(), line.P2.ToCCPoint(), 5, CCColor4B.Blue); } // Register patterns (concept) _patternEvaluator = new PatternEvaluator(); _patternEvaluator.Add("button").When(Pattern.WideRectangle); _patternEvaluator.Add("image").When(Pattern.Cross); _patternEvaluator.Add("text").When(p => p.Repetitive(ip => ip.MovesRight().MovesLeftAndDown()).MovesRight()); _patternEvaluator.Add("entry").When(p => p.MovesDown().MovesRight().MovesUp().Bounds(BoundsDescriptor.IsWide)); _patternEvaluator.Add("lineoftext").When(p => p.MovesRight()); _patternEvaluator.Add("delete").When(p => p.MovesRightAndUp()); }
public void WideRectanglePatternFailTest2() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("button").When(Pattern.WideRectangle); var result = evaluator.Evaluate(PathsForTesting.TallRectangle); // Assert Assert.False(result.IsValid); }
public override void Execute(List <Allotment> allotments) { _buildings = new List <Building> (); foreach (Allotment allotment in allotments) { ArchitectureStyle architectureStyle = allotment.architectureStyle; int heightInTiles = UnityEngine.Random.Range(architectureStyle.minHeight, architectureStyle.maxHeight + 1); int height = heightInTiles * architectureStyle.tileHeight; int widthInTiles = allotment.widthInTiles - architectureStyle.spacing; int width = widthInTiles * architectureStyle.tileWidth; int depthInTiles = allotment.depthInTiles - architectureStyle.spacing; int depth = depthInTiles * architectureStyle.tileWidth; Facade[] facades = new Facade[allotment.freeFaces.Length]; int i = 0; foreach (Direction freeFace in allotment.freeFaces) { int longitude; int longitudeInTiles; if (freeFace == Direction.BACK || freeFace == Direction.FRONT) { longitude = width; longitudeInTiles = widthInTiles; } else { longitude = depth; longitudeInTiles = depthInTiles; } Pattern <FacadeItem> elementsPattern = architectureStyle.randomElementsPattern.Stretch(longitudeInTiles, heightInTiles); Pattern <FacadeItem> detailsPattern = architectureStyle.randomDetailsPattern.Stretch(longitudeInTiles, heightInTiles); Pattern <FacadeOperation> operationsPattern; if (architectureStyle.usesOperations) { operationsPattern = architectureStyle.randomOperationsPattern.Stretch(longitudeInTiles, heightInTiles); } else { operationsPattern = null; } PatternEvaluator.Evaluate(elementsPattern, detailsPattern, operationsPattern, architectureStyle); facades [i++] = new Facade(freeFace, longitude, height, longitudeInTiles, heightInTiles, architectureStyle, elementsPattern, detailsPattern, operationsPattern); } _buildings.Add(new Building(allotment.x, allotment.y, width, height, depth, widthInTiles, heightInTiles, depthInTiles, facades, architectureStyle)); } }
public void WideRectanglePatternTest() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("button").When(Pattern.WideRectangle); var result = evaluator.Evaluate(PathsForTesting.WideRectangle1); // Assert Assert.True(result.IsValid); Assert.Equal("button", result.Key); }
public void EntryTest() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("10,300 -> 10,260 -> 600,260 -> 600,300"); // Act evaluator.Add("entry").When(p => p.MovesDown().MovesRight().MovesUp().Bounds(BoundsDescriptor.IsWide)); var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); }
public void CrossPathTest() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("10,300 -> 100,200 | 100,300 -> 10,200"); // Act evaluator.Add("test").When(Pattern.Cross); var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); }
public void JigSawPatternTest() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("test").When(p => p.Repetitive(ip => ip.MovesRight().MovesLeftAndDown()).MovesRight()); var result = evaluator.Evaluate(PathsForTesting.JigSawPath); // Assert Assert.True(result.IsValid); Assert.Equal("test", result.Key); }
public void InverseHorizontalTest() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("image").When(p => p.MovesRightAndDown().MovesLeftAndDown()).AllowInverse(InverseDescriptor.Horizontal); var result = evaluator.Evaluate(PathsForTesting.InverseImage); // Assert Assert.True(result.IsValid); Assert.Same("image", result.Key); }
public void Step_NotEndsNearStart_Test() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("200,200 -> 50,200 -> 197, 290"); // Act evaluator.Add("p").When(e => e.MovesLeft().MovesRight().End(RelativePosition.NearStart)); var result = evaluator.Evaluate(path); // Assert Assert.False(result.IsValid); }
public void Step_MovesLeftAndDownStep_Test() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("300,300 -> 200,200"); // Act evaluator.Add("p").When(e => e.MovesLeftAndDown()); var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); Assert.Equal("p", result.Key); }
public void ImagePatternFailTest() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("image").When(Pattern.WideRectangle) .When(p => p.MovesRightAndDown()) .When(p => p.MovesLeftAndDown()); var results = evaluator.Evaluate(PathsForTesting.WideRectangle1); // Assert Assert.False(results.IsValid); }
public void LineDownTest() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("10,300 -> 10,200"); // Act evaluator.Add("linedown").When(e => e.MovesDown()); var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); Assert.Equal("linedown", result.Key); }
public void BrokenLineTest() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("10,300 -> 20,320 -> 100,310"); // Act evaluator.Add("line").When(e => e.MovesRight()); var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); Assert.Equal("line", result.Key); }
public void ShadyRectangleTest2() { // Arrange var evaluator = new PatternEvaluator(); var path = Path.Parse("Line 253, 1086 -> 779, 1133\nLine 781, 1133 -> 813, 838\nLine 813, 833 -> 285, 774\nLine 280, 874 -> 277, 1107"); evaluator.Add("rect").When(Pattern.WideRectangle); // Act var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); }
public void ImagePatternTest() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("image").When(p => p.MovesRightAndDown()) .When(p => p.MovesLeftAndDown()); var result = evaluator.Evaluate(PathsForTesting.Image); // Assert Assert.True(result.IsValid); Assert.Same("image", result.Key); }
public void ImagePatternWithMultipleRegisteredTest() { // Arrange var evaluator = new PatternEvaluator(); // Act evaluator.Add("button").When(Pattern.WideRectangle); evaluator.Add("image") .When(p => p.MovesRightAndDown()) .When(p => p.MovesLeftAndDown()); var result = evaluator.Evaluate(PathsForTesting.Image); // Assert Assert.True(result.IsValid); Assert.Same("image", result.Key); }
public void ShadyRectangleTest1() { // Arrange var json = "[{ \"X\":267.042267,\"Y\":921.1268} ,{ \"X\":322.8169,\"Y\":921.1268} ,{ \"X\":365.0704,\"Y\":921.1268} ,{ \"X\":417.4648,\"Y\":921.1268} ,{ \"X\":456.338,\"Y\":921.1268} ,{ \"X\":485.0704,\"Y\":921.1268} ,{ \"X\":498.591553,\"Y\":921.1268} ,{ \"X\":508.7324,\"Y\":921.1268} ,{ \"X\":520.563354,\"Y\":921.1268} ,{ \"X\":523.943665,\"Y\":921.1268} ,{ \"X\":527.324,\"Y\":921.1268} ,{ \"X\":527.324,\"Y\":917.74646} ,{ \"X\":527.324,\"Y\":907.605652} ,{ \"X\":527.324,\"Y\":890.7042} ,{ \"X\":530.7042,\"Y\":868.7324} ,{ \"X\":534.084534,\"Y\":843.3803} ,{ \"X\":537.4648,\"Y\":816.338} ,{ \"X\":537.4648,\"Y\":797.74646} ,{ \"X\":537.4648,\"Y\":774.0845} ,{ \"X\":537.4648,\"Y\":758.8732} ,{ \"X\":537.4648,\"Y\":748.7324} ,{ \"X\":537.4648,\"Y\":745.3521} ,{ \"X\":537.4648,\"Y\":741.971863} ,{ \"X\":537.4648,\"Y\":736.9014} ,{ \"X\":534.084534,\"Y\":736.9014} ,{ \"X\":508.7324,\"Y\":736.9014} ,{ \"X\":488.4507,\"Y\":736.9014} ,{ \"X\":427.605652,\"Y\":736.9014} ,{ \"X\":378.591553,\"Y\":736.9014} ,{ \"X\":329.577454,\"Y\":736.9014} ,{ \"X\":287.323944,\"Y\":736.9014} ,{ \"X\":258.591553,\"Y\":736.9014} ,{ \"X\":241.690155,\"Y\":736.9014} ,{ \"X\":234.929581,\"Y\":736.9014} ,{ \"X\":224.788742,\"Y\":736.9014} ,{ \"X\":221.408447,\"Y\":736.9014} ,{ \"X\":218.028168,\"Y\":736.9014} ,{ \"X\":214.647873,\"Y\":736.9014} ,{ \"X\":212.957748,\"Y\":747.0423} ,{ \"X\":209.577454,\"Y\":767.324} ,{ \"X\":206.197189,\"Y\":799.436646} ,{ \"X\":206.197189,\"Y\":848.450745} ,{ \"X\":206.197189,\"Y\":880.563354} ,{ \"X\":206.197189,\"Y\":905.9155} ,{ \"X\":206.197189,\"Y\":922.8169} ,{ \"X\":206.197189,\"Y\":932.9577} ,{ \"X\":206.197189,\"Y\":939.7183} ,{ \"X\":206.197189,\"Y\":944.788757} ,{ \"X\":206.197189,\"Y\":949.859131} ,{ \"X\":209.577454,\"Y\":949.859131} ]"; var points = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Point> >(json); var lineRec = new LineRecognizer(); lineRec.RegisterPoints(points); var path = lineRec.End(); var evaluator = new PatternEvaluator(); evaluator.Add("rect").When(Pattern.WideRectangle); // Act var result = evaluator.Evaluate(path); // Assert Assert.True(result.IsValid); }
public void AllowAnyOrderTest() { // Arrange var evaluator = new PatternEvaluator(); var path1 = Path.Parse("300,300 -> 400,200 -> 200,200 -> 300,300"); // the same triangle, just drawn in different order var path2 = Path.Parse("400,200 -> 200,200 -> 300,300 -> 400,200"); // Act evaluator.Add("allowanyorder-triangle").When( p => p.MovesRightAndDown() .MovesLeft() .MovesRightAndUp() .End(RelativePosition.NearStart)).AllowAnyOrder(); var result1 = evaluator.Evaluate(path1); var result2 = evaluator.Evaluate(path2); // Assert Assert.True(result1.IsValid); Assert.True(result2.IsValid); }
void Start() { UnityEngine.Random.seed = _seed; int widthInTiles = UnityEngine.Random.Range(_architectureStyle.minWidth, _architectureStyle.maxWidth); int heightInTiles = UnityEngine.Random.Range(_architectureStyle.minHeight, _architectureStyle.maxHeight); int depthInTiles = UnityEngine.Random.Range(_architectureStyle.minDepth, _architectureStyle.maxDepth); int tileWidth = _architectureStyle.tileWidth; int tileHeight = _architectureStyle.tileHeight; int width = widthInTiles * tileWidth; int height = heightInTiles * tileHeight; int depth = depthInTiles * tileWidth; Pattern <FacadeItem> elementsPattern = _architectureStyle.randomElementsPattern.Stretch(widthInTiles, heightInTiles); Pattern <FacadeItem> detailsPattern = _architectureStyle.randomDetailsPattern.Stretch(widthInTiles, heightInTiles); Pattern <FacadeOperation> operationsPattern; if (_architectureStyle.usesOperations) { operationsPattern = _architectureStyle.randomOperationsPattern.Stretch(widthInTiles, heightInTiles); } else { operationsPattern = null; } PatternEvaluator.Evaluate(elementsPattern, detailsPattern, operationsPattern, _architectureStyle); List <Facade> facades = new List <Facade> (); Facade facade = new Facade(Direction.FRONT, width, height, widthInTiles, heightInTiles, _architectureStyle, elementsPattern, detailsPattern, operationsPattern); facades.Add(facade); facade = new Facade(Direction.BACK, width, height, widthInTiles, heightInTiles, _architectureStyle, elementsPattern, detailsPattern, operationsPattern); facades.Add(facade); elementsPattern = _architectureStyle.randomElementsPattern.Stretch(depthInTiles, heightInTiles); detailsPattern = _architectureStyle.randomDetailsPattern.Stretch(depthInTiles, heightInTiles); if (_architectureStyle.usesOperations) { operationsPattern = _architectureStyle.randomOperationsPattern.Stretch(depthInTiles, heightInTiles); } else { operationsPattern = null; } PatternEvaluator.Evaluate(elementsPattern, detailsPattern, operationsPattern, _architectureStyle); facade = new Facade(Direction.LEFT, depth, height, depthInTiles, heightInTiles, _architectureStyle, elementsPattern, detailsPattern, operationsPattern); facades.Add(facade); facade = new Facade(Direction.RIGHT, depth, height, depthInTiles, heightInTiles, _architectureStyle, elementsPattern, detailsPattern, operationsPattern); facades.Add(facade); Building building = new Building(0, 0, width, height, depth, widthInTiles, heightInTiles, depthInTiles, facades.ToArray(), _architectureStyle); List <Building> buildings = new List <Building> (); buildings.Add(building); _buildingsMeshGenerator.Execute(buildings); float distance = height / (2.0f * _camera.near * Mathf.Tan(Mathf.Deg2Rad * _camera.fov / 2.0f)); _camera.transform.position = new Vector3(width / 2.0f, height / 2.0f, -distance); }
static void Main(string[] args) { //TestSwitchCaseCondition("@Test", 1); TestSwitchCaseCondition("% 10 = 2 or (1 and < 1)", 1); TestSwitchCaseCondition("% 10 = 2 or (1 and < 1)", 12); TestSwitchCaseCondition("% 10 = 2 or 5, 6, 7, 8, 9", 7); TestSwitchCaseCondition("% 10 = 2 or 5, 6, 7, 8, 9", 15); TestSwitchCaseCondition(" +1 % 10 = 1", 10); TestSwitchCaseCondition(" + 1 % 10 = 1", 10); TestSwitchCaseCondition("%10=1", 1); TestSwitchCaseCondition("%10=1", 10); TestSwitchCaseCondition("%10=1", 25); TestSwitchCaseCondition("%10=1", 11); var dialect = new DefaultDialect(); var manager = new DummyManager(); var test = "Hej {P1: Format spec} <F1: {Moo:tahr}> {Abe:kat} #Fisso{1: Foo 10 #Nested{Boo:Hawrh!} | 10} #Moo{{ab}} #Foo{|?Gok}"; var p = new DefaultExpressionParser(); var e = p.Parse(test, null); e.Accept(new Printer()); var eval = new PatternEvaluator(e); Console.Out.WriteLine(); Console.Out.WriteLine(e.ToString()); Console.Out.WriteLine("Custom expression part"); var customTest = "Hej {Name}"; e = p.Parse(customTest, null); e.Parts.Add(new TestPart()); e.Accept(new PatternDecorator(manager, dialect)); eval = new PatternEvaluator(e); e.Accept(new Printer()); Console.Out.WriteLine(); Console.Out.WriteLine(eval.Evaluate( CreateContext(null, manager.CurrentLanguage, new Dictionary <string, object> { { "Name", "John" } }))); Console.Out.WriteLine(); Console.Out.WriteLine(e.ToString()); var ptest = @"The values are {Name} and <Bold: <Bold:{Test}> <Bold:{Test}>><Bold: {Number:N2} (roman: {Number:roman})>. #Number{1: Singularis: 1 ({#}) | Pluralis\: n ({#})}. Boolean Expression: #Number{2 or 5: Yes | No} ModuloTest: #Number{% 2 = 0: Yes | No} {Name} has {Name.Length:N2} characters Let's enumerate Enum test 1: #EnumTest1{0:{#}|, {#}|-1:"" and {#}""} Enum test 2: #EnumTest2{0:{#}|, {#}|-1:"" and {#}""}"; Console.Out.WriteLine(); var evaluator = dialect.GetEvaluator(ptest, manager); Console.Out.WriteLine(evaluator.Evaluate( CreateContext(null, manager.CurrentLanguage, new Dictionary <string, object> { { "Name", "John Doe" }, { "Number", 5 }, { "Bold", "<b>{#}</b>" }, { "EnumTest1", new string[] { "A", "B", "C", "D" } }, { "EnumTest2", new string[] { "A" } }, { "EnumTest3", new string[] { "A", "B" } }, { "Test", true } }))); var texts = new List <LocalizedText> { new LocalizedText { Key = "LookupCondition", Pattern = "% 10 <= 2", Language = "en-US", PatternDialect = "Text" }, new LocalizedText { Key = "Plural1", Pattern = "1", Language = "en-US", PatternDialect = "Text" }, new LocalizedText { Key = "Plural2", Pattern = "<20", Language = "en-US", PatternDialect = "Text" }, new LocalizedText { Key = "ShortPlural", Pattern = "The number is #Plural(Number){Not plural|Plural|More plural}", Language = "en-US" }, new LocalizedText { Key = "PluralFun", Pattern = "The number is #Number{@LookupCondition: Plural|Not plural}", Language = "en-US" }, new LocalizedText { Key = "Arithmetic", Pattern = "Test #Number{% 10 = 1: Module | + 1 * 2 > 10: Combined}", Language = "en-US" }, new LocalizedText { Key = "Text one", Pattern = "Test one", Language = "en-US" }, new LocalizedText { Key = "Text two", Pattern = "Hello {UserName}", Language = "en-US" }, new LocalizedText { Key = "Text two", Pattern = "Hej {UserName}", Language = "da-DK" }, new LocalizedText { Key = "Enum", Pattern = @"#0{0: {#Index:roman}: {#}|, {#Index:roman}\: {#}|-1: "" {1} {#Index:roman}\: {#}""}", Language = "en-US" }, new LocalizedText { Key = "Reffed", Pattern = "Test {0} String literal {1}", Language = "en-US" }, new LocalizedText { Key = "Ref test 1", Pattern = "Ref 1: {@Reffed} and Another namespace {@Another__Reffed}", Language = "en-US" }, new LocalizedText { Key = "Ref test 2", Pattern = @"Ref 2: {@Reffed(UserName, ""Moo"")}", Language = "en-US" }, //This one makes sense, and shows why pattern references are neat new LocalizedText { Key = "Ref test 3", Pattern = @"You have selected {@Enum(List, 'and')}", Language = "en-US" }, new LocalizedText { Key = "Ref test 3", Namespace = "Another", Pattern = "Test one {@Reffed} and {@__Reffed}", Language = "en-US" }, new LocalizedText { Key = "Reffed", Namespace = "Another", Pattern = "I'm another", Language = "en-US" }, new LocalizedText { Key = "FormattedSwitch", Pattern = "Two decimals #Count:N2{1: One - ({#}) | More - {#}}", Language = "en-US" }, }; var xml = new XmlTextSource(); xml.Put(texts.Select(x => new LocalizedTextState { Text = x, Status = LocalizedTextStatus.Unchanged }), TextMergeOptions.KeepUnused); xml.Document.Save("Texts.xml"); xml = new XmlTextSource(); xml.Document = XDocument.Load("Texts.xml"); manager.Texts.Sources.Add(new PrioritizedTextSource(xml)); Console.Out.WriteLine(manager.Get("LookupCondition")); Console.Out.WriteLine(manager.Get("PluralFun", new { Number = 1 })); Console.Out.WriteLine("Shorthand:"); Console.Out.WriteLine(manager.Get("ShortPlural", new { Number = 30 })); Console.Out.WriteLine(manager.Get("Text two", new { UserName = "******" })); Console.Out.WriteLine("Debug:"); Console.Out.WriteLine(manager.Get("Text two", new { UserName = "******" }, debug: true)); Console.Out.WriteLine(); Console.Out.WriteLine(manager.Get("FormattedSwitch", new { Count = 7 })); Console.Out.WriteLine(manager.Get("Ref test 1", new { UserName = "******" })); Console.Out.WriteLine(manager.Get("Ref test 2", new { UserName = "******" })); Console.Out.WriteLine(manager.Get("Ref test 3", new { List = new[] { "Item 1", "Item 2", "Item 7", "Item 17" } })); Console.Out.WriteLine(manager.Get("Ref test 3", new { UserName = "******" }, ns: "Another")); string a = "Key"; /* @L10n @da-DK Foo @en-US Bar */ string b = "Key 2"; // @L10n @da-DK Foo 2 string.Format("Key 3" /* @L10n @da-DK Foo 3 */); string g = "Key"; /* @L10n @da-DK */ string m = "Key" /* @L10n @en-US Goo */; //var extractor = new CStyleLanguageTextExtractor(); //extractor.SourceFiles = // new SourceFileList(@"C:\Users\niels.kuhnel\Stuff\Rebel\Rebel 5\I18n\i18n\Sandboxes\Localization\Sandbox.Localization.Tryout", // new[] { "cs" }, new[] { "obj" }).GetFiles(); //xml.Document = null; //xml.Put(extractor.Get().Select(x => new LocalizedTextState { Text = x }), TextMergeOptions.KeepUnused); //xml.Document.Save("Extracted.xml"); Console.Out.WriteLine("Arithmetic"); Console.Out.WriteLine(manager.Get("Arithmetic", new { Number = 11 })); Console.In.Read(); }