public static Sink Isink(Trapezoid trapezoid) { if (trapezoid.Sink == null) return new Sink(trapezoid); return trapezoid.Sink; }
public TrapezoidalNode(Trapezoid trapezoid) { IsTrapezoid = true; Trapezoid = trapezoid; LeftChildren = null; RightChildren = null; }
public void TestScaleTrapezoid100Percent() { Trapezoid trapezoid = new Trapezoid(20, 15, 10); trapezoid.Scale(100); Assert.AreEqual(20, trapezoid.LongBase); Assert.AreEqual(15, trapezoid.ShortBase); Assert.AreEqual(10, trapezoid.Height); Assert.AreEqual((decimal)75.96, trapezoid.AcuteAngle); Assert.AreEqual((decimal)104.04, trapezoid.ObtuseAngle); }
public static Trapezoid operator +(Trapezoid c1, Trapezoid c2) { int [] temp = new int [8]; for (int i = 0; i < 8; i++) { temp[i] = coord[i] + c1[i]; } Trapezoid t = new Trapezoid(temp); return(t); }
public void TrapezoidCalculateSurfaceArea() { // Arrange Trapezoid trapezoid = new Trapezoid(TrapezoidSide1, TrapezoidSide2, TrapezoidHeight); // Act double surfaceArea = trapezoid.CalculateSurfaceArea(); // Assert Assert.AreEqual(TrapezoidSurfaceArea, surfaceArea); }
public void TrapezoidCalculateSurfaceArea() { // Arrange var trapezoid = new Trapezoid(TrapezoidHeight, TrapezoidUpperWidth, TrapezoidLowerWidth); // Act var surfaceArea = trapezoid.CalculateSurfaceArea(); // Assert Assert.AreEqual(TrapezoidSurfaceArea, surfaceArea); }
/* * Given an Voronoi diagram in DCEL format: * Extract all edges and map them to LineSegments * Store with each segment the shepherd above it * Incrementally add each segment to the vertical decomposition */ public VerticalDecomposition(DCEL InGraph, MeshFilter m_meshFilter) { // *** Initialize vertical decomposition with one trapezoid containing the entire canvas *** // Determine bounding box corners float width = 10000; float height = 10000; LineSegment bottom = new LineSegment(new Vector2(-width, -height), new Vector2(width, -height), null); LineSegment top = new LineSegment(new Vector2(-width, height), new Vector2(width, height), null); // Create initial trapezoid and root of searchtree Trapezoid inital_trapezoid = new Trapezoid(new Vector2(-width, height), new Vector2(width, -height), top, bottom); traps.Add(inital_trapezoid); this.TreeRoot = new SearchNode(inital_trapezoid); inital_trapezoid.SetLeaf(TreeRoot); // *** Add all edges to the vertical decomposition *** // Randomize the collection of half-edges ICollection <HalfEdge> c_edges = InGraph.Edges; List <HalfEdge> temp_edges = new List <HalfEdge>(); List <HalfEdge> edges = new List <HalfEdge>(); foreach (HalfEdge edge in c_edges) { temp_edges.Add(edge); } for (int i = 0; i < c_edges.Count; i++) { int randomIndex = Random.Range(0, temp_edges.Count); //Choose a random object in the list edges.Add(temp_edges[randomIndex]); //add it to the new, random list temp_edges.RemoveAt(randomIndex); //remove to avoid duplicates } Debug.Log("Adding voronoi with " + edges.Count + " halfedges"); // Transform all DCEL edges into Linesegments foreach (HalfEdge edge in edges) { // Only add half-edges whose face is above it // So only add half-edges whose to-vertex is to the right of the from-vertex // So skip half-edges where 'to' has smaller x value than 'from' if (edge.To.Pos.x > edge.From.Pos.x) { continue; } if (edge.To.Pos.x == edge.From.Pos.x && edge.To.Pos.y <= edge.From.Pos.y) { continue; } LineSegment segment = new LineSegment(edge.From.Pos, edge.To.Pos, edge.Face); Debug.Log("Inserting segment: " + segment.show()); this.Insert(segment); } }
public void TrapezoidMeasurement() { var trapezoid = new Trapezoid(); trapezoid.Height = 3; trapezoid.ShortBase = 2; trapezoid.Leg1 = 2; trapezoid.Leg2 = 2; trapezoid.LongBase = 4; Assert.AreEqual(trapezoid.Perimeter, 10.0); Assert.AreEqual(trapezoid.GetArea(), 9.0); }
public bool Equals(Trapezoid t) { //Check for null and compare run-time types. if ((t == null) || !this.GetType().Equals(t.GetType())) { return(false); } else { return((top == t.top) && (bottom == t.bottom) && (left == t.left) && (right == t.right)); } }
public void TrapezoidTest() { var trapezoid = new Trapezoid(5, 6, 7); Assert.AreEqual(5, trapezoid.BaseOne); Assert.AreEqual(6, trapezoid.BaseTwo); Assert.AreEqual(7, trapezoid.Height); Assert.AreEqual(38.5, trapezoid.Area); var trapezoid2 = new Trapezoid(5, 6, 7); Assert.AreEqual(trapezoid, trapezoid2); }
public Triangulator(List <Point> polyLine, float sheer) { _sheer = sheer; Triangles = new List <List <Point> >(); Trapezoids = new List <Trapezoid>(); _xMonoPoly = new List <MonotoneMountain>(); _edgeList = InitEdges(polyLine); _trapezoidalMap = new TrapezoidalMap(); _boundingBox = _trapezoidalMap.BoundingBox(_edgeList); _queryGraph = new QueryGraph(Sink.Isink(_boundingBox)); Process(); }
public void CalculatesTrapezoidArea() { var expectedArea = 4.5; var trapezoid = new Trapezoid(); trapezoid.base1 = 1; trapezoid.base2 = 2; trapezoid.height = 3; var actualArea = trapezoid.CalculateArea(); Assert.AreEqual(expectedArea, actualArea); }
public void CalculatesTrapezoidPerimeter() { var expectedPerimeter = 18; var trapezoid = new Trapezoid(); trapezoid.base1 = 1.2; trapezoid.base2 = 3.4; trapezoid.leg1 = 5.6; trapezoid.leg2 = 7.8; var actualPerimeter = trapezoid.CalculatePerimiter(); Assert.AreEqual(expectedPerimeter, actualPerimeter); }
// Case 1: segment completely enclosed by trapezoid // break trapezoid into 4 smaller trapezoids public Trapezoid[] Case1(Trapezoid t, Edge e) { Trapezoid[] trapezoids = new Trapezoid[4]; trapezoids[0] = new Trapezoid(t.LeftPoint, e.P, t.Top, t.Bottom); trapezoids[1] = new Trapezoid(e.P, e.Q, t.Top, e); trapezoids[2] = new Trapezoid(e.P, e.Q, e, t.Bottom); trapezoids[3] = new Trapezoid(e.Q, t.RightPoint, t.Top, t.Bottom); trapezoids[0].UpdateLeft(t.UpperLeft, t.LowerLeft); trapezoids[1].UpdateLeftRight(trapezoids[0], null, trapezoids[3], null); trapezoids[2].UpdateLeftRight(null, trapezoids[0], null, trapezoids[3]); trapezoids[3].UpdateRight(t.UpperRight, t.LowerRight); return(trapezoids); }
public static void Initialization_with_Dimensions_Creates_Shape() { Trapezoid trapezoid = new Trapezoid(height, topWidth, bottomWidth, skew); Assert.AreEqual(4, trapezoid.Points.Count); Assert.AreEqual(4, trapezoid.Angles.Count); Assert.AreEqual(4, trapezoid.Sides.Count); Assert.AreEqual(GeometryLibrary.ZeroTolerance, trapezoid.Tolerance); Assert.AreEqual(6.96969697, trapezoid.Centroid.X, Tolerance); Assert.AreEqual(2.424242424, trapezoid.Centroid.Y, Tolerance); Assert.AreEqual(skew, trapezoid.g); Assert.AreEqual(height, trapezoid.h); Assert.AreEqual(topWidth, trapezoid.b_t); Assert.AreEqual(bottomWidth, trapezoid.b_b); }
private static List <EdgeAggregator> InstantiateFromIsoscelesTrapezoid(Trapezoid trapezoid, GroundedClause original) { List <EdgeAggregator> newGrounded = new List <EdgeAggregator>(); // Create the congruent, oppsing side segments GeometricCongruentSegments gcs = new GeometricCongruentSegments(trapezoid.leftLeg, trapezoid.rightLeg); // For hypergraph List <GroundedClause> antecedent = new List <GroundedClause>(); antecedent.Add(original); newGrounded.Add(new EdgeAggregator(antecedent, gcs, annotation)); return(newGrounded); }
/// <summary> /// Return a tree that contains 2 trapezoids /// </summary> /// <param name="segment"></param> /// <returns></returns> public Node To2Traps(Segment segment) { // Segment node Node root = new SegmentNode(segment); // Trapezoid nodes Trapezoid higherTrap = new Trapezoid(null, null, Trapezoid.Top, segment); Trapezoid lowerTrap = new Trapezoid(null, null, segment, Trapezoid.Bottom); Node higherTrapNode = new TrapezoidalNode(higherTrap); Node lowerTrapNode = new TrapezoidalNode(lowerTrap); root.SetChildren(ref higherTrapNode, ref lowerTrapNode); return(root); }
/// <summary> /// Return a tree that contains 2 trapezoids /// </summary> /// <param name="segment"></param> /// <returns></returns> public Node To2Traps(Segment segment) { // Segment node Node root = new SegmentNode(segment); // Trapezoid nodes Trapezoid higherTrap = new Trapezoid(null, null, Trapezoid.Top, segment); Trapezoid lowerTrap = new Trapezoid(null, null, segment, Trapezoid.Bottom); Node higherTrapNode = new TrapezoidalNode(higherTrap); Node lowerTrapNode = new TrapezoidalNode(lowerTrap); root.SetChildren(ref higherTrapNode, ref lowerTrapNode); return root; }
private Shape CreateShape(MyPoint point) { Shape shape = null; if (createFigure.CBCreateFigure.SelectedItem.Equals("Circle")) { int radius = int.Parse(createFigure.textBox1.Text); shape = new Circle(point, radius); } else if (createFigure.CBCreateFigure.SelectedItem.Equals("Rectangle")) { int lenght = int.Parse(createFigure.textBox1.Text); int width = int.Parse(createFigure.textBox2.Text); shape = new Shapes.Rectangle(point, lenght, width); } else if (createFigure.CBCreateFigure.SelectedItem.Equals("Triangle")) { int sideone = int.Parse(createFigure.textBox1.Text); int sidetwo = int.Parse(createFigure.textBox2.Text); int sidethree = int.Parse(createFigure.textBox3.Text); shape = new Triangle(point, sideone, sidetwo, sidethree); } else if (createFigure.CBCreateFigure.SelectedItem.Equals("Square")) { int side = int.Parse(createFigure.textBox1.Text); shape = new Square(point, side); } else if (createFigure.CBCreateFigure.SelectedItem.Equals("Trapezoid")) { int sideone = int.Parse(createFigure.textBox1.Text); int sidetwo = int.Parse(createFigure.textBox2.Text); int sidethree = int.Parse(createFigure.textBox3.Text); int sidefour = int.Parse(createFigure.textBox4.Text); shape = new Trapezoid(point, sideone, sidetwo, sidethree, sidefour); } else { throw new Exception("First select settings!"); } return(shape); }
public static void LocalCoordinates_Returns_Coordinates_of_Vertices_in_Original_Local_Coordinates() { Trapezoid trapezoid = new Trapezoid(height, topWidth, bottomWidth, skew); IList <CartesianCoordinate> coordinates = trapezoid.LocalCoordinates(); Assert.AreEqual(0, coordinates[0].X); Assert.AreEqual(0, coordinates[0].Y); Assert.AreEqual(bottomWidth, coordinates[1].X); Assert.AreEqual(0, coordinates[1].Y); Assert.AreEqual(skew + topWidth, coordinates[2].X); Assert.AreEqual(height, coordinates[2].Y); Assert.AreEqual(skew, coordinates[3].X); Assert.AreEqual(height, coordinates[3].Y); }
private static List <EdgeAggregator> InstantiateFromTrapezoid(Trapezoid trapezoid, GroundedClause original) { List <EdgeAggregator> newGrounded = new List <EdgeAggregator>(); // // Determine the parallel opposing sides and output that. // GeometricParallel newParallel = new GeometricParallel(trapezoid.baseSegment, trapezoid.oppBaseSegment); // For hypergraph List <GroundedClause> antecedent = new List <GroundedClause>(); antecedent.Add(original); newGrounded.Add(new EdgeAggregator(antecedent, newParallel, annotation)); return(newGrounded); }
static void Main() { bool exit = false; Trapezoid trapezoid = null; while (!exit) { DisplayMainMenu(); string input = Console.ReadLine().ToLower(); switch (input) { case "1": GetUserTrapezoidSides(out double a, out double b, out double c, out double d, out double h); if (IsValidTrapezoid(a, b, c, d, h)) { Console.WriteLine("Trapezoid can exist."); trapezoid = new Trapezoid(a, b, c, d, h); } else { Console.WriteLine("Trapezoid with stated values cannot exist."); trapezoid = null; } break; case "2": if (trapezoid != null) { DisplayTrapezoidValues(trapezoid); } else { Console.WriteLine("Trapezoid has not been stored."); } break; case "q": exit = true; break; } } }
Trapezoid CreateBoundingTrapezoid() { // Find min/max coordinates float minY = -Camera.main.orthographicSize; float maxY = Camera.main.orthographicSize; float minX = -Camera.main.orthographicSize * Camera.main.aspect; float maxX = Camera.main.orthographicSize * Camera.main.aspect; minY--; maxY++; minX--; maxX++; // Create vertices Vertex topLeft = Instantiate(vertexPrefab).GetComponent <Vertex>(); Vertex topRight = Instantiate(vertexPrefab).GetComponent <Vertex>(); Vertex bottomLeft = Instantiate(vertexPrefab).GetComponent <Vertex>(); Vertex bottomRight = Instantiate(vertexPrefab).GetComponent <Vertex>(); topLeft.transform.position = new Vector2(minX, maxY); topRight.transform.position = new Vector2(maxX, maxY); bottomLeft.transform.position = new Vector2(minX, minY); bottomRight.transform.position = new Vector2(maxX, minY); // Create edges Edge topEdge = Instantiate(edgePrefab).GetComponent <Edge>(); Edge bottomEdge = Instantiate(edgePrefab).GetComponent <Edge>(); topEdge.Point1 = topLeft; topEdge.Point2 = topRight; bottomEdge.Point1 = bottomLeft; bottomEdge.Point2 = bottomRight; // Create trapezoid Trapezoid trap = Instantiate(trapezoidPrefab).GetComponent <Trapezoid>(); trap.TopEdge = topEdge; trap.BottomEdge = bottomEdge; trap.LeftVertex = topEdge.Point1; trap.RightVertex = topEdge.Point2; return(trap); }
/// <summary> /// Adds trapezoid shape in shape list /// </summary> /// <param name="region">region of the trapezoid on the board</param> /// <param name="penColor">Color of the pen</param> /// <param name="fillColor">Fill color</param> /// <param name="penWidth">Width of the pen</param> /// <param name="isFilled">Is trapezoid filled</param> public void AddTrapezoid(Region region, Color penColor, Color fillColor, float penWidth, bool isFilled) { region.FixSize(MinimumSize); this.DeSelect(); Trapezoid trapezoid = new Trapezoid(); trapezoid.Region = region; trapezoid.PenColor = penColor; trapezoid.PenWidth = penWidth; trapezoid.FillColor = fillColor; trapezoid.FillEnabled = isFilled; this.shapes.Add(trapezoid); StoreInBuffer(BufferOperation.Insert, trapezoid); handlerCol = new ShapeHandlerCollection(trapezoid); this.selectedElement = trapezoid; this.selectedElement.Select(); }
/* * Add a new neighbor to the trapezoid */ public void AddNeighbor(Trapezoid neighbor) { if (neighbor == null) { return; } // Desperate attempt at stopping weird neighbor behavoir // Only add valid neighbors if ((neighbor.left.x == this.right.x || neighbor.right.x == this.left.x) && !this.Neighbors.Contains(neighbor)) { this.Neighbors.Add(neighbor); } else { Debug.LogWarning("Weird neighbor behavior spotted for " + this.show() + "\nWith " + neighbor.show()); } }
/// <summary> /// Handle an opening cusp. i.e. starts two new edges. /// </summary> /// <param name="id">the id of the cusp vertex</param> /// <param name="prev">the id of previous polygon vertex</param> /// <param name="next">the id of the next polygon vertex</param> public void HandleOpeningCusp(IPolygonVertexInfo info) { var(lowerEdge, upperEdge) = this.StartNewTrapezoidEdges( info.Id, info.Prev, info.PrevUnique, info.Next, info.NextUnique); if (lowerEdge.IsRightToLeft) { Trapezoid.EnterInsideBySplit(info.Id, lowerEdge, upperEdge); } else { var belowEdge = lowerEdge.TreeNode.Prev.Data; var trapezoid = belowEdge.Trapezoid; trapezoid.LeaveInsideBySplit(info.Id, lowerEdge, upperEdge, this.splitSink); } }
static void Main() { Point point1 = new Point(0, 0); Point point2 = new Point(8, 0); Point point3 = new Point(2, 3); Point point4 = new Point(10, 3); Parellelogram parellelogram = new Parellelogram(point1, point2, point3, point4); Console.WriteLine($"The height of the parellelogram is: {Math.Abs(point1.Y - point3.Y)}"); Console.WriteLine($"The base of the parellelogram is: {Math.Abs(point1.X - point2.X)}"); Console.WriteLine($"Parellelogram area is: {parellelogram.Area()}\n"); point2 = new Point(8, 0); point3 = new Point(0, 3); point4 = new Point(8, 3); Rectangle rectangle = new Rectangle(point1, point2, point3, point4); Console.WriteLine($"The length of the rectangle is: {Math.Abs(point1.X - point2.X)}"); Console.WriteLine($"The width of the rectangle is: {Math.Abs(point1.Y - point3.Y)}"); Console.WriteLine($"Rectangle area is: {rectangle.Area()}\n"); point2 = new Point(4, 0); point3 = new Point(0, 4); point4 = new Point(4, 4); Square square = new Square(point1, point2, point3, point4); Console.WriteLine($"The side of the square is: {Math.Abs(point1.X - point2.X)}"); Console.WriteLine($"Square area is: {square.Area()}\n"); point2 = new Point(14, 0); point3 = new Point(3, 4); point4 = new Point(11, 4); Trapezoid trapezoid = new Trapezoid(point1, point2, point3, point4); Console.WriteLine($"The baseB of the trapezoid is: {Math.Abs(point1.X - point2.X)}"); Console.WriteLine($"The baseA of the trapezoid is: {Math.Abs(point3.X - point4.X)}"); Console.WriteLine($"The height of the trapezoid is: {Math.Abs(point1.Y - point3.Y)}"); Console.WriteLine($"Trapezoid area is: {trapezoid.Area()}"); Console.ReadLine(); }
// Case 4: Trapezoid contains point q, p lies outside // break trapezoid into 3 smaller trapezoids public Trapezoid[] Case4(Trapezoid t, Edge e) { Point lp; if (e.P.X == t.LeftPoint.X) { lp = e.P; } else { lp = t.LeftPoint; } Trapezoid[] trapezoids = new Trapezoid[3]; if (_cross == t.Top) { trapezoids[0] = t.UpperLeft; trapezoids[0].RightPoint = e.Q; } else { trapezoids[0] = new Trapezoid(lp, e.Q, t.Top, e); trapezoids[0].UpdateLeft(t.UpperLeft, e.Above); } if (_bCross == t.Bottom) { trapezoids[1] = t.LowerLeft; trapezoids[1].RightPoint = e.Q; } else { trapezoids[1] = new Trapezoid(lp, e.Q, e, t.Bottom); trapezoids[1].UpdateLeft(e.Below, t.LowerLeft); } trapezoids[2] = new Trapezoid(e.Q, t.RightPoint, t.Top, t.Bottom); trapezoids[2].UpdateLeftRight(trapezoids[0], trapezoids[1], t.UpperRight, t.LowerRight); return(trapezoids); }
static void Main(string[] args) { Quad quad = new Quad(1.1F, 1.2F, 6.6F, 2.8F, 6.2F, 9.9F, 2.2F, 7.4F); Trapezoid trap = new Trapezoid(0.0F, 0.0F, 10.0F, 0.0F, 8.0F, 5.0F, 3.3F, 5.0F); Para para = new Para(5F, 5F, 11F, 5F, 12F, 20F, 6F, 20F); Rectangle rect = new Rectangle(17F, 14F, 30F, 14F, 30F, 28F, 17F, 28F); Square square = new Square(4F, 0F, 8F, 0F, 8F, 4F, 4F, 4F); Console.WriteLine(quad + " "); Console.WriteLine(trap + " "); Console.WriteLine(para + " "); Console.WriteLine(rect + " "); Console.WriteLine(square); Console.ReadKey(); }
public Edge(Point p, Point q) { P = p; Q = q; if (q.X - p.X != 0) { Slope = (q.Y - p.Y) / (q.X - p.X); } else { Slope = 0; } B = p.Y - (p.X * Slope); Above = null; Below = null; MPoints = new HashSet <Point>(); MPoints.Add(p); MPoints.Add(q); }
/// <summary> /// Return a tree that contains 4 trapezoids /// </summary> /// <param name="segment"></param> /// <returns></returns> public Node To4Traps(Segment segment) { // Vertex nodes Node root = new VertexNode(segment.LeftVertex); Node rightVertexNode = new VertexNode(segment.RightVertex); // Segment node Node segmentNode = new SegmentNode(segment); // Trapezoid nodes Trapezoid leftTrap = new Trapezoid(Trapezoid.Leftp, segment.LeftVertex, Trapezoid.Top, Trapezoid.Bottom); Trapezoid higherCenterTrap = new Trapezoid(segment.LeftVertex, segment.RightVertex, Trapezoid.Top, segment); Trapezoid lowerCenterTrap = new Trapezoid(segment.LeftVertex, segment.RightVertex, segment, Trapezoid.Bottom); Trapezoid rightTrap = new Trapezoid(segment.RightVertex, Trapezoid.Rightp, Trapezoid.Top, Trapezoid.Bottom); Node leftTrapNode = new TrapezoidalNode(leftTrap); Node higherCenterTrapNode = new TrapezoidalNode(higherCenterTrap); Node lowerCenterTrapNode = new TrapezoidalNode(lowerCenterTrap); Node rightTrapNode = new TrapezoidalNode(rightTrap); leftTrap.SetNeighbor(Trapezoid.HigherLeftNeighbor, Trapezoid.LowerLeftNeighbor, higherCenterTrap, lowerCenterTrap); leftTrap.Node = leftTrapNode; higherCenterTrap.SetNeighbor(leftTrap, leftTrap, rightTrap, rightTrap); higherCenterTrap.Node = higherCenterTrapNode; lowerCenterTrap.SetNeighbor(leftTrap, leftTrap, rightTrap, rightTrap); lowerCenterTrap.Node = lowerCenterTrapNode; rightTrap.SetNeighbor(higherCenterTrap, lowerCenterTrap, Trapezoid.HigherRightNeighbor, Trapezoid.LowerRightNeighbor); rightTrap.Node = rightTrapNode; segmentNode.SetChildren(ref higherCenterTrapNode, ref lowerCenterTrapNode); rightVertexNode.SetChildren(ref segmentNode, ref rightTrapNode); root.SetChildren(ref leftTrapNode, ref rightVertexNode); return(root); }
/// <summary> /// Handle a closing cusp. i.e. joins two edges /// </summary> /// <param name="id">the id of the cusp vertex</param> /// <param name="prev">the id of previous polygon vertex</param> /// <param name="next">the id of the next polygon vertex</param> public void HandleClosingCusp(IPolygonVertexInfo info) { var lowerEdge = this.EdgeForVertex(info.Id, info.Unique); TrapezoidEdge upperEdge; var prevEdge = lowerEdge.TreeNode.Prev?.Data; if (prevEdge?.Right == lowerEdge.Right && (prevEdge.Left == info.Prev || prevEdge.Left == info.Next)) { upperEdge = lowerEdge; lowerEdge = prevEdge; } else { upperEdge = lowerEdge.TreeNode.Next?.Data; } if (lowerEdge.Right != upperEdge?.Right) { throw new InvalidOperationException($"Invalid join of edges lower: {lowerEdge} and upper: {upperEdge}"); } var lowerTrapezoid = lowerEdge.Trapezoid; if (lowerEdge.IsRightToLeft) { lowerTrapezoid.LeaveInsideByJoin(info.Id, this.splitSink); } else { var upperEdge2 = lowerEdge.TreeNode.Next.Data; var upperTrapezoid = upperEdge2.Trapezoid; Trapezoid.EnterInsideByJoin(lowerTrapezoid, upperTrapezoid, info.Id, this.splitSink); } this.JoinTrapezoidEdges(lowerEdge); }
public static SpectatorGrid CreateGrid(Trapezoid Bounds, Vector2 CellDimensions) { if (Bounds.Height <= 0) { return(null); } SpectatorCell[][] Cells; int NumRows = Mathf.CeilToInt(Bounds.Height / CellDimensions.y); float XZRatio = Bounds.LegBase / Bounds.Height; Cells = new SpectatorCell[NumRows][]; int Row = 0; Vector2 CellPos = Bounds.TopRightCorner; do { float RowXMax = Bounds.xMin + (CellPos.y - Bounds.zMin - 1) * XZRatio; int Column = 0; int NumColumns = Mathf.CeilToInt(2 * RowXMax / CellDimensions.x); CellPos = new Vector2(-NumColumns * .5f * CellDimensions.x, CellPos.y); Cells[Row] = new SpectatorCell[NumColumns]; while (Column < NumColumns) { Cells[Row][Column] = new SpectatorCell(CellPos); CellPos += CellDimensions.x * Vector2.right; Column++; } CellPos -= CellDimensions.y * Vector2.up; Row++; } while (Row < NumRows); return(new SpectatorGrid(Cells, CellDimensions)); }
// A __________ B // / \ // / \ // / \ // D /________________\ C // // Trapezoid(A, B, C, D) -> Parallel(Segment(A, B), Segment(C, D)) // private static List <EdgeAggregator> InstantiateFromTrapezoid(GroundedClause clause) { List <EdgeAggregator> newGrounded = new List <EdgeAggregator>(); if (clause is Trapezoid) { Trapezoid trapezoid = clause as Trapezoid; newGrounded.AddRange(InstantiateFromTrapezoid(trapezoid, trapezoid)); } else if (clause is Strengthened) { Strengthened streng = clause as Strengthened; if (!(streng.strengthened is Trapezoid)) { return(newGrounded); } newGrounded.AddRange(InstantiateFromTrapezoid(streng.strengthened as Trapezoid, streng)); } return(newGrounded); }
/// <summary> /// Return a tree that contains 4 trapezoids /// </summary> /// <param name="segment"></param> /// <returns></returns> public Node To4Traps(Segment segment) { // Vertex nodes Node root = new VertexNode(segment.LeftVertex); Node rightVertexNode = new VertexNode(segment.RightVertex); // Segment node Node segmentNode = new SegmentNode(segment); // Trapezoid nodes Trapezoid leftTrap = new Trapezoid(Trapezoid.Leftp, segment.LeftVertex, Trapezoid.Top, Trapezoid.Bottom); Trapezoid higherCenterTrap = new Trapezoid(segment.LeftVertex, segment.RightVertex, Trapezoid.Top, segment); Trapezoid lowerCenterTrap = new Trapezoid(segment.LeftVertex, segment.RightVertex, segment, Trapezoid.Bottom); Trapezoid rightTrap = new Trapezoid(segment.RightVertex, Trapezoid.Rightp, Trapezoid.Top, Trapezoid.Bottom); Node leftTrapNode = new TrapezoidalNode(leftTrap); Node higherCenterTrapNode = new TrapezoidalNode(higherCenterTrap); Node lowerCenterTrapNode = new TrapezoidalNode(lowerCenterTrap); Node rightTrapNode = new TrapezoidalNode(rightTrap); leftTrap.SetNeighbor(Trapezoid.HigherLeftNeighbor, Trapezoid.LowerLeftNeighbor, higherCenterTrap, lowerCenterTrap); leftTrap.Node = leftTrapNode; higherCenterTrap.SetNeighbor(leftTrap, leftTrap, rightTrap, rightTrap); higherCenterTrap.Node = higherCenterTrapNode; lowerCenterTrap.SetNeighbor(leftTrap, leftTrap, rightTrap, rightTrap); lowerCenterTrap.Node = lowerCenterTrapNode; rightTrap.SetNeighbor(higherCenterTrap, lowerCenterTrap, Trapezoid.HigherRightNeighbor, Trapezoid.LowerRightNeighbor); rightTrap.Node = rightTrapNode; segmentNode.SetChildren(ref higherCenterTrapNode, ref lowerCenterTrapNode); rightVertexNode.SetChildren(ref segmentNode, ref rightTrapNode); root.SetChildren(ref leftTrapNode,ref rightVertexNode); return root; }
private Sink(Trapezoid trapezoid) : base(null, null) { Trapezoid = trapezoid; trapezoid.Sink = this; }