public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { FunctionColor function = (FunctionColor)item; if (!function.IsValid) { yield break; } ColorModel model = ColorParser.TryParseColor(function.Text, ColorParser.Options.AllowAlpha); if (model != null) { // Don't convert RGBA and HSLA to HEX or named color if (model.Alpha == 1) { if (ColorConverterSmartTagAction.GetNamedColor(model.Color) != null) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Name)); } yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.RgbHex3)); } if (model.Format == ColorFormat.Rgb) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Hsl)); } else if (model.Format == ColorFormat.Hsl) { yield return(new ColorConverterSmartTagAction(itemTrackingSpan, model, ColorFormat.Rgb)); } } }
public AddFunction(FunctionColor fc) { InitializeComponent(); this.fc = fc; Functions.Text = fc.Function; cp.SelectedColor = fc.Color; }
private static bool AreWithinLimits(Direction direction, float number, NumericalValue item) { UnitType type = GetUnitType(item); switch (type) { case UnitType.Angle: return((direction == Direction.Up) ? number <360 : number> -360); //case UnitType.Percentage: // return (direction == Direction.Up) ? number < 100 : number > 0; // Larger than zero case UnitType.Grid: case UnitType.Frequency: case UnitType.Resolution: case UnitType.Time: return((direction == Direction.Down) ? number > 0 : true); case UnitType.Percentage: case UnitType.Length: case UnitType.Viewport: return(true); } FunctionColor func = item.FindType <FunctionColor>(); if (func != null) { if (func.FunctionName.Text.StartsWith("rgb", StringComparison.Ordinal)) { if (direction == Direction.Up) { return(number < 255); } else { return(number > 0); } } if (func.FunctionName.Text.StartsWith("hsl", StringComparison.Ordinal)) { if (direction == Direction.Up) { return(number < 360); } else { return(number > 0); } } } return(true); }
private static void ValidateHsl(ICssCheckerContext context, FunctionColor function) { ParseItem argument; string text = ""; string[] pair; int argumentCount = function.Arguments.Count; int value; if (function.FunctionName.Text.StartsWith("hsla", StringComparison.OrdinalIgnoreCase) && argumentCount < 4) { context.AddError(new SimpleErrorTag(function.Arguments[2], "Validation: HSLA expects alpha value between 0 and 1 as fourth parameter", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } for (int i = 0; i < argumentCount; i++) { argument = function.Arguments[i]; text = argument.Text.Trim(','); if (i < 3) { pair = text.Split('%'); if (pair.Length > 1 || pair[0].IsNumeric()) { context.AddError(new SimpleErrorTag(argument, "Validation: Invalid value", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } if (!int.TryParse(pair[0], out value)) { context.AddError(new SimpleErrorTag(argument, "Validation: Missing value", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } else { if (value < 0 || value > 100) { context.AddError(new SimpleErrorTag(argument, "Validation: Values must be between 0 and 100%", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } if (i > 0 && value > 0 && pair[1] == "%") { context.AddError(new SimpleErrorTag(argument, "Validation: Parameter missing the % unit", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } } } else if (function.FunctionName.Text.StartsWith("hsla", StringComparison.OrdinalIgnoreCase)) { ValidateAlphaValue(context, argument, text); } else { context.AddError(new SimpleErrorTag(argument, "Validation: HSL cannot have fourth parameter. Are you confusing HSL with HSLA?", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } } }
public void Refresh(Canvas graphFunctions, ListBox list, TextBox minx, TextBox miny, TextBox maxx, TextBox maxy) { this.minX = Convert.ToDouble(minx.Text); this.maxX = Convert.ToDouble(maxx.Text); this.minY = Convert.ToDouble(miny.Text); this.maxY = Convert.ToDouble(maxy.Text); Loaded(graphFunctions, minX, maxX, minY, maxY); for (int i = 0; i < list.Items.Count; i++) { FunctionColor fc = list.Items[i] as FunctionColor; DrawFunction(graphFunctions, fc.Function, fc.Color); } }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { FunctionColor function = (FunctionColor)item; if (!function.IsValid || context == null) { return(ItemCheckResult.Continue); } if (function.FunctionName.Text.StartsWith("rgb")) { ValidateRgb(context, function); } return(ItemCheckResult.Continue); }
/// <summary> /// Creates a regular voxel on a voxel grid /// </summary> /// <param name="index">The index of the Voxel</param> /// <param name="voxelgrid">The <see cref="VoxelGrid"/> this <see cref="Voxel"/> is attached to</param> /// <param name="voxelGameObject">The <see cref="GameObject"/> used on the Voxel</param> public Voxel(Vector3Int index, VoxelGrid voxelGrid, bool createCollider = false, Transform parent = null) { Index = index; _voxelGrid = voxelGrid; _size = _voxelGrid.VoxelSize; IsActive = true; FColor = FunctionColor.Empty; if (createCollider) { var colliderPrefab = Resources.Load <GameObject>("Prefabs/VoxelCollider"); VoxelCollider = GameObject.Instantiate(colliderPrefab, parent, true); VoxelCollider.transform.localPosition = new Vector3(Index.x, Index.y, Index.z) * _size; VoxelCollider.name = $"{Index.x}_{Index.y}_{Index.z}"; VoxelCollider.tag = "Voxel"; } }
private static void ValidateHsl(ICssCheckerContext context, FunctionColor function) { ParseItem argument; string text = ""; string[] pair; int argumentCount = function.Arguments.Count; int value; if (function.FunctionName.Text.StartsWith("hsla", StringComparison.OrdinalIgnoreCase) && argumentCount < 4) { context.AddError(new SimpleErrorTag(function.Arguments[2], "Validation: HSLA expects alpha value between 0 and 1 as fourth parameter", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } for (int i = 0; i < argumentCount; i++) { argument = function.Arguments[i]; text = argument.Text.Trim(','); if (i < 3) { pair = text.Split('%'); if (int.TryParse(pair[0], out value)) { if (value < 0 || value > 100 && i > 0) { context.AddError(new SimpleErrorTag(argument, "Validation: Values must be between 0 and 100%", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } if (i > 0 && value > 0 && pair[1] == "%") { context.AddError(new SimpleErrorTag(argument, "Validation: Parameter missing the % unit", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } } } else if (function.FunctionName.Text.StartsWith("hsla", StringComparison.OrdinalIgnoreCase)) { ValidateAlphaValue(context, argument, text); } else { context.AddError(new SimpleErrorTag(argument, "Validation: HSL cannot have fourth parameter. Are you confusing HSL with HSLA?", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } } }
private static void ValidateRgb(ICssCheckerContext context, FunctionColor function) { for (int i = 0; i < function.Arguments.Count; i++) { var argument = function.Arguments[i]; string text = argument.Text.Trim(','); if (i < 3) { int value; if (int.TryParse(text, out value) && (value < 0 || value > 255)) context.AddError(new SimpleErrorTag(argument, Resources.ValidationColorValuesInRange, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } else { ValidateAlphaValue(context, argument, text); } } }
private static void ValidateHsl(ICssCheckerContext context, FunctionColor function) { for (int i = 0; i < function.Arguments.Count; i++) { var argument = function.Arguments[i]; string text = argument.Text.Trim(',','%'); if (i < 3) { int value; if (int.TryParse(text, out value) && (value < 0 || value > 100)) context.AddError(new SimpleErrorTag(argument, "Validation: Values must be between 0 and 100%", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } else { ValidateAlphaValue(context, argument, text); } } }
public ItemCheckResult CheckItem(ParseItem item, ICssCheckerContext context) { FunctionColor function = (FunctionColor)item; if (!function.IsValid || context == null) { return(ItemCheckResult.Continue); } if (function.FunctionName.Text.StartsWith("rgb", StringComparison.OrdinalIgnoreCase)) { ValidateRgb(context, function); } //else if (function.FunctionName.Text.StartsWith("hsl")) //{ // ValidateHsl(context, function); //} return(ItemCheckResult.Continue); }
private static void ValidateRgb(ICssCheckerContext context, FunctionColor function) { for (int i = 0; i < function.Arguments.Count; i++) { var argument = function.Arguments[i]; string text = argument.Text.Trim(','); if (i < 3) { int value; if (int.TryParse(text, out value) && (value < 0 || value > 255)) { context.AddError(new SimpleErrorTag(argument, Resources.ValidationColorValuesInRange, CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } } else { ValidateAlphaValue(context, argument, text); } } }
private static void ValidateHsl(ICssCheckerContext context, FunctionColor function) { for (int i = 0; i < function.Arguments.Count; i++) { var argument = function.Arguments[i]; string text = argument.Text.Trim(',', '%'); if (i < 3) { int value; if (int.TryParse(text, out value) && (value < 0 || value > 100)) { context.AddError(new SimpleErrorTag(argument, "Validation: Values must be between 0 and 100%", CssErrorFlags.TaskListWarning | CssErrorFlags.UnderlineRed)); } } else { ValidateAlphaValue(context, argument, text); } } }
/// <summary> /// Tries to create a black rectangle from the /// specified origin and with the specified size /// </summary> /// <param name="origin">The index of the origin</param> /// <param name="width">The width of the rectangle, in X</param> /// <param name="depth">The depth of the rectangle, in Z</param> /// <param name="layer">The layer to draw in, default is 0</param> /// <returns>If the process was successful</returns> public bool CreateBlackRectangle(Vector3Int origin, int width, int depth, int layer = 0) { FunctionColor fcolor = FunctionColor.Black; int oX = origin.x; int oZ = origin.z; List <Voxel> recVoxels = new List <Voxel>(); for (int x = oX; x < oX + width; x++) { for (int z = oZ; z < oZ + depth; z++) { Vector3Int idx = new Vector3Int(x, 0, z); if (Util.ValidateIndex(GridSize, idx)) { var voxel = Voxels[x, layer, z]; if (voxel.FColor == FunctionColor.Empty) { recVoxels.Add(voxel); } else { return(false); } } else { return(false); } } } foreach (var voxel in recVoxels) { voxel.FColor = fcolor; } return(true); }
private void EditButton_Click(object sender, RoutedEventArgs e) { if (FunctionsList.SelectedItems == null) { return; } AddFunction addFunction = new AddFunction(FunctionsList.SelectedItem as FunctionColor); if (addFunction.ShowDialog() == DialogResult.HasValue) { FunctionsList.Items.Remove(FunctionsList.SelectedItem); FunctionsList.Items.Add(addFunction.Fc); functions.Loaded(GraphFunctions, minX, maxX, minY, maxY); for (int i = 0; i < FunctionsList.Items.Count; i++) { fc = FunctionsList.Items[i] as FunctionColor; functions.DrawFunction(GraphFunctions, fc.Function, fc.Color); } } }
public void DrawFunction(Func <double, double> function, Brush color) { if (!Functions.Contains(function)) { Functions.Add(function); FunctionColor.Add(color); } double previousX = 0; double previousY = 0; for (double i = MinX; i <= MaxX; i += 0.01) { var result = function(i); if (result >= MinY && result <= MaxY) { previousX = (i - MinX) * Unit; previousY = (MaxY - function(i)) * Unit; break; } } for (var i = MinX + 0.01; i <= MaxX; i += 0.01) { var currentX = (i - MinX) * Unit; var currentY = (MaxY - function(i)) * Unit; if (function(i) < MinY || function(i) > MaxY) { continue; } var draw = new Line(); DrawLine(draw, previousX, currentX, previousY, currentY); draw.Stroke = color; draw.StrokeThickness = 3; Plane.Children.Add(draw); previousX = currentX; previousY = currentY; } }
/// <summary> /// Creates a regular voxel on a voxel grid /// </summary> /// <param name="index">The index of the Voxel</param> /// <param name="voxelgrid">The <see cref="VoxelGrid"/> this <see cref="Voxel"/> is attached to</param> /// <param name="voxelGameObject">The <see cref="GameObject"/> used on the Voxel</param> public Voxel(Vector3Int index, VoxelGrid voxelGrid, bool createCollider = false, Transform parent = null) { Index = index; _voxelGrid = voxelGrid; _size = _voxelGrid.VoxelSize; IsActive = true; FColor = FunctionColor.Empty; if (createCollider) { var colliderPrefab = Resources.Load <GameObject>("Prefabs/VoxelCollider"); VoxelCollider = GameObject.Instantiate(colliderPrefab, parent, true); VoxelCollider.transform.localPosition = new Vector3(Index.x, Index.y, Index.z) * _size; VoxelCollider.name = $"{Index.x}_{Index.y}_{Index.z}"; VoxelCollider.tag = "Voxel"; } //_PlotVoxel = GameObject.CreatePrimitive(PrimitiveType.Cube); //_PlotVoxel.transform.position = (_voxelGrid.Origin + Index) * _size; //_PlotVoxel.transform.localScale *= _voxelGrid.VoxelSize * 1; //_PlotVoxel.name = $"Voxel_{Index.x}_{Index.y}_{Index.z}"; //_PlotVoxel.GetComponent<MeshRenderer>().material = Resources.Load<Material>("Materials/Plot"); }
public void FunctionColor_FloatParseTest() { StyleSheet ss = Helpers.MakeStyleSheet("p { color: rgba(1, 2, 3, 0.625); }"); FunctionColor func = ss.RuleSets[0].Block.Declarations[0].Values[0] as FunctionColor; Assert.IsNotNull(func); Assert.IsTrue(func.GetColorArgumentValue(3, false, out float value)); Assert.AreEqual(0.625f, value); CultureInfo oldCulture = Thread.CurrentThread.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("ru-RU"); Assert.IsTrue(func.GetColorArgumentValue(3, false, out value)); Assert.AreEqual(0.625f, value); } finally { // Don't let the asserts cause the thread to stay in the wrong culture Thread.CurrentThread.CurrentCulture = oldCulture; } }
public void FindShortestPath(Vector3Int start, Vector3Int end, int radius, Vector3Int voxelGrid) { //a list to store the path voxel List <Voxel> pathVoxels = new List <Voxel>(); FunctionColor pathColor = FunctionColor.White; voxelGrid = _voxelGrid.GridSize; //add the start and end voxel to list if (Util.ValidateIndex(voxelGrid, start)) { pathVoxels.Add(_voxelGrid.Voxels[start.x, start.y, start.z]); } else { pathVoxels = null; } for (int i = 0; i < radius; i++) { List <Voxel> availableVoxels = new List <Voxel>(); foreach (var voxel in pathVoxels) { //get the neighbors of path voxel Voxel[] neighbors; neighbors = voxel.GetFaceNeighboursXZ().ToArray(); foreach (var neighbour in neighbors) { //check if is the available plot voxel //+ if color is blue(backyard area that allows to grow) if (neighbour.FColor == FunctionColor.Blue && neighbour.IsActive && Util.ValidateIndex(voxelGrid, neighbour.Index) && !pathVoxels.Contains(neighbour) && !availableVoxels.Contains(neighbour)) { availableVoxels.Add(neighbour); } } } if (availableVoxels.Count == 0) { break; } // add these available voxels to growing voxels list foreach (var availableVoxel in availableVoxels) { if (availableVoxel.FColor == FunctionColor.Blue) { pathVoxels.Add(availableVoxel); } } } // set the plot color and quality foreach (var voxel in pathVoxels) { if (voxel.FColor == FunctionColor.Blue) { voxel.FColor = FunctionColor.White; voxel.Qname = ColorQuality.Plot; } } }
/// <summary> /// Tries to create a black blob from the /// specified origin and with the specified size /// </summary> /// <param name="origin">The index of the origin</param> /// <param name="radius">The radius of the blob in voxels</param> /// <param name="picky">If the blob should skip voxels randomly as it expands</param> /// <param name="flat">If the blob should be located on the first layer or use all</param> /// <returns></returns> public bool CreateBlackBlob(Vector3Int origin, int radius, bool picky = true, bool flat = true) { // Create the list to store the blob voxels List <Voxel> blobVoxels = new List <Voxel>(); // Set the target fucntion color to black FunctionColor fcolor = FunctionColor.Black; // Check if the origin is valid and add it to the list of voxels if (Util.ValidateIndex(GridSize, origin)) { blobVoxels.Add(Voxels[origin.x, origin.y, origin.z]); } else { return(false); } // Iterate through each of the neighbouring layers for (int i = 0; i < radius; i++) { // Create a list to store the new voxels List <Voxel> newVoxels = new List <Voxel>(); // Check the neighbours of each of the voxels already collected foreach (var voxel in blobVoxels) { // Get it's neighbours Voxel[] neighbours; if (flat) { neighbours = voxel.GetFaceNeighboursXZ().ToArray(); } else { neighbours = voxel.GetFaceNeighbours().ToArray(); } // Iterate through each neighbour foreach (var neighbour in neighbours) { // Decide if neighbour should be taken if picky is true bool takeMe = true; if (picky && (Random.value < 0.6f)) { takeMe = false; } // Check if neighbour is valid if (takeMe && neighbour.IsActive && Util.ValidateIndex(GridSize, neighbour.Index) && neighbour.FColor == FunctionColor.Empty && !blobVoxels.Contains(neighbour) && !newVoxels.Contains(neighbour)) { // Add to temp list newVoxels.Add(neighbour); } } } // If no new voxels were added, break if (newVoxels.Count == 0) { break; } // Add new voxels to main list foreach (var newVoxel in newVoxels) { blobVoxels.Add(newVoxel); } } // If the resulting number of voxels is less than the radius, return false if (blobVoxels.Count < radius) { return(false); } // Set the Function color of the voxels foreach (var voxel in blobVoxels) { voxel.FColor = fcolor; } return(true); }
/// <summary> /// Tries to create a black blob from the /// specified origin and with the specified size /// </summary> /// <param name="origin">The index of the origin</param> /// <param name="radius">The radius of the blob in voxels</param> /// <param name="picky">If the blob should skip voxels randomly as it expands</param> /// <param name="flat">If the blob should be located on the first layer or use all</param> /// <returns></returns> public bool GrowPlot(Vector3Int origin, int radius, int height = 0) { //List<Vector3> growingVoxel //A list to store the growing voxel List <Voxel> growingVoxel = new List <Voxel>(); //Give them white coluor as plot FunctionColor plotcolor = FunctionColor.White; //check if the origin is valid and add it to voxel list if (Util.ValidateIndex(GridSize, origin)) { growingVoxel.Add(Voxels[origin.x, height, origin.z]); } else { return(false); } //Iterate through the neighboring layer within the radius for (int i = 0; i < radius; i++) { List <Voxel> availableVoxels = new List <Voxel>(); foreach (var voxel in growingVoxel) { //Get neighbors in 2D or 3D Voxel[] neighbors; if (height == 0) { neighbors = voxel.GetFaceNeighboursXZ().ToArray(); } else { neighbors = voxel.GetFaceNeighbours().ToArray(); } //Iterate each neighbors + and check if is available foreach (var neighbour in neighbors) { //check if is the available plot voxel //+ if color is blue(backyard area that allows to grow) if (neighbour.FColor == FunctionColor.Blue && neighbour.IsActive && Util.ValidateIndex(GridSize, neighbour.Index) && !growingVoxel.Contains(neighbour) && !availableVoxels.Contains(neighbour)) { availableVoxels.Add(neighbour); } } } if (availableVoxels.Count == 0) { break; } //add these available voxels to growing voxels list foreach (var availableVoxel in availableVoxels) { if (availableVoxel.FColor == FunctionColor.Blue) { growingVoxel.Add(availableVoxel); } } } // set the plot color and quality foreach (var voxel in growingVoxel) { if (voxel.FColor == FunctionColor.Blue) { voxel.FColor = plotcolor; voxel.Qname = ColorQuality.Plot; } } return(true); }
private void CancelButton_Click(object sender, RoutedEventArgs e) { fc = null; this.Close(); }