public void ThreeItemPolygonCountTest() { var storage = new VertexStorage(); // Square storage.MoveTo(0, 0); storage.LineTo(100, 0); storage.LineTo(100, 100); storage.LineTo(0, 100); storage.ClosePolygon(); // Triangle storage.MoveTo(30, 30); storage.LineTo(40, 30); storage.LineTo(35, 40); storage.ClosePolygon(); // Small Square storage.MoveTo(20, 20); storage.LineTo(25, 20); storage.LineTo(25, 25); storage.LineTo(20, 25); storage.ClosePolygon(); var polygons = storage.CreatePolygons(); //var image = new ImageBuffer(200, 200); //var graphics = image.NewGraphics2D(); //graphics.Render(new Stroke(storage), Color.Blue); //ImageTgaIO.Save(image, @"c:\temp\some.tga"); Assert.AreEqual(3, polygons.Count, "Three polygons should be create for a two squares and a triangle"); }
public void CreateGrid(Affine transform) { Vector2 gridOffset = gridCenterMm - gridSizeMm / 2; if (gridSizeMm.X > 0 && gridSizeMm.Y > 0) { grid.remove_all(); for (int y = 0; y <= gridSizeMm.Y; y += 10) { Vector2 start = new Vector2(0, y) + gridOffset; Vector2 end = new Vector2(gridSizeMm.X, y) + gridOffset; transform.transform(ref start); transform.transform(ref end); grid.MoveTo((int)(start.X + .5), (int)(start.Y + .5) + .5); grid.LineTo((int)(int)(end.X + .5), (int)(end.Y + .5) + .5); } for (int x = 0; x <= gridSizeMm.X; x += 10) { Vector2 start = new Vector2(x, 0) + gridOffset; Vector2 end = new Vector2(x, gridSizeMm.Y) + gridOffset; transform.transform(ref start); transform.transform(ref end); grid.MoveTo((int)(start.X + .5) + .5, (int)(start.Y + .5)); grid.LineTo((int)(end.X + .5) + .5, (int)(end.Y + .5)); } } }
public void Curve3(float xControl, float yControl, float x, float y) { if (polygonStartIndex == vertexStorage.Count) { // we have not started the polygon so there is no point to curve3 from // store this control point and add it at the end of the polygon curve3Control = new Vector2(xControl, yControl); // then move to the end of this curve vertexStorage.MoveTo(x, y); } else { vertexStorage.curve3(xControl, yControl, x, y); } }
public override void OnDraw(Graphics2D graphics2D) { targetBounds = this.GetTargetBounds(productTour.ActiveItem.Widget); var dimRegion = new VertexStorage(); dimRegion.MoveTo(LocalBounds.Left, LocalBounds.Bottom); dimRegion.LineTo(LocalBounds.Right, LocalBounds.Bottom); dimRegion.LineTo(LocalBounds.Right, LocalBounds.Top); dimRegion.LineTo(LocalBounds.Left, LocalBounds.Top); var targetRect = new VertexStorage(); targetRect.MoveTo(targetBounds.Right, targetBounds.Bottom); targetRect.LineTo(targetBounds.Left, targetBounds.Bottom); targetRect.LineTo(targetBounds.Left, targetBounds.Top); targetRect.LineTo(targetBounds.Right, targetBounds.Top); var overlayMinusTargetRect = new CombinePaths(dimRegion, targetRect); graphics2D.Render(overlayMinusTargetRect, new Color(Color.Black, 180)); base.OnDraw(graphics2D); graphics2D.Render(new Stroke(new RoundedRect(targetBounds, 0), 2), Color.White.WithAlpha(50)); //graphics2D.Render(new Stroke(new RoundedRect(GetContentBounds(), 3), 4), theme.PrimaryAccentColor); }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); bool changed = false; using (RebuildLock()) { Sides = agg_basics.Clamp(Sides, 3, 360, ref changed); var aabb = this.GetAxisAlignedBoundingBox(); var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(Diameter / 2, 0); path.LineTo(0, Height); Mesh = VertexSourceToMesh.Revolve(path, Sides); if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); if (changed) { base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties)); } }
public static void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, Matrix4X4 matrix, Vector2 offset, double scale, Color silhouetteColor) { graphics2D.Rasterizer.gamma(new gamma_power(.3)); VertexStorage polygonProjected = new VertexStorage(); foreach (Face face in meshToDraw.Faces) { if (Vector3.TransformNormal(face.Normal, matrix).Z > 0) { polygonProjected.remove_all(); bool first = true; foreach (FaceEdge faceEdge in face.FaceEdges()) { var position3D = Vector3.Transform(faceEdge.FirstVertex.Position, matrix); Vector2 position = new Vector2(position3D.X, position3D.Y); position += offset; position *= scale; if (first) { polygonProjected.MoveTo(position.X, position.Y); first = false; } else { polygonProjected.LineTo(position.X, position.Y); } } graphics2D.Render(polygonProjected, silhouetteColor); } } graphics2D.Rasterizer.gamma(new gamma_none()); }
private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, double dotRadius, int numSnapPoints, int markToSnapTo) { var graphics2DOpenGL = new Graphics2DOpenGL(); double snappingRadians = MathHelper.Tau / numSnapPoints; var clippingFrustum = GLHelper.GetClippingFrustum(InteractionContext.World); for (int i = 0; i < numSnapPoints; i++) { double startAngle = i * snappingRadians + mouseAngle; VertexStorage snapShape = new VertexStorage(); snapShape.MoveTo(-10, 0); snapShape.LineTo(5, 7); snapShape.LineTo(5, -7); snapShape.ClosePolygon(); var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle)); // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius); var color = Color.Black; if (i == markToSnapTo) { color = Color.Red; } graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered); } }
public static void DrawMeasureLine(Graphics2D graphics2D, Vector2 lineStart, Vector2 lineEnd, Color color, LineArrows arrows) { graphics2D.Line(lineStart, lineEnd, Color.Black); Vector2 direction = lineEnd - lineStart; if (direction.LengthSquared > 0 && (arrows.HasFlag(LineArrows.Start) || arrows.HasFlag(LineArrows.End))) { VertexStorage arrow = new VertexStorage(); arrow.MoveTo(-3, -5); arrow.LineTo(0, 0); arrow.LineTo(3, -5); if (arrows.HasFlag(LineArrows.End)) { double rotation = Math.Atan2(direction.Y, direction.X); IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4)); IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineEnd)); graphics2D.Render(inPosition, Color.Black); } if (arrows.HasFlag(LineArrows.Start)) { double rotation = Math.Atan2(direction.Y, direction.X) + MathHelper.Tau / 2; IVertexSource correctRotation = new VertexSourceApplyTransform(arrow, Affine.NewRotation(rotation - MathHelper.Tau / 4)); IVertexSource inPosition = new VertexSourceApplyTransform(correctRotation, Affine.NewTranslation(lineStart)); graphics2D.Render(inPosition, Color.Black); } } }
public override Task Rebuild() { this.DebugDepth("Rebuild"); bool valuesChanged = false; using (RebuildLock()) { InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref valuesChanged); Sides = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged); RingSides = agg_basics.Clamp(RingSides, 3, 360, ref valuesChanged); StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged); EndingAngle = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged); var ringSides = RingSides; var startingAngle = StartingAngle; var endingAngle = EndingAngle; var ringPhaseAngle = RingPhaseAngle; if (!Advanced) { ringSides = Math.Max(3, (int)(Sides / 2)); startingAngle = 0; endingAngle = 360; ringPhaseAngle = 0; } var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter); using (new CenterAndHeightMaintainer(this)) { var poleRadius = (OuterDiameter / 2 - innerDiameter / 2) / 2; var toroidRadius = innerDiameter / 2 + poleRadius; var path = new VertexStorage(); var angleDelta = MathHelper.Tau / ringSides; var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle); var ringAngle = ringStartAngle; var circleCenter = new Vector2(toroidRadius, 0); path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle))); for (int i = 0; i < ringSides - 1; i++) { ringAngle += angleDelta; path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle))); } path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle))); var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle)); var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle)); Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle); } } if (valuesChanged) { Invalidate(InvalidateType.DisplayValues); } Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); return(Task.CompletedTask); }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); using (RebuildLock()) { var aabb = this.GetAxisAlignedBoundingBox(); var radius = Diameter / 2; var angleDelta = MathHelper.Tau / 4 / LatitudeSides; var angle = 0.0; var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); for (int i = 0; i < LatitudeSides; i++) { angle += angleDelta; path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); } Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides); if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); }
public void JsonSerializeVertexStorage() { var test1Control = new VertexStorage(); test1Control.MoveTo(10, 11); test1Control.LineTo(100, 11); test1Control.LineTo(100, 110); test1Control.ClosePolygon(); string jsonData = JsonConvert.SerializeObject(test1Control); var test1Result = JsonConvert.DeserializeObject <VertexStorage>(jsonData); Assert.AreEqual(test1Control.Count, test1Result.Count); var control = test1Control.Vertices().GetEnumerator(); var result = test1Result.Vertices().GetEnumerator(); for (int i = 0; i < test1Control.Count; i++) { control.MoveNext(); result.MoveNext(); var controlVertex = control.Current; var resultVertex = result.Current; Assert.AreEqual(controlVertex.command, resultVertex.command); Assert.AreEqual(controlVertex.position, resultVertex.position); } }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); using (RebuildLock()) { var aabb = this.GetAxisAlignedBoundingBox(); var path = new VertexStorage(); path.MoveTo(Width / 2, 0); for (int i = 1; i < Sides; i++) { var angle = MathHelper.Tau * i / 2 / (Sides - 1); path.LineTo(Math.Cos(angle) * Width / 2, Math.Sin(angle) * Width / 2); } var mesh = VertexSourceToMesh.Extrude(path, Depth); mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4)); Mesh = mesh; if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); bool changed = false; using (RebuildLock()) { InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref changed); Sides = agg_basics.Clamp(Sides, 3, 360, ref changed); RingSides = agg_basics.Clamp(RingSides, 3, 360, ref changed); var ringSides = RingSides; var startingAngle = StartingAngle; var endingAngle = EndingAngle; var ringPhaseAngle = RingPhaseAngle; if (!Advanced) { ringSides = Math.Max(3, (int)(Sides / 2)); startingAngle = 0; endingAngle = 360; ringPhaseAngle = 0; } var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter); var aabb = this.GetAxisAlignedBoundingBox(); var poleRadius = (OuterDiameter / 2 - innerDiameter / 2) / 2; var toroidRadius = innerDiameter / 2 + poleRadius; var path = new VertexStorage(); var angleDelta = MathHelper.Tau / ringSides; var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle); var ringAngle = ringStartAngle; var circleCenter = new Vector2(toroidRadius, 0); path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle))); for (int i = 0; i < ringSides - 1; i++) { ringAngle += angleDelta; path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle))); } path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle))); var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle)); var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle)); Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle); if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); if (changed) { base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties)); } }
public void MoveToCreatesAdditionalPolygonTest() { // Any MoveTo should always create a new Polygon var storage = new VertexStorage(); storage.MoveTo(0, 0); storage.LineTo(100, 0); storage.LineTo(100, 100); storage.MoveTo(30, 30); storage.LineTo(0, 100); storage.ClosePolygon(); var polygons = storage.CreatePolygons(); Assert.AreEqual(2, polygons.Count, "Two polygons should be created for a path with a floating MoveTo command"); }
public override Task Rebuild() { this.DebugDepth("Rebuild"); bool valuesChanged = false; using (RebuildLock()) { var sides = Sides.ClampIfNotCalculated(this, 3, 180, ref valuesChanged); using (new CenterAndHeightMaintainer(this)) { var path = new VertexStorage(); path.MoveTo(Width.Value(this) / 2, 0); for (int i = 1; i < sides; i++) { var angle = MathHelper.Tau * i / 2 / (sides - 1); path.LineTo(Math.Cos(angle) * Width.Value(this) / 2, Math.Sin(angle) * Width.Value(this) / 2); } var mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this)); mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4)); Mesh = mesh; } } Invalidate(InvalidateType.DisplayValues); Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); return(Task.CompletedTask); }
protected IObject3D CreateReach(double reach, double innerDiameter) { var finWidth = 4.0; var finLength = innerDiameter; var pattern = new VertexStorage(); pattern.MoveTo(0, 0); pattern.LineTo(finLength / 2, 0); pattern.LineTo(finLength / 2, reach - finLength / 8); pattern.LineTo(finLength / 2 - finLength / 8, reach); pattern.LineTo(-finLength / 2 + finLength / 8, reach); pattern.LineTo(-finLength / 2, reach - finLength / 8); pattern.LineTo(-finLength / 2, 0); var fin1 = new Object3D() { Mesh = VertexSourceToMesh.Extrude(pattern, finWidth) }; fin1 = new TranslateObject3D(fin1, 0, 0, -finWidth / 2); //fin1.ChamferEdge(Face.Top | Face.Back, finLength / 8); //fin1.ChamferEdge(Face.Top | Face.Front, finLength / 8); fin1 = new RotateObject3D(fin1, -MathHelper.Tau / 4); var fin2 = new SetCenterObject3D(new RotateObject3D(fin1, 0, 0, MathHelper.Tau / 4), fin1.GetCenter()); return(new Object3D().SetChildren(new List <IObject3D>() { fin1, fin2 })); }
private void DrawSnappingMarks(DrawGlContentEventArgs drawEventArgs, double mouseAngle, double alphaValue, Matrix4X4 rotationCenterTransform, double distanceFromCenter, int numSnapPoints, int markToSnapTo) { var graphics2DOpenGL = new Graphics2DOpenGL(GuiWidget.DeviceScale); double snappingRadians = MathHelper.Tau / numSnapPoints; for (int i = 0; i < numSnapPoints; i++) { double startAngle = i * snappingRadians + mouseAngle; var snapShape = new VertexStorage(); var scale = GuiWidget.DeviceScale; snapShape.MoveTo(-10 * scale, 0); snapShape.LineTo(5 * scale, 7 * scale); snapShape.LineTo(5 * scale, -7 * scale); snapShape.ClosePolygon(); var transformed = new VertexSourceApplyTransform(snapShape, Affine.NewTranslation(distanceFromCenter, 0) * Affine.NewRotation(startAngle)); // new Ellipse(startPosition.x, startPosition.y, dotRadius, dotRadius); var color = theme.TextColor; if (i == markToSnapTo) { color = theme.PrimaryAccentColor; } graphics2DOpenGL.RenderTransformedPath(rotationCenterTransform, transformed, new Color(color, (int)(254 * alphaValue)), drawEventArgs.ZBuffered); } }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); using (RebuildLock()) { var aabb = this.GetAxisAlignedBoundingBox(); var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(Math.Sqrt(2), 0); path.LineTo(0, Height); var mesh = VertexSourceToMesh.Revolve(path, 4); mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1)); Mesh = mesh; if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); }
public void BuildHistogramFromImage(ImageBuffer image, ImageToPathObject3D_2.AnalysisTypes analysisType) { // build the histogram cache var height = (int)(100 * GuiWidget.DeviceScale); _histogramRawCache = new ImageBuffer(256, height); var counts = new int[_histogramRawCache.Width]; IThresholdFunction function = new MapOnMaxIntensity(0, 1); var bottom = 0; if (analysisType == ImageToPathObject3D_2.AnalysisTypes.Colors) { function = new QuickHue(); bottom = (int)(10 * GuiWidget.DeviceScale); } byte[] buffer = image.GetBuffer(); for (int y = 0; y < image.Height; y++) { int imageBufferOffset = image.GetBufferOffsetY(y); for (int x = 0; x < image.Width; x++) { int imageBufferOffsetWithX = imageBufferOffset + x * 4; var color = GetRGBA(buffer, imageBufferOffsetWithX); counts[(int)(function.Transform(color) * (_histogramRawCache.Width - 1))]++; } } double max = counts.Select((value, index) => new { value, index }) .OrderByDescending(vi => vi.value) .First().value; var graphics = _histogramRawCache.NewGraphics2D(); var theme = ApplicationController.Instance.Theme; graphics.Clear(theme.SlightShade); var graphShape = new VertexStorage(); var graphHeight = height - bottom; graphShape.MoveTo(0, bottom); for (int i = 0; i < 256; i++) { graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight); // graphShape.LineTo(i, bottom + Easing.Cubic.Out(counts[i] / max) * graphHeight); // graphShape.LineTo(i, bottom + Easing.Exponential.Out(counts[i] / max) * graphHeight); // graphShape.LineTo(i, bottom + counts[i] / max * graphHeight); } graphShape.LineTo(256, bottom); graphShape.LineTo(0, bottom); graphics.Render(graphShape, 0, 0, theme.TextColor); for (int i = 0; i < 256; i++) { var hue = ColorF.FromHSL(i / 255.0, 1, .49).ToColor(); graphics.Line(i, 0, i, bottom, hue); } }
static public int parse_lion(VertexStorage path, Color[] colors, int[] path_idx) { // Parse the lion and then detect its bounding // box and arrange polygons orientations (make all polygons // oriented clockwise or counterclockwise) int npaths = 0; string[] splitOnNL = g_lion.Split('\n'); foreach (string LineString in splitOnNL) { int c; if (LineString.Length > 0 && LineString[0] != 'M' && Int32.TryParse(LineString, NumberStyles.HexNumber, null, out c)) { // New color. Every new color creates new path in the path object. path.ClosePolygon(); colors[npaths] = Color.rgb8_packed((int)c); path_idx[npaths] = path.start_new_path(); npaths++; } else { bool startedPoly = false; string[] splitOnSpace = LineString.Split(' '); for (int i = 0; i < splitOnSpace.Length; i++) { string[] splitOnComma = splitOnSpace[i].Split(','); if (splitOnComma.Length > 1) { double x = 0.0; double y = 0.0; double.TryParse(splitOnComma[0], NumberStyles.Number, null, out x); double.TryParse(splitOnComma[1], NumberStyles.Number, null, out y); if (!startedPoly) { startedPoly = true; path.ClosePolygon(); path.MoveTo(x, y); } else { path.LineTo(x, y); } } } } } path.arrange_orientations_all_paths(ShapePath.FlagsAndCommand.FlagCW); return(npaths); }
// TODO: EditorTools owns this, move to more general location private static Mesh CreateCylinder(double height = 20, double radius = 10, int rotationCount = 30) { var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(radius, 0); path.LineTo(radius, height); path.LineTo(0, height); return(VertexSourceToMesh.Revolve(path, rotationCount)); }
private void Rebuild(UndoBuffer undoBuffer) { this.DebugDepth("Rebuild"); bool changed = false; using (RebuildLock()) { Sides = agg_basics.Clamp(Sides, 3, 360, ref changed); LatitudeSides = agg_basics.Clamp(LatitudeSides, 3, 360, ref changed); var aabb = this.GetAxisAlignedBoundingBox(); var startingAngle = StartingAngle; var endingAngle = EndingAngle; var latitudeSides = LatitudeSides; if (!Advanced) { startingAngle = 0; endingAngle = 360; latitudeSides = Sides; } var path = new VertexStorage(); var angleDelta = MathHelper.Tau / 2 / latitudeSides; var angle = -MathHelper.Tau / 4; var radius = Diameter / 2; path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); for (int i = 0; i < latitudeSides; i++) { angle += angleDelta; path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); } var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle)); var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle)); var steps = Math.Max(1, (int)(Sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5)); Mesh = VertexSourceToMesh.Revolve(path, steps, startAngle, endAngle); if (aabb.ZSize > 0) { // If the part was already created and at a height, maintain the height. PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z); } } Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); if (changed) { base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties)); } }
public virtual void Line(double x1, double y1, double x2, double y2, Color color, double strokeWidth = 1) { var lineToDraw = new VertexStorage(); lineToDraw.remove_all(); lineToDraw.MoveTo(x1, y1); lineToDraw.LineTo(x2, y2); this.Render( new Stroke(lineToDraw, strokeWidth), color); }
public void DrawSegments(Graphics2D graphics2D) { foreach (LineSegmentFloat lineSegment in LineSegments) { VertexStorage m_LinesToDraw = new VertexStorage(); m_LinesToDraw.remove_all(); m_LinesToDraw.MoveTo(lineSegment.start.X, lineSegment.start.Y); m_LinesToDraw.LineTo(lineSegment.end.X, lineSegment.end.Y); Stroke StrockedLineToDraw = new Stroke(m_LinesToDraw, .25); graphics2D.Render(StrockedLineToDraw, Color.Black); } }
static DropArrow() { DownArrow = new VertexStorage(); DownArrow.MoveTo(-ArrowHeight, 0); DownArrow.LineTo(ArrowHeight, 0); DownArrow.LineTo(0, -ArrowHeight); UpArrow = new VertexStorage(); UpArrow.MoveTo(-ArrowHeight, -ArrowHeight); UpArrow.LineTo(ArrowHeight, -ArrowHeight); UpArrow.LineTo(0, 0); }
private void make_arrows(VertexStorage ps) { ps.remove_all(); ps.MoveTo(1330.599999999999909, 1282.399999999999864); ps.LineTo(1377.400000000000091, 1282.399999999999864); ps.LineTo(1361.799999999999955, 1298.000000000000000); ps.LineTo(1393.000000000000000, 1313.599999999999909); ps.LineTo(1361.799999999999955, 1344.799999999999955); ps.LineTo(1346.200000000000045, 1313.599999999999909); ps.LineTo(1330.599999999999909, 1329.200000000000045); ps.ClosePolygon(); ps.MoveTo(1330.599999999999909, 1266.799999999999955); ps.LineTo(1377.400000000000091, 1266.799999999999955); ps.LineTo(1361.799999999999955, 1251.200000000000045); ps.LineTo(1393.000000000000000, 1235.599999999999909); ps.LineTo(1361.799999999999955, 1204.399999999999864); ps.LineTo(1346.200000000000045, 1235.599999999999909); ps.LineTo(1330.599999999999909, 1220.000000000000000); ps.ClosePolygon(); ps.MoveTo(1315.000000000000000, 1282.399999999999864); ps.LineTo(1315.000000000000000, 1329.200000000000045); ps.LineTo(1299.400000000000091, 1313.599999999999909); ps.LineTo(1283.799999999999955, 1344.799999999999955); ps.LineTo(1252.599999999999909, 1313.599999999999909); ps.LineTo(1283.799999999999955, 1298.000000000000000); ps.LineTo(1268.200000000000045, 1282.399999999999864); ps.ClosePolygon(); ps.MoveTo(1268.200000000000045, 1266.799999999999955); ps.LineTo(1315.000000000000000, 1266.799999999999955); ps.LineTo(1315.000000000000000, 1220.000000000000000); ps.LineTo(1299.400000000000091, 1235.599999999999909); ps.LineTo(1283.799999999999955, 1204.399999999999864); ps.LineTo(1252.599999999999909, 1235.599999999999909); ps.LineTo(1283.799999999999955, 1251.200000000000045); ps.ClosePolygon(); }
public override Task Rebuild() { this.DebugDepth("Rebuild"); bool valuesChanged = false; var roundSegments = RoundSegments.ClampIfNotCalculated(this, 2, 90, ref valuesChanged); Invalidate(InvalidateType.DisplayValues); using (RebuildLock()) { var height = Height.Value(this); var width = Width.Value(this); using (new CenterAndHeightMaintainer(this)) { var path = new VertexStorage(); path.MoveTo(0, 0); path.LineTo(width, 0); var range = 360 / 4.0; switch (Round) { case RoundTypes.Up: for (int i = 1; i < roundSegments - 1; i++) { var angle = range / (roundSegments - 1) * i; var rad = MathHelper.DegreesToRadians(angle); path.LineTo(Math.Cos(rad) * width, Math.Sin(rad) * height); } break; case RoundTypes.Down: for (int i = 1; i < roundSegments - 1; i++) { var angle = range / (roundSegments - 1) * i; var rad = MathHelper.DegreesToRadians(angle); path.LineTo(width - Math.Sin(rad) * width, height - Math.Cos(rad) * height); } break; } path.LineTo(0, height); Mesh = VertexSourceToMesh.Extrude(path, Depth.Value(this)); Mesh.Transform(Matrix4X4.CreateRotationX(MathHelper.Tau / 4)); } } Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); return(Task.CompletedTask); }
public override Task Rebuild() { this.DebugDepth("Rebuild"); bool valuesChanged = false; using (RebuildLock()) { Sides = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged); LatitudeSides = agg_basics.Clamp(LatitudeSides, 3, 360, ref valuesChanged); using (new CenterAndHeightMaintainer(this)) { var startingAngle = StartingAngle; var endingAngle = EndingAngle; var latitudeSides = LatitudeSides; if (!Advanced) { startingAngle = 0; endingAngle = 360; latitudeSides = Sides; } var path = new VertexStorage(); var angleDelta = MathHelper.Tau / 2 / latitudeSides; var angle = -MathHelper.Tau / 4; var radius = Diameter / 2; path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); for (int i = 0; i < latitudeSides; i++) { angle += angleDelta; path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle))); } var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle)); var endAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle)); var steps = Math.Max(1, (int)(Sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5)); Mesh = VertexSourceToMesh.Revolve(path, steps, startAngle, endAngle); } } if (valuesChanged) { Invalidate(InvalidateType.DisplayValues); } Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh)); return(Task.CompletedTask); }
public void Rebuild() { var path = new VertexStorage(); path.MoveTo(Radius, 0); for (int i = 1; i < 6; i++) { var angle = MathHelper.Tau / 6 * i; var next = new Vector2(Math.Cos(angle), Math.Sin(angle)) * Radius; path.LineTo(next); } Path = new Stroke(path, StrokeWidth); }
public void CubePolygonCountTest() { var square = new VertexStorage(); square.MoveTo(0, 0); square.LineTo(100, 0); square.LineTo(100, 100); square.LineTo(0, 100); square.ClosePolygon(); var polygons = square.CreatePolygons(); Assert.AreEqual(1, polygons.Count, "One polygon should be created for a simple 4 point cube path"); }