public void ContainsTopLeft() { var rect = new Rect2f(10, 10, 100, 100); Assert.True(rect.Contains(rect.TopLeft)); Assert.True(rect.Contains(rect.Left, rect.Top)); }
public void DoNotContainsBottomRight() { var rect = new Rect2f(10, 10, 100, 100); Assert.False(rect.Contains(rect.BottomRight)); Assert.False(rect.Contains(rect.Right, rect.Bottom)); }
public void Contains() { var rect = new Rect2f(new Point2f(0, 0), new Size2f(3, 3)); // OpenCV typically assumes that the top and left boundary of the rectangle are inclusive, // while the right and bottom boundaries are not. https://docs.opencv.org/2.4/modules/core/doc/basic_structures.html?highlight=rect Assert.False(rect.Contains(0, -1)); Assert.False(rect.Contains(-1, 0)); Assert.False(rect.Contains(-1, -1)); Assert.True(rect.Contains(0, 0)); Assert.True(rect.Contains(0, 1)); Assert.True(rect.Contains(1, 0)); Assert.True(rect.Contains(1, 1)); Assert.True(rect.Contains(2, 0)); Assert.True(rect.Contains(2, 1)); Assert.True(rect.Contains(2, 2)); Assert.True(rect.Contains(0, 2)); Assert.True(rect.Contains(1, 2)); Assert.True(rect.Contains(2, 2)); Assert.False(rect.Contains(0, 3)); Assert.False(rect.Contains(1, 3)); Assert.False(rect.Contains(2, 3)); Assert.False(rect.Contains(3, 3)); Assert.False(rect.Contains(3, 0)); Assert.False(rect.Contains(3, 1)); Assert.False(rect.Contains(3, 2)); Assert.False(rect.Contains(3, 3)); }
public void BottomRight() { var rect = new Rect2f(10, 10, 100, 100); Assert.Equal(110, rect.Bottom); Assert.Equal(110, rect.Right); Assert.Equal(new Point2f(110, 110), rect.BottomRight); }
public void TopLeft() { var rect = new Rect2f(10, 10, 100, 100); Assert.Equal(10, rect.Top); Assert.Equal(10, rect.Left); Assert.Equal(new Point2f(10, 10), rect.TopLeft); }
public static Mat Apply(this Rect2f area, Mat super) { int w = super.Width; int h = super.Height; return(super.Clone(new Rect((int)Math.Round(w * area.X), (int)Math.Round(h * area.Y), (int)Math.Round(w * area.Width), (int)Math.Round(h * area.Height)))); }
public static LineItem[] MakeRectangle( Rect2f rect, Vector4f color ) { return new[] { new LineItem( rect.Origin, rect.BottomRight, color ), new LineItem( rect.BottomRight, rect.TopRight, color ), new LineItem( rect.TopRight, rect.TopLeft, color ), new LineItem( rect.TopLeft, rect.Origin, color ) }; }
public void IntersectsWith() { var rect1 = new Rect2f(0, 0, 100, 100); var rect2 = new Rect2f(0, 0, 100, 100); Assert.True(rect1.IntersectsWith(rect2)); rect2 = new Rect2f(50, 0, 100, 100); Assert.True(rect1.IntersectsWith(rect2)); rect2 = new Rect2f(100, 0, 100, 100); Assert.False(rect1.IntersectsWith(rect2)); }
public new void AutoSize() { if(this.Template != null) { Rect2f boundingRect = this.Template.EditRect; boundingRect.LeftBottom -= new Vector2f(60.0f, 60.0f); boundingRect.Size += new Vector2f(120.0f, 120.0f); this.OutRect = boundingRect; } else { this.OutRect = new Rect2f(100, 100); } }
public void Intersect() { var rect1 = new Rect2f(0, 0, 100, 100); var rect2 = new Rect2f(0, 0, 100, 100); var intersect = rect1.Intersect(rect2); Assert.Equal(new Rect2f(0, 0, 100, 100), intersect); rect2 = new Rect2f(50, 0, 100, 100); intersect = rect1.Intersect(rect2); Assert.Equal(new Rect2f(50, 0, 50, 100), intersect); rect2 = new Rect2f(100, 0, 100, 100); intersect = rect1.Intersect(rect2); Assert.Equal(new Rect2f(100, 0, 0, 100), intersect); }
/// <summary> /// Applies the CSS specification formula for resolving object relative positions using the values given /// </summary> /// <param name="xPos">Positioning (along x-axis) to resolve </param> /// <param name="yPos">Positioning (along y-axis) to resolve </param> /// <param name="ObjectArea">Size of the area the object resides in</param> /// <param name="ObjectSize">Size of the object itsself</param> public static Point2f Solve_Object_Position(CssValue xPos, CssValue yPos, Rect2f ObjectArea, Rect2f ObjectSize) {/* https://www.w3.org/TR/css-backgrounds-3/#the-background-position */ if (ObjectArea is null) { throw new ArgumentNullException(nameof(ObjectArea)); } if (ObjectSize is null) { throw new ArgumentNullException(nameof(ObjectSize)); } Contract.EndContractBlock(); var retPos = new Point2f { X = Solve_Object_Axis_Position(xPos, ObjectArea.Width, ObjectSize.Width), Y = Solve_Object_Axis_Position(yPos, ObjectArea.Height, ObjectSize.Height) }; return(retPos); }
public static extern ExceptionStatus core_FileNode_read_Rect2f(IntPtr node, out Rect2f returnValue);
/// <summary> /// Renders a texture "textureSRV" into a rectangle rect. /// Rect is always specified such that x points right and y points up, /// but can be modified by pvw. /// /// opaque specifies whether to use the opaque or alpha pass. /// /// yPointsUp specifies that in the *input image* textureSRV, whether y points up /// If false, then [0,0] is the top left corner, else it's the bottom left corner /// </summary> /// <param name="textureSRV"></param> /// <param name="rect"></param> /// <param name="pvw"></param> /// <param name="opaque"></param> /// <param name="yPointsUp"></param> private void RenderTexture( ShaderResourceView textureSRV, Rect2f rect, Matrix4f pvw, bool opaque, bool yPointsUp ) { // TODO: split: passing in opaque is stupid var viewportMatrix = Matrix4f.Identity; var textureMatrix = Matrix4f.Identity; viewportMatrix.m00 = rect.Width; viewportMatrix.m11 = rect.Height; viewportMatrix.m03 = rect.Origin.x; viewportMatrix.m13 = rect.Origin.y; pvw = pvw * viewportMatrix; if( yPointsUp ) { textureMatrix.m11 = -1; textureMatrix.m13 = 1; } effect.GetVariableByName( "pvw" ).AsMatrix().SetMatrix( pvw ); effect.GetVariableByName( "textureMatrix" ).AsMatrix().SetMatrix( textureMatrix ); effect.GetVariableByName( "tex" ).AsResource().SetResource( textureSRV ); d3d.Device.InputAssembler.SetVertexBuffers( 0, textureVertexBuffer.DefaultBinding ); d3d.Device.InputAssembler.SetPrimitiveTopology( PrimitiveTopology.TriangleList ); if( opaque ) { d3d.Device.InputAssembler.SetInputLayout( opaqueTexturePassLayout ); opaqueTexturePass.Apply(); } else { d3d.Device.InputAssembler.SetInputLayout( alphaTexturePassLayout ); alphaTexturePass.Apply(); } d3d.Device.Draw( 6, 0 ); }
public void RenderAlphaTexture( ShaderResourceView textureSRV, Rect2f rect, Matrix4f pvw, bool yPointsUp ) { RenderTexture( textureSRV, rect, pvw, false, yPointsUp ); }
public void FromLTRB() { var rect = Rect2f.FromLTRB(1, 2, 3, 4); Assert.Equal(new Rect2f(1, 2, 3, 3), rect); }
public static bool LineRectangleIntersection( Vector2f p0, Vector2f p1, Rect2f rect ) { if( rect.Contains( p0 ) || rect.Contains( p1 ) ) { return true; } if( SegmentSegmentIntersection( p0, p1, rect.Origin, rect.BottomRight ) == IntersectionResult.INTERESECTING ) { return true; } if( SegmentSegmentIntersection( p0, p1, rect.BottomRight, rect.TopRight ) == IntersectionResult.INTERESECTING ) { return true; } if( SegmentSegmentIntersection( p0, p1, rect.TopRight, rect.TopLeft ) == IntersectionResult.INTERESECTING ) { return true; } if( SegmentSegmentIntersection( p0, p1, rect.TopLeft, rect.Origin ) == IntersectionResult.INTERESECTING ) { return true; } return false; }
public static extern ExceptionStatus core_Mat_push_back_Rect2f(IntPtr self, Rect2f v);
public void ContainsRect() { var rect = new Rect2f(10, 10, 100, 100); Assert.True(rect.Contains(rect)); }
public static double Get_Logical_Height(EWritingMode WritingMode, Rect2f rect) => Get_Logical(WritingMode, rect.Height, rect.Width);
private void OnOutRectChanged(ShapeTemplateView sender, Rect2f oldValue) { UpdateOutRect(); }
public void RenderOpaqueTexture( ShaderResourceView textureSRV, Rect2f rect, Matrix4f pvw, bool yPointsUp ) { RenderTexture( textureSRV, rect, pvw, true, yPointsUp ); }
public static Mat GetTexture(List <Tile> mapData, out Rect2f area) { float minX = float.MaxValue; float maxX = float.MinValue; float minY = float.MaxValue; float maxY = float.MinValue; float step = Tile.Width; foreach (Tile item in mapData) { float x = item.X; float y = item.Y; if (minX > x) { minX = x; } if (maxX < x) { maxX = x; } if (minY > y) { minY = y; } if (maxY < y) { maxY = y; } } int imageWidth = (int)Math.Round((maxX - minX) / step) + 1; int imageHeight = (int)Math.Round((maxY - minY) / step) + 1; // Console.WriteLine("높이" + imageHeight + "넓이" + imageWidth); Mat mat = new Mat(new Size(imageWidth, imageHeight), MatType.CV_8UC3); for (int y = 0; y < imageHeight; y++) { for (int x = 0; x < imageWidth; x++) { mat.Set(y, x, new Vec3b(255, 255, 255)); } } int mx = 0; int my = 0; foreach (Tile item in mapData) { int x = (int)Math.Round((item.X - minX) / step); int y = (int)Math.Round((item.Y - minY) / step); mat.Set(y, x, new Vec3b(item.B, item.G, item.R)); mx = Math.Max(mx, x); my = Math.Max(my, y); } // Cv2.ImShow("asdf", mat); area = new Rect2f(minX, minY, maxX - minX, maxY - minY); return(mat); }
public static extern ExceptionStatus core_FileStorage_shift_Rect2f(IntPtr fs, Rect2f val);
protected Quad2f GetShapeQuad(Shape shape) { ShapeCircle root = shape.RootCircle; ShapeCircle leftBottomCircle = GetLeftBottomCircle(root); ShapeCircle rightTopCircle = GetRightTopCircle(root); Vector2f leftBottomOffset = (leftBottomCircle.Position - root.Position).Rotate(-shape.Angle); Vector2f rightTopOffset = (rightTopCircle.Position - root.Position).Rotate(-shape.Angle); Vector2f rectLeftBottom = root.Position + leftBottomOffset; Vector2f rightTopBottom = root.Position + rightTopOffset; Rect2f rect = new Rect2f(rectLeftBottom, rightTopBottom - rectLeftBottom).Normalize(); return rect.Rotate(root.Position, shape.Angle); }