public Value() { var value = new Choice( new String(), new Number(), new Text("true"), new Text("false"), new Text("null") ); var whitespace = new Many(new Any(" \r\n\t")); var separator = new Sequence(whitespace, new Character(','), whitespace); var element = new Sequence(whitespace, value, whitespace); var array = new Sequence(whitespace, new Character('['), new List(element, separator), new Character(']') ); var objectSeparator = new Sequence(whitespace, new Character(':'), whitespace); var objectString = new Sequence(whitespace, new String(), whitespace); var members = new Sequence(objectString, objectSeparator, element); var jsonObject = new Sequence(whitespace, new Character('{'), new List(members, separator), new Character('}') ); value.Add(array); value.Add(jsonObject); pattern = value; }
public Value() { var value = new Choice( new StringValue(), new Number(), new Text("true"), new Text("false"), new Text("null")); var whitespace = new Optional(new OneOrMore(new Any(" \r\n\t"))); var leftSquareBracket = new Character('['); var rightSquareBracket = new Character(']'); var leftBracket = new Character('{'); var rightBracket = new Character('}'); var colon = new Character(':'); var separator = new Sequence(whitespace, new Character(','), whitespace); var element = new Sequence(whitespace, value, whitespace); var member = new Sequence(whitespace, new StringValue(), whitespace, colon, element); var array = new Sequence(leftSquareBracket, new List(element, separator), rightSquareBracket); var jsonObject = new Sequence(leftBracket, new List(member, separator), rightBracket); value.Add(array); value.Add(jsonObject); pattern = value; }
private Area Lights() { var list = new MenuList(renderer, Orientation.Vertical); list.ChildLayoutStyle = Area.AreaLayoutStyle.ExtendHorizontal; list.Add(new Slider(renderer, "Exposure", LightsUniforms.Exposure, 0, 0.0f, 10.0f, 0.0f, 10.0f)); float r = 0.02f; var bias_x = new Slider(renderer, "Bias x", LightsUniforms.Bias, 0, -r, r, -r, r); var bias_y = new Slider(renderer, "Bias y", LightsUniforms.Bias, 1, -r, r, -r, r); var bias_z = new Slider(renderer, "Bias z", LightsUniforms.Bias, 2, -r, r, -r, r); var bias_w = new Slider(renderer, "Bias w", LightsUniforms.Bias, 3, -r, r, -r, r); /*bias_x.IsLogarithmic = true; * bias_y.IsLogarithmic = true; * bias_z.IsLogarithmic = true; * bias_w.IsLogarithmic = true;*/ list.Add(bias_x); list.Add(bias_y); list.Add(bias_z); list.Add(bias_w); for (int i = 0; i < sceneManager.RenderGroup.Lights.Count; ++i) { list.Add( new Slider( renderer, "Radiance " + (i + 1).ToString(), LightsUniforms.Color, 4 * i + 3, 0.0f, 10.0f, 0.0f, 10.0f ) ); } list.Add(new Slider(renderer, "Ambient Red", LightsUniforms.AmbientLightColor, 0, 0.0f, 4.0f, 0.0f, 4.0f)); list.Add(new Slider(renderer, "Ambient Green", LightsUniforms.AmbientLightColor, 1, 0.0f, 4.0f, 0.0f, 4.0f)); list.Add(new Slider(renderer, "Ambient Blue", LightsUniforms.AmbientLightColor, 2, 0.0f, 4.0f, 0.0f, 4.0f)); if (Configuration.stereo) { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "Config"; choice.Style = Style.NullPadding; var ao = choice.Add(new ChoiceItem(renderer, "AO")); var basic = choice.Add(new ChoiceItem(renderer, "Basic")); choice.Action = LightConfigAction; if (CurrentLightConfig == "AO") { choice.Selected = ao; } if (CurrentLightConfig == "Basic") { choice.Selected = basic; } list.Add(choice); } var expand = new Button(renderer, "lights", SetActive); expand.Link = list; return(expand); }
public ConvertIfToNullCoalescingAction() { var leftPattern = PatternHelper.OptionalParentheses(new AnyNode(comparedNodeGroupName)); var rightPattern = PatternHelper.OptionalParentheses(new NullReferenceExpression()); var choicePattern = new Choice(); var equalityPattern = PatternHelper.CommutativeOperator(leftPattern, BinaryOperatorType.Equality, rightPattern); var inequalityPattern = PatternHelper.CommutativeOperator(leftPattern.Clone(), BinaryOperatorType.InEquality, rightPattern.Clone()); choicePattern.Add(equalityPattern); choicePattern.Add(inequalityPattern); var namedChoicePattern = new NamedNode(expressionGroupName, choicePattern); ActionPattern = PatternHelper.OptionalParentheses(namedChoicePattern); }
public Value() { Choice value = new Choice( new String(), new Number(), new Text("true"), new Text("false"), new Text("null") ); var element = Element(value); value.Add(Array(value)); value.Add(Object(element)); this.pattern = element; }
public void Add_Method_For_Number_Should_Return_Empty_String_For_True_For_8_Hex() { var hex = new Choice( new Range('a', 'f'), new Range('A', 'F')); hex.Add(new Number()); IMatch actual = hex.Match("12.123e+3"); Assert.Equal(string.Empty, actual.RemainingText()); }
public int LevenshteinDistance <T>(T[] strOld, T[] strNew, IEqualityComparer <T>?comparer = null, Func <Choice <T>, int>?weight = null, bool allowTransposition = false) { int M1 = strOld.Length + 1; int M2 = strNew.Length + 1; if (comparer == null) { comparer = EqualityComparer <T> .Default; } if (weight == null) { weight = c => 1; } var num = ResizeArray(M1, M2); num[0, 0] = 0; for (int i = 1; i < M1; i++) { num[i, 0] = num[i - 1, 0] + weight(Choice <T> .Remove(strOld[i - 1])); } for (int j = 1; j < M2; j++) { num[0, j] = num[0, j - 1] + weight(Choice <T> .Add(strNew[j - 1])); } for (int i = 1; i < M1; i++) { for (int j = 1; j < M2; j++) { if (comparer.Equals(strOld[i - 1], strNew[j - 1])) { num[i, j] = num[i - 1, j - 1]; } else { num[i, j] = Math.Min(Math.Min( num[i - 1, j] + weight(Choice <T> .Remove(strOld[i - 1])), num[i, j - 1] + weight(Choice <T> .Add(strNew[j - 1]))), num[i - 1, j - 1] + weight(Choice <T> .Substitute(strOld[i - 1], strNew[j - 1]))); if (allowTransposition && i > 1 && j > 1 && comparer.Equals(strOld[i - 1], strNew[j - 2]) && comparer.Equals(strOld[i - 2], strNew[j - 1])) { num[i, j] = Math.Min(num[i, j], num[i - 2, j - 2] + weight(Choice <T> .Transpose(strOld[i - 1], strOld[i - 2]))); } } } } return(num[M1 - 1, M2 - 1]); }
public Value() { // aici construiește patternul pentru // un JSON value // ai grijă să ți seama de `spații albe` var value = new Choice( new String(), new Number(), new Text("true"), new Text("false"), new Text("null")); var whitespace = new Many(new Any(" \r\n\t")); var separator = new Sequence(whitespace, new Character(','), whitespace); var arrElement = new Sequence(whitespace, value, whitespace); var array = new Sequence( new Character('['), new List(arrElement, separator), new Character(']')); value.Add(array); var element = new Sequence( whitespace, new String(), whitespace, new Character(':'), whitespace, value, whitespace); var objectValue = new Sequence( new Character('{'), new List(element, new Character(',')), new Character('}')); value.Add(objectValue); pattern = value; }
public void AddMethodTest() { var value = new Choice( new Text("true"), new Text("false"), new Text("null")); var obj = new Text("zero"); value.Add(obj); const string string1 = "zerotruefalsenull"; Assert.Equal("truefalsenull", value.Match(string1).RemainingText()); }
public void IsValidArrayValue() { var stringValue = new String(); var number = new Number(); var value = new Choice( stringValue, number ); value.Add(new Text("true")); var actual = value.Match("true"); Assert.True(actual.Success()); Assert.Equal("", actual.RemainingText()); }
private Area Materials() { if (materialManager == null) { return(null); } var list = new MenuList(renderer, Orientation.Vertical); list.ChildLayoutStyle = Area.AreaLayoutStyle.ExtendHorizontal; var choice = new Choice(Orientation.Vertical); choice.Style = Style.NullPadding; choice.Action = MaterialChoiceAction; string[] materials = { "pearl", "gold", "red", "green", "cyan", "blue", "magenta", "noisy", "pink", "EdgeLines", "transparent", "Grid" }; foreach (var name in materials) { var item = new ChoiceItem(renderer, name); choice.Add(item); if (name == CurrentMaterial) { choice.Selected = item; } } roughness = new Slider(renderer, "Roughness", null, 0, 0.0f, 1.0f, 0.0f, 1.0f); roughness.IsLogarithmic = true; ChooseMaterial(); //var colorPicker = new ColorPicker(materialManager, renderer); //list.Add(colorPicker); list.Add(roughness); list.Add(choice); var expand = new Button(renderer, "Materials", SetActive); expand.Link = list; return(expand); }
private Area Scene() { var list = new MenuList(renderer, Orientation.Vertical); list.Name = "list"; list.ChildLayoutStyle = Area.AreaLayoutStyle.ExtendHorizontal; /*if(Configuration.curveTool)*/ { list.Add(new Slider(renderer, "Tension", curveTool.TCB, 0, -1.0f, 1.0f, -1.0f, 1.0f)); list.Add(new Slider(renderer, "Continuity", curveTool.TCB, 1, -1.0f, 1.0f, -1.0f, 1.0f)); list.Add(new Slider(renderer, "Bias", curveTool.TCB, 2, -1.0f, 1.0f, -1.0f, 1.0f)); } { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "Scene choice"; choice.Style = Style.NullPadding; choice.Action = SceneChoiceAction; string[] scenes = { "Simple", "Polyhedra", "Stereoscopic", "Noise", "Trees", "Game", "Curve" }; foreach (var label in scenes) { var choiceItem = choice.Add(new ChoiceItem(renderer, label)); if (label == CurrentScene) { choice.Selected = choiceItem; } } list.Add(choice); } var expand = new Button(renderer, "Scene", SetActive); expand.Link = list; return(expand); }
private Area Palette() { if (brushManager == null) { return(null); } var list = new MenuList(renderer, Orientation.Vertical); var palette = new Palette(brushManager, materialManager, renderer); palette.Name = "Brush palette"; list.Add(palette); CurrentPalette = brushManager.Dictionaries.First().Key; var choice = new Choice(Orientation.Vertical); choice.Style = Style.NullPadding; choice.Action = PaletteChoiceAction; foreach (var kvp in brushManager.Dictionaries) { var item = new ChoiceItem(renderer, kvp.Key); choice.Add(item); if (kvp.Key == "cupola") { choice.Selected = item; } } list.Add(choice); var expand = new Button(renderer, "Palette", SetActive); expand.Link = list; return(expand); }
public List <Choice <T> > LevenshteinChoices <T>(T[] strOld, T[] strNew, IEqualityComparer <T>?comparer = null, Func <Choice <T>, int>?weight = null) { if (comparer == null) { comparer = EqualityComparer <T> .Default; } if (weight == null) { weight = (c) => 1; } this.LevenshteinDistance <T>(strOld, strNew, comparer, weight); int i = strOld.Length; int j = strNew.Length; List <Choice <T> > result = new List <Choice <T> >(); while (i > 0 && j > 0) { if (comparer.Equals(strOld[i - 1], strNew[j - 1])) { result.Add(Choice <T> .Equal(strOld[i - 1])); i = i - 1; j = j - 1; } else { var cRemove = Choice <T> .Remove(strOld[i - 1]); var cAdd = Choice <T> .Add(strNew[j - 1]); var cSubstitute = Choice <T> .Substitute(strOld[i - 1], strNew[j - 1]); var num = _cachedNum !; var remove = num[i - 1, j] + weight(cRemove); var add = num[i, j - 1] + weight(cAdd); var substitute = num[i - 1, j - 1] + weight(cSubstitute); var min = Math.Min(remove, Math.Min(add, substitute)); if (substitute == min) { result.Add(cSubstitute); i = i - 1; j = j - 1; } else if (remove == min) { result.Add(cRemove); i = i - 1; } else if (add == min) { result.Add(cAdd); j = j - 1; } } } while (i > 0) { result.Add(Choice <T> .Remove(strOld[i - 1])); i = i - 1; } while (j > 0) { result.Add(Choice <T> .Add(strNew[j - 1])); j = j - 1; } result.Reverse(); return(result); }
private Area Camera() { var list = new MenuList(renderer, Orientation.Vertical); list.Name = "list"; list.ChildLayoutStyle = Area.AreaLayoutStyle.ExtendHorizontal; Camera camera = sceneManager.Camera; StereoParameters stereo = camera.Projection.StereoParameters; list.ChildLayoutStyle = Area.AreaLayoutStyle.ExtendHorizontal; stereo.ViewportCenter.Z = 4.0f; list.Add(new Slider(renderer, "Fov X", camera.Projection.FovXParameter, 0, 0.0f, (float)(System.Math.PI), 0.0f, 180.0f)); list.Add(new Slider(renderer, "Fov Y", camera.Projection.FovYParameter, 0, 0.0f, (float)(System.Math.PI), 0.0f, 180.0f)); if (Configuration.stereo) { list.Add(new Slider(renderer, "Eye Separation", stereo.EyeSeparation, 0, -1.0f, 1.0f, -1.0f, 1.0f)); list.Add(new Slider(renderer, "Perspective", stereo.Perspective, 0, 0.0f, 1.0f, 0.0f, 1.0f)); list.Add(new Slider(renderer, "Center X", stereo.ViewportCenter, 0, -4.0f, 4.0f, -4.0f, 4.0f)); list.Add(new Slider(renderer, "Center Y", stereo.ViewportCenter, 1, -4.0f, 4.0f, -4.0f, 4.0f)); list.Add(new Slider(renderer, "Center Z", stereo.ViewportCenter, 2, 0.0f, 20.0f, 0.0f, 20.0f)); list.Add(new Slider(renderer, "Eye X", stereo.EyePosition, 0, -4.0f, 4.0f, -4.0f, 4.0f)); list.Add(new Slider(renderer, "Eye Y", stereo.EyePosition, 1, -4.0f, 4.0f, -4.0f, 4.0f)); list.Add(new Slider(renderer, "Eye Z", stereo.EyePosition, 2, -20.0f, 20.0f, -20.0f, 20.0f)); //list.Add(new Slider(renderer, "Near", camera.NearParameter, 0, 0.0f, 10.0f, 0.0f, 10.0f)); //list.Add(new Slider(renderer, "Far", camera.FarParameter, 0, 0.0f, 100.0f, 0.0f, 100.0f)); } if (Configuration.stereo) { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "Focus choice"; choice.Style = Style.NullPadding; choice.Add(new ChoiceItem(renderer, "AutoFocus")); choice.Add(new ChoiceItem(renderer, "Manual")); choice.Action = FocusChoiceAction; choice.Selected = choice.Items.First(); list.Add(choice); } { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "FOV choice"; choice.Style = Style.NullPadding; var dict = new Dictionary <string, ProjectionType>(); dict["Vertical"] = ProjectionType.PerspectiveVertical; dict["Horizontal"] = ProjectionType.PerspectiveHorizontal; dict["V. Stereo"] = ProjectionType.StereoscopicVertical; dict["H. Stereo"] = ProjectionType.StereoscopicHorizontal; foreach (var kvp in dict) { var choiceItem = choice.Add(new ChoiceItem(renderer, kvp.Key)); if (kvp.Value == sceneManager.Camera.Projection.ProjectionType) { choice.Selected = choiceItem; } } choice.Action = ProjectionChoiceAction; list.Add(choice); } { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "StereoMode choice"; choice.Style = Style.NullPadding; foreach (var kvp in stereoModes) { ChoiceItem choiceItem = choice.Add(new ChoiceItem(renderer, kvp.Key)); if (kvp.Value == CurrentStereoMode) { choice.Selected = choiceItem; } } choice.Action = StereoModeChoiceAction; list.Add(choice); } #if false // \todo stereo material if (Configuration.stereo) { list.Add(new Slider(renderer, "Saturation", renderer.Global.Floats("saturation"), 0, 0.0f, 1.0f, 0.0f, 1.0f)); list.Add(new Slider(renderer, "Contrast", renderer.Global.Floats("contrast"), 0, 0.0f, 1.0f, 0.0f, 1.0f)); list.Add(new Slider(renderer, "Deghost", renderer.Global.Floats("deghost"), 0, 0.0f, 1.0f, 0.0f, 1.0f)); } #endif { Dock dock = new Dock(Orientation.Horizontal); dock.Name = "Reset Home dock"; dock.Style = Style.NullPadding; Button reset = new Button(renderer, "Reset"); reset.Action = ResetCamera; dock.Add(reset); /*Button reference = new Button(renderer, "Reference"); * reference.Action = ReferenceStereo; * dock.Add(reference);*/ Button home = new Button(renderer, "Home"); home.Action = HomeCamera; dock.Add(home); list.Add(dock); } var expand = new Button(renderer, "Camera", SetActive); expand.Link = list; return(expand); }
public void Reset() { CurrentPalette = "cupola"; wheel = window.Mouse.WheelPrecise; layer = new Layer(this, window); layer.Name = "Root layer"; if (Configuration.graphicalUserInterface == false) { return; } Dock verticalGroup = new Dock(Orientation.Vertical); active = new Dock(Orientation.Horizontal); #region bottom MenuList bottom = new MenuList(renderer, Orientation.Horizontal); bottom.Name = "test"; bottom.Add(Operations()); bottom.Add(Palette()); bottom.Add(Scene()); bottom.Add(Camera()); bottom.Add(Lights()); bottom.Add(Materials()); bottom.Add(Noise()); bottom.Add(Physics()); //if(Configuration.physics) { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "Action choice"; choice.Style = Style.NullPadding; if (Configuration.physics) { choice.Add(new ChoiceItem(renderer, "Drag")); choice.Add(new ChoiceItem(renderer, "Select")); } else { if (Configuration.physics) { choice.Add(new ChoiceItem(renderer, "Drag")); } choice.Add(new ChoiceItem(renderer, "Select")); } choice.Add(new ChoiceItem(renderer, "Add")); choice.Action = ActionChoiceAction; choice.Selected = choice.Items.First(); bottom.Add(choice); } { Choice choice = new Choice(Orientation.Horizontal); choice.Name = "AddWithPhysics choice"; choice.Style = Style.NullPadding; choice.Add(new ChoiceItem(renderer, "Add Static")); choice.Add(new ChoiceItem(renderer, "Add Dynamic")); choice.Action = AddModeChoiceAction; choice.Selected = choice.Items.First(); bottom.Add(choice); } bottom.OffsetFreeSizeRelative = new Vector2(0.5f, 0.0f); bottom.OffsetSelfSizeRelative = new Vector2(-0.5f, 0.0f); //bottom.OffsetPixels = new Vector2( 4.0f, 4.0f); #endregion bottom verticalGroup.Add(bottom); verticalGroup.OffsetFreeSizeRelative = new Vector2(0.5f, 0.0f); verticalGroup.OffsetSelfSizeRelative = new Vector2(-0.5f, 0.0f); verticalGroup.OffsetPixels = new Vector2(4.0f, 4.0f); verticalGroup.Add(active); Layer.Add(verticalGroup); if (CurrentScene != "Game") { ConnectUserControls(); } }