A Method to pick up 2D vector graphics objects

Source: Internet
Author: User

The collection of two-dimensional vector graphics objects is a common operation in the vector graphics software. Inaccurate collection is easy to implement. You can directly calculate the bound of geometry, however, this is a little too rough to look very professional! To reflect the professional drawing level, we must achieve accurate pick-up. Here we introduce a method that combines geos buffer analysis with the GDI region. This section only describes precise polygon picking.

First, define the meaning of the precise pickup here. The so-called precise pickup means that it is counted as a valid pickup only when the pixel range of the screen covered by the mouse is clicked.

 

The image is picked up only when you click in the red area. Therefore, we consider the width and style of the pen, especially joinstyle and endcapstyle.

The region of GDI is an irregular closed range. It provides the ptinregion function to determine whether a vertex is in the region. Therefore, as long as we can compute the area of the above image, it is easy to accurately pick up. But how can we compute a region based on the coordinate data and paint information of the image?

It is easy to think of two parallel lines whose distance from the point string data of the image is the width of the paint brush, but it is a little hard to write this algorithm. Fortunately, we have open-source geos, the parallel lines we require are actually buffer analysis in geometric operations. Through the bufferop operation provided by geos, we can easily find the boundary data we need, in this way, we can create a region based on the boundary data, and then perform a click test.

It should be noted that geos considers the complex topological relationship of the ry. For irregular polygon, the computed geometry may be wrong, for example

 

This figure uses the polygon of GDI to draw a non-filled polygon. If you directly call a polygon-type geometry to buffer the Polygon-type polygon, the lower half of the image may only exist, this is the result of geos processing, but this is not what we want, so we cannot directly drop the bufferop: getresultgeometry using geos. In-depth analysis of the geos buffer analysis algorithm, we found an alternative solution offsetcurvebuilder. Its method is actually the parallel line algorithm we are looking for, and considering the brush style, we only need to call the response's get * curve () function based on our geomerty type.

For the above irregular polygon, we may need to call the getringcurve function twice to calculate the inner ring and outer ring respectively, when constructing a region, pay attention that the dot string sequence of the inner ring and outer ring is reversed to obtain the correct region.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.