/// <summary>Creates a new canvas context for the given canvas element.</summary> /// <param name="canvas">The canvas handler for a particular canvas element.</param> public CanvasContext(CanvasTag tag) { // Apply the tag: Canvas = tag; Path = new VectorPath(); }
public override ShapeProvider ToShape(SVGElement context, RenderContext renderer, out Css.Value value) { value = this; if (_cachedTarget == null) { string id = this[0].Hash; // Get the target now: SVGElement target = context.document.getElementById(id) as SVGElement; if (target == null) { return(null); } // Get the path from the element (note that it could be a clip path): VectorPath path = target.GetPath(context, renderer); // Create a shape provider for it: _cachedTarget = new ShapeProvider(); _cachedTarget.SetPath(path); } return(_cachedTarget); }
public void NestPaths(VectorDocument doc, int size, uint sheet) { CutLibWrapper.CutTestResult res = new CutLibWrapper.CutTestResult(); CutLibWrapper.ResetSheet(sheet, size); doc.DocHeight = size; foreach (VectorPath pi in doc.Paths) { pi.Nested = false; } VectorPath p = null; while ((p = GetPathByMaxArea(doc)) != null) { res.resultOK = false; CutLibWrapper.TestShape(sheet, p.Shape, ref res, true, 0); if (res.resultOK) { CutLibWrapper.Plot(sheet, p.Shape, res.angle, res.x, res.y); p.SetPos(res.x, res.y); p.Rotate(res.angle); } p.Nested = true; } }
public bool NestPath(VectorPath path) { if (pathId.ContainsKey(path.PathID)) { uint shape = pathId[path.PathID]; CutTestResult res = new CutTestResult(); TestShape((uint)cutSheet, shape, ref res, path.ForceAngle, path.ForcedAngle); if (res.resultOK) { path.SetPos(res.x, res.y); path.Rotate(res.angle); path.SetAsGoodPos(); path.GenerateCurrentScan(); PlotCurrentScan((uint)cutSheet, shape, res.x, res.y); return(true); } } return(false); }
public PathCPUParticleEmitter(GameScreen scrn, FPoint pos, VectorPath path, ParticleEmitterConfig cfg, int order) : base(scrn, cfg, order) { vectorPath = path; vectorPathCenter = path.Boundings.Center; Position = pos; }
/// <summary> /// Renders the fill of the <see cref="SvgVisualElement"/> to the specified <see cref="RenderContext"/> /// </summary> protected internal virtual void BuildFill(VectorPath path, RenderContext renderer) { // Get the fill: Loonim.TextureNode fill = Fill; if (fill == null) { // Fill isn't active. return; } // Get as a property: Loonim.Property prop = (fill as Loonim.Property); if (prop != null) { // Check if it's transparent: if (prop.Colour.a == 0f) { return; } } ApplyOpacity(FillOpacity, prop, ref fill); // Fill now! renderer.FillPath(fill, path, (FillRule == "evenodd")); }
/// <summary>Renders a stroke with markers.</summary> protected bool BuildStrokeMarkers(VectorPath path, RenderContext renderer) { // Default (base) stroke first: bool result = BuildDefaultStroke(path, renderer); /* * if (MarkerStart != null){ * SvgMarker marker = this.OwnerDocument.GetElementById<SvgMarker>(this.MarkerStart.ToString()); * marker.RenderMarker(renderer, this, path.PathPoints[0], path.PathPoints[0], path.PathPoints[1]); * } * * if (MarkerMid != null){ * SvgMarker marker = this.OwnerDocument.GetElementById<SvgMarker>(this.MarkerMid.ToString()); * for (int i = 1; i <= path.PathPoints.Length - 2; i++) * marker.RenderMarker(renderer, this, path.PathPoints[i], path.PathPoints[i - 1], path.PathPoints[i], path.PathPoints[i + 1]); * } * * if (MarkerEnd != null){ * SvgMarker marker = this.OwnerDocument.GetElementById<SvgMarker>(this.MarkerEnd.ToString()); * marker.RenderMarker(renderer, this, path.PathPoints[path.PathPoints.Length - 1], path.PathPoints[path.PathPoints.Length - 2], path.PathPoints[path.PathPoints.Length - 1]); * } */ return(result); }
public void TestToString() { double x = 3; double y = 5; VectorPath path = new VectorPath(); Vector vector = new Vector(x, y); path.Add(vector); string expected = $"[{x};{y}] with magnitude {vector.Magnitude()}\n"; vector = new Vector(x, -y); path.Add(vector); expected += $"[{x};{-y}] with magnitude {vector.Magnitude()}\n"; vector = new Vector(-x, -y); path.Add(vector); expected += $"[{-x};{-y}] with magnitude {vector.Magnitude()}\n"; vector = new Vector(-x, y); path.Add(vector); expected += $"[{-x};{y}] with magnitude {vector.Magnitude()}"; Assert.Equal(expected, path.ToString()); }
static void Main(string[] args) { Console.WriteLine("Welcome to Vectors - From Start to End"); Console.WriteLine("This app allows you to insert mathematical vectors"); Console.WriteLine("and calculate the resulting total vector.\n"); VectorPath path = new VectorPath(); bool keepAddingVectors = true; do { Console.Write("Please enter the x and y coordinates (separated with space - both zero stops): "); string[] coordinates = Console.ReadLine().Split(" "); if (coordinates[0] != "0" && coordinates[0] != "0") { double x = Convert.ToDouble(coordinates[0]); double y = Convert.ToDouble(coordinates[1]); path.Add(new Vector(x, y)); } else { keepAddingVectors = false; } } while (keepAddingVectors); Console.WriteLine("\n-------------------------------------------------------"); Console.WriteLine("Summing all vector:"); Console.WriteLine(path); Console.WriteLine("\nThe resulting vector is: " + path.ResultingVector()); Console.WriteLine("-------------------------------------------------------"); Console.WriteLine("\nThank you for using our app"); }
void Start() { NotePath = new VectorPath(new Vector3[] { transform.position, NoteTarget.transform.position }); }
/// <summary> /// Gets the clip path. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { if (_computedPath == null) { Matrix4x4 transform; bool applyExtra; if (ClipPathUnits == CoordinateUnits.ObjectBoundingBox) { BoxRegion bounds = context.Bounds; transform = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3( bounds.Width, bounds.Height, 0f )); transform *= Matrix4x4.TRS(new Vector3( bounds.X, bounds.Y, 0f ), Quaternion.identity, Vector3.one); applyExtra = true; } else { transform = Matrix4x4.identity; applyExtra = false; } // For each child which is a PathBase, append it. _computedPath = new VectorPath(); AddChildPaths(this, _computedPath, renderer, transform, applyExtra); } return(_computedPath); }
public void RegisterPath(VectorPath path) { if (!pathId.ContainsKey(path.PathID)) { uint shape = path.GenerateCutShape((uint)cutSheet); pathId.Add(path.PathID, shape); } }
/// <summary>Creates a new canvas context for the given canvas element.</summary> /// <param name="canvas">The canvas for a particular canvas element.</param> public CanvasContext(HtmlCanvasElement canvas) { // Apply the tag: Canvas = canvas; Path = new VectorPath(); ImageData_ = new DynamicTexture(); canvas.SetImage(ImageData_); }
public void TestResultingVectorWithoutAdd() { VectorPath path = new VectorPath(); Vector result = path.ResultingVector(); Assert.Equal(0, result.X(), 2); Assert.Equal(0, result.Y(), 2); }
public AnimatedPathCPUParticleEmitter(GameScreen scrn, FPoint pos, VectorPath path, ParticleEmitterConfig cfg, float delay, float length, int order) : base(scrn, cfg, order) { vectorPath = path; vectorPathCenter = path.Boundings.Center; Position = pos; animationLength = length; animationInitialDelay = delay; }
/// <summary>Generates one or more stroke meshes for the given path.</summary> public List <Mesh> GenerateMeshes(VectorPath path) { // Output set: Output = new List <Mesh>(); // Generate: Generate(path); return(Output); }
/// <summary>Adds all child paths together.</summary> protected VectorPath GetPaths(Node parent, RenderContext renderer) { // Create: VectorPath bakeInto = new VectorPath(); // Add: AddChildPaths(parent, bakeInto, renderer, Matrix4x4.identity, false); return(bakeInto); }
public PathScreenRegion(VectorPath path) { Path = path; if (path.Width == 0f) { // Bounds are required here: path.RecalculateBounds(); } }
public void TestResultingSingleVector() { VectorPath path = new VectorPath(); path.Add(new Vector(8, -22)); Vector result = path.ResultingVector(); Assert.Equal(8, result.X(), 2); Assert.Equal(-22, result.Y(), 2); }
/// <summary> /// Gets the path representing this element. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { Css.RenderableData rd = context.RenderData; // Don't build the path if there's no radius: float radius = Radius.GetDecimal(rd, ViewportAxis.None); if (radius <= 0) { return(null); } if (_Path == null) { // Don't need to consider stroke width. _Path = new VectorPath(); float centerX = CenterX.GetDecimal(rd, ViewportAxis.X); float centerY = CenterX.GetDecimal(rd, ViewportAxis.Y); // Get the C values: float cX = BezierC * radius; float cY = cX; // Offset to match the center: cX += centerX; cY += centerY; float radiusX = centerX + radius; float radiusY = centerY + radius; float nRadiusX = centerX - radius; float nRadiusY = centerY - radius; _Path.MoveTo(centerX, radiusY); // First quadrant (top right, going clockwise): _Path.CurveTo(cX, radiusY, radiusX, cY, radiusX, centerY); // Bottom right: _Path.CurveTo(radiusX, -cY, cX, nRadiusY, centerX, nRadiusY); // Bottom left: _Path.CurveTo(-cX, nRadiusY, nRadiusX, -cY, nRadiusX, centerY); // Top left: _Path.CurveTo(nRadiusX, cY, -cX, radiusY, centerX, radiusY); // Mark as closed: _Path.LatestPathNode.IsClose = true; } return(_Path); }
/// <summary> /// Gets the path representing this element. /// </summary> public override VectorPath GetPath(SVGElement context, RenderContext renderer) { Css.RenderableData rd = context.RenderData; if (_Path == null) { _Path = new VectorPath(); try{ Css.Value points = Points; int count = points.Count; for (int i = 2; (i + 1) < count; i += 2) { float endPointX = points[i].GetDecimal(rd, ViewportAxis.X); float endPointY = points[i + 1].GetDecimal(rd, ViewportAxis.Y); if (Close) { //first line if (_Path.FirstPathNode == null) { // Wrap around: float startPointX = points[i - 2].GetDecimal(rd, ViewportAxis.X); float startPointY = points[i - 1].GetDecimal(rd, ViewportAxis.Y); _Path.MoveTo(startPointX, startPointY); } _Path.LineTo(endPointX, endPointY); } else { // It's a polyline //first line if (_Path.FirstPathNode == null) { _Path.MoveTo(endPointX, endPointY); } else { _Path.LineTo(endPointX, endPointY); } } } } catch { Dom.Log.Add("Warning: Failed to parse a set of points for a polygon definition in either an SVG or your CSS."); } } return(_Path); }
public void TestResultingTwoVectors() { VectorPath path = new VectorPath(); path.Add(new Vector(3, 4)); path.Add(new Vector(5, -1)); Vector result = path.ResultingVector(); Assert.Equal(8, result.X(), 2); Assert.Equal(3, result.Y(), 2); }
public void TestResultingFourVectors() { VectorPath path = new VectorPath(); path.Add(new Vector(11.98, 0.63)); path.Add(new Vector(22.63, 22.63)); path.Add(new Vector(1.92, -0.55)); path.Add(new Vector(-3.36, 12.56)); Vector result = path.ResultingVector(); Assert.Equal(33.17, result.X(), 2); Assert.Equal(35.27, result.Y(), 2); }
/// <summary> /// Used to generate the smooth curve control points. /// </summary> public static void Reflect(VectorPath path, out float cx, out float cy) { // - Take the last control point from the previous curve // - Reflect it around the start point // - Result is 'my' first control point VectorPoint node = path.LatestPathNode; if (node == null) { cx = 0f; cy = 0f; return; } float lastControlX = 0f; float lastControlY = 0f; float reflectAroundX = node.X; float reflectAroundY = node.Y; // Try as a curve: CurveLinePoint clp = node as CurveLinePoint; if (clp == null) { // Try quad point instead: QuadLinePoint qlp = node as QuadLinePoint; if (qlp == null) { cx = path.LatestPathNode.X; cy = path.LatestPathNode.Y; return; } lastControlX = qlp.Control1X; lastControlY = qlp.Control1Y; } else { lastControlX = clp.Control2X; lastControlY = clp.Control2Y; } // Reflect lastControl around reflectAround: // reflectAround-(COORD-reflectAround) cx = 2f * reflectAroundX - lastControlX; cy = 2f * reflectAroundY - lastControlY; }
/// <summary> /// Updates the input layer resources from <see cref="VectorPath"/> instance, or replace by new path resource and updates. /// </summary> /// <param name="psdLayer">The psd layer.</param> /// <param name="vectorPath">The vector path.</param> /// <param name="imageSize">The image size to correct converting point coordinates.</param> public static void UpdateLayerFromVectorPath(Layer psdLayer, VectorPath vectorPath, bool createIfNotExist = false) { ValidateLayer(psdLayer); VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, createIfNotExist); VogkResource vogkResource = FindVogkResource(psdLayer, createIfNotExist); SoCoResource socoResource = FindSoCoResource(psdLayer, createIfNotExist); Size imageSize = psdLayer.Container.Size; UpdateResources(pathResource, vogkResource, socoResource, vectorPath, imageSize); ReplaceVectorPathDataResourceInLayer(psdLayer, pathResource, vogkResource, socoResource); }
/// <summary>Gets the defined shape as a region. Allows optimisations for rectangles.</summary> public virtual ScreenRegion GetRegion(SVGElement context, RenderContext ctx) { // Get the path: VectorPath path = GetPath(context, ctx); if (path == null || path.FirstPathNode == null) { // None! return(null); } // Create a shape region for it: return(new PathScreenRegion(path)); }
public void DrawPath(FPoint pos, VectorPath path, int segments, Color color, float thickness = 1) { foreach (var segment in path.Segments) { if (segment is LineSegment) { DrawPathSegment(pos, segment, 1, color, thickness); } else { DrawPathSegment(pos, segment, segments, color, thickness); } } }
/// <summary>Adds all child paths together.</summary> protected void AddChildPaths(Node parent, VectorPath bakeInto, RenderContext renderer, Matrix4x4 extraTransform, bool applyExtra) { if (parent.childNodes_ == null) { return; } foreach (Node child in parent.childNodes_) { SVGGeometryElement pathBase = child as SVGGeometryElement; // Got a path? if (pathBase != null) { // Yep! Get the path itself: VectorPath path = pathBase.GetPath(pathBase, renderer); if (path != null) { // Copy it: path = path.CopyPath(); // Push transform: pathBase.PushTransforms(renderer); // Get the resolved matrix: Matrix4x4 transform = renderer.Transform.Matrix; // Apply extra transform: if (applyExtra) { transform *= extraTransform; } // Pop it again: pathBase.PopTransforms(renderer); // Transform the path: path.Transform(transform); // Add into bakeInto: bakeInto.Append(path); } } // Apply to this child too: AddChildPaths(child, bakeInto, renderer, extraTransform, applyExtra); } }
private void AddLetter(VectorPath chr, ParticleEmitterConfig cfg, float px, float py, float scale, float animOffset, float animLen) { if (UseCPUParticles) { var emt = new AnimatedPathCPUParticleEmitter(_screen, new FPoint(px, py), chr.AsScaled(scale), cfg, animOffset, animLen, _order); _childEmitter.Add(emt); _screen.Entities.AddEntity(emt); } else { var emt = new AnimatedPathGPUParticleEmitter(_screen, new FPoint(px, py), chr.AsScaled(scale), cfg, animOffset, animLen, _order); _childEmitter.Add(emt); _screen.Entities.AddEntity(emt); } }
private void BuildFilter(RenderContext renderer, bool withCssFilter) { // Get a path to draw: VectorPath path = GetPath(this, renderer); if (Visibility == VisibilityMode.Hidden || !PushTransforms(renderer)) { return; } if (withCssFilter) { // Get the filter CSS property: Css.Value filterValue = style.Computed[Css.Properties.Filter.GlobalProperty]; if (filterValue != null) { string filterPath = filterValue.Text; Element filter = document.getElementById(filterPath) as SVGFilterElement; if (filter != null) { PopTransforms(renderer); // filter.ApplyFilter(this, renderer, (r) => this.BuildFilter(r, false)); // Don't render normally. return; } } } SetClip(renderer); if (path != null) { BuildFill(path, renderer); BuildStroke(path, renderer); } else { BuildChildren(renderer); } ResetClip(renderer); PopTransforms(renderer); }
public void Parse(GameBitBuffer buffer) { Field0 = buffer.ReadInt(32); Field1 = buffer.ReadInt(32); Field2 = buffer.ReadInt(32); Field3 = buffer.ReadInt(32); Field4 = buffer.ReadInt(32); Field5 = new InterpolationScalar(); Field5.Parse(buffer); Field6 = new FloatPath(); Field6.Parse(buffer); Field7 = new IntPath(); Field7.Parse(buffer); Field8 = new FloatPath(); Field8.Parse(buffer); Field9 = new TimePath(); Field9.Parse(buffer); Field10 = new FloatPath(); Field10.Parse(buffer); Field11 = new AnglePath(); Field11.Parse(buffer); Field12 = new VelocityVectorPath(); Field12.Parse(buffer); Field13 = new VelocityVectorPath(); Field13.Parse(buffer); Field14 = new VelocityPath(); Field14.Parse(buffer); Field15 = new VelocityPath(); Field15.Parse(buffer); Field16 = new VelocityPath(); Field16.Parse(buffer); Field17 = new VectorPath(); Field17.Parse(buffer); Field18 = new VelocityPath(); Field18.Parse(buffer); Field19 = buffer.ReadFloat32(); Field20 = new UberMaterial(); Field20.Parse(buffer); snoPhysics = buffer.ReadInt(32); Field22 = buffer.ReadFloat32(); Field23 = buffer.ReadInt(32); Field24 = buffer.ReadFloat32(); Field25 = buffer.ReadFloat32(); Field26 = buffer.ReadFloat32(); Field27 = buffer.ReadFloat32(); Field28 = buffer.ReadFloat32(); Field29 = buffer.ReadFloat32(); Field30 = buffer.ReadFloat32(); snoActor = buffer.ReadInt(32); Field32 = new EmitterParams(); Field32.Parse(buffer); Field33 = new ColorPath(); Field33.Parse(buffer); Field34 = new FloatPath(); Field34.Parse(buffer); Field35 = new FloatPath(); Field35.Parse(buffer); Field36 = new FloatPath(); Field36.Parse(buffer); Field37 = new AnglePath(); Field37.Parse(buffer); Field38 = new AngularVelocityPath(); Field38.Parse(buffer); Field39 = new AngularVelocityPath(); Field39.Parse(buffer); Field40 = new AnglePath(); Field40.Parse(buffer); Field41 = new VectorPath(); Field41.Parse(buffer); Field42 = new FloatPath(); Field42.Parse(buffer); Field43 = new VelocityPath(); Field43.Parse(buffer); Field44 = new AngularVelocityPath(); Field44.Parse(buffer); Field45 = new FloatPath(); Field45.Parse(buffer); Field46 = new VelocityPath(); Field46.Parse(buffer); Field47 = new VectorPath(); Field47.Parse(buffer); Field48 = new VelocityVectorPath(); Field48.Parse(buffer); Field49 = new AccelVectorPath(); Field49.Parse(buffer); Field50 = new VectorPath(); Field50.Parse(buffer); Field51 = new VelocityVectorPath(); Field51.Parse(buffer); Field52 = new AccelVectorPath(); Field52.Parse(buffer); Field53 = new VelocityPath(); Field53.Parse(buffer); Field54 = new FloatPath(); Field54.Parse(buffer); Field55 = buffer.ReadInt(32); Field56 = buffer.ReadFloat32(); Field57 = buffer.ReadFloat32(); serMsgTriggeredEvents = new SerializeData(); serMsgTriggeredEvents.Parse(buffer); Field59 = buffer.ReadInt(32); Field60 = new DT_VARIABLEARRAY(); Field60.Parse(buffer); }
public void Parse(GameBitBuffer buffer) { Field0 = buffer.ReadInt(32); Field1 = new FloatPath(); Field1.Parse(buffer); Field2 = new FloatPath(); Field2.Parse(buffer); Field3 = new VectorPath(); Field3.Parse(buffer); Field4 = buffer.ReadCharArray(128); }
public void Parse(GameBitBuffer buffer) { Field0 = buffer.ReadInt(32); Field1 = buffer.ReadInt(32); Field2 = buffer.ReadInt(32); Field3 = buffer.ReadFloat32(); Field4 = buffer.ReadFloat32(); Field5 = new VectorPath(); Field5.Parse(buffer); Field6 = new VectorPath(); Field6.Parse(buffer); Field7 = new AnglePath(); Field7.Parse(buffer); Field8 = new FloatPath(); Field8.Parse(buffer); Field9 = new AnglePath(); Field9.Parse(buffer); Field10 = new FloatPath(); Field10.Parse(buffer); Field11 = new AnglePath(); Field11.Parse(buffer); Field12 = new FloatPath(); Field12.Parse(buffer); }
public void Parse(GameBitBuffer buffer) { Field0 = buffer.ReadInt(32); Field1 = buffer.ReadInt(32); Field2 = buffer.ReadFloat32(); Field3 = buffer.ReadFloat32(); Field4 = buffer.ReadFloat32(); Field5 = buffer.ReadFloat32(); Field6 = buffer.ReadFloat32(); Field7 = buffer.ReadFloat32(); Field8 = new UberMaterial(); Field8.Parse(buffer); snoPhysics = buffer.ReadInt(32); Field10 = buffer.ReadInt(32); Field11 = buffer.ReadInt(32); Field12 = buffer.ReadInt(32); Field13 = buffer.ReadInt(32); Field14 = new ColorPath(); Field14.Parse(buffer); Field15 = new ColorPath(); Field15.Parse(buffer); Field16 = new FloatPath(); Field16.Parse(buffer); Field17 = new FloatPath(); Field17.Parse(buffer); Field18 = new FloatPath(); Field18.Parse(buffer); Field19 = new FloatPath(); Field19.Parse(buffer); Field20 = new FloatPath(); Field20.Parse(buffer); Field21 = new FloatPath(); Field21.Parse(buffer); Field22 = new FloatPath(); Field22.Parse(buffer); Field23 = new FloatPath(); Field23.Parse(buffer); Field24 = new FloatPath(); Field24.Parse(buffer); Field25 = new FloatPath(); Field25.Parse(buffer); Field26 = new VectorPath(); Field26.Parse(buffer); Field27 = new VelocityPath(); Field27.Parse(buffer); Field28 = buffer.ReadFloat32(); Field29 = buffer.ReadFloat32(); Field30 = new FloatPath(); Field30.Parse(buffer); Field31 = new FloatPath(); Field31.Parse(buffer); Field32 = new FloatPath(); Field32.Parse(buffer); Field33 = new FloatPath(); Field33.Parse(buffer); Field34 = new FloatPath(); Field34.Parse(buffer); serMsgTriggeredEvents = new SerializeData(); serMsgTriggeredEvents.Parse(buffer); Field36 = buffer.ReadInt(32); Field37 = new DT_VARIABLEARRAY(); Field37.Parse(buffer); }