Descending Packing Algorithm for Irregular Graphics Based on Geometric Feature Points

The packing for two-dimensional irregular graphics is one of the NP-complete problems and widely used in industrial applications. In this paper, a descending nesting algorithm for a two-dimensional irregular graph based on geometric feature points is proposed. Before the packing, the parts to be packed are sorted, matched, and spliced, and the matching of the rectangular pieces and the rectangular-like pieces is carried out according to the plate size. On this basis, the geometric feature points of the parts are used to construct the packing baseline, and the packing is accurately carried out according to the principles of the bottom left, the principle of the lowest center of gravity, and combination with virtual moving, rotating collision calculation. The computation of the moving collision distance between the graphics is replaced by the projecting computation of the geometric feature points of the graphic parts, so the computation amount can be reduced. Also, this method is used to test a number of benchmarks examples which are provided by ESICUP (EURO Special Interest Group on Cutting and Packing), which show that the proposed algorithm not only can improve packing but also has better stability and reliability.


Introduction
Two-dimensional packing is a classic problem, and the purpose of it is to find a layout with minimal waste on a given shape and size of a plate. e packing technology has been widely used in sheet metal, clothing, shipbuilding, and furniture industries [1]. For the problem of cutting and packing of irregular parts, how to obtain the applicable layout of the geometric conditions is very complicated since all parts must be completely inside the plate and cannot overlap [2]. Two-dimensional irregular packing is a kind of combinatorial optimization problems, which is a NPcomplete problem. e calculation complexity is extremely high, and there is no effective mathematical calculation method up to now. Due to its wide application in modern industry, researchers have done a lot of research on this and also proposed many feasible solutions. For example, Baldacci et al. [3] used Lagrangian relaxation method and heuristic algorithm to carry out defect layout and applied it to the leather clothing and furniture industry, but the convergence of this method is difficult to guarantee. To reduce the complexity of the packing problem, pairwise clustering was introduced in literature [4] to group congruent polygons together in pairs. Pairwise clustering was done automatically to discover matched features among multiple present polygons. In literature [5], a systematic study of the problem and an exact branch-and-bound Algorithm was made by reducing the size of the problem to be solved at each node. Based on the literature [5], Wang et al. [6] utilized a novel branching scheme to deal with the reverse convex quadratic constraints in the quadratic model and incorporated a number of problem-specific algorithmic tweaks. Literature [4][5][6][7][8][9] all belonged to the NFP-(no-fit polygon-) based packing algorithm. Although some improvements had been made to achieve packing, due to the large amount of calculation of NFP itself, the algorithm efficiency could not be improved well. Based on two known techniques, the vector graphics were transformed into pixel matrix by AutoCAD before packing, and the bottom-left-fill algorithm was used for packing, an irregular stock cutting system (NEST) developed on AutoCAD software platform, which is presented in [10]. But this method lacks accurate collision detection, and the material utilization rate is not very high. Since the existing packing algorithms do not consider the shape contour features, an irregular packing algorithm was proposed to solve this problem based on a principal component analysis methodology in [11], but the collision detection between two pixels increases the amount of calculation. Jones et al. [12] introduced a fully general, exact algorithm for packing irregular shapes based on a specialized branch-and-bound algorithm together with some heuristics. Camacho et al. [13] proposed an adaptation to the twodimensional irregular bin packing problem of the Djang and Finch heuristic (DJD) which is originally designed for the one-dimensional bin packing problem. A new mixed-integer model in which binary decision variables were associated with each discrete point of the board (a dot) and with each piece type was proposed in [14]. Based on [14], a mixedinteger-linear programming formulation was proposed to optimize the packing of particular polygonal shapes [15]. ese algorithms above used discrete methods to calculate the collision distance, but the discretization method required a large number of data points. Liao et al. [16] adopted a physical method that used the rubber band packing algorithm to simulate a rubber band wrapping those packing irregular shapes. e simulation showed a visual and fast packing process. However, this method had no advantage for mixed packing of multiple irregularities. ere are some strip packing algorithms, heuristic algorithms, hybrid algorithms, three-dimensional packing algorithms, and some applications of these algorithms [17][18][19][20][21][22][23][24][25]. But some are only suitable for rectangular packing, and the calculation is complicated, which will be improved in this paper. In addition, similar heuristic optimization layout ideas have also been applied to more and more fields, which are also worth learning [26][27][28][29].
In summary, the two-dimensional irregular graphics packing algorithm can be roughly divided into two categories: one is to simplify the two-dimensional irregular layout problem to a regular piece (rectangular bounding box) layout problem and perform simplified layout and the other one is based on the BL principle, through extrusion, abutment, and pattern rotation to adjust the abutment angle to optimize packing and improve material utilization. However, when you rotate and adjust the docking angle if you choose a preset angle for docking, you will lose the best angle docking. And, in the process of horizontal moving docking and vertical moving docking, it is often to cause the overlapping phenomenon in the previous moving direction after the second movement.
In view of these defects, a two-dimensional irregular descending geometric optimization packing algorithm based on the geometric feature points of graphs is proposed in this paper.
is paper has made some contributions in the following aspects: (1) Use the graph normalization preprocessing to sort the layout parts in descending order that overcomes the space waste defect caused by random layout. (2) Use variable packing baseline to arrange the layout graphs by collision. Overcome the limitation of layered packing strategy and improve the compactness of packing. (3) According to the principle of adaptation, the precise touch between the layout graphs is replaced by the discrete feature points of graphs, which greatly reduces the amount of calculation. (4) e adaptive virtual collision computing is carried out to reduce the calculation caused by the graphs' movement, which also avoids the phenomenon that the one-way collision calculation easily causes the failure of finding the best packing position.

Methods
is paper proposes a two-dimensional irregular packing algorithm. is method builds an irregular packing baseline based on the geometric feature points of the layout piece. In this paper, the layout of the same parts is processed in advance to improve the priority of the same parts packing. erefore, the regularity of the similar parts packing is effectively improved. e calculation of the distance between horizontal and vertical collisions and the angle of rotation against collisions can greatly enhance the efficiency of packing and the positioning accuracy of a one-time layout. e calculation of the graphic feature points is used instead of the graphic mobile layout, which realizes virtual packing and can save time. Figure 1 shows the main processes of this algorithm.

Graphic Prenormalization.
In order to simplify the packing process and reduce the time of repeated searches, before the packing, it is proposed to encode and store graphics with a unified standard to be packing. e normalization rules are to sort the geometric feature points of all the pieces by arranging clockwise and to store them with the BL (bottom left) point as the starting point, to extract the geometric feature points of the packing parts and save them as the points group table named obj(i)_plst. As shown in Figure 2, the layout part is a polygon formed by eight points connected in sequence. According to the normalization rules, the order of the eight points stored in obj(i)_plst is P 8 ⟶P 1 ⟶P 2 ⟶P 3 ⟶P 4 ⟶P 5 ⟶P 6 ⟶P 7 . e purpose of such normalization is to facilitate the subsequent search of the reference points for packing; that is, the first point of each points' group of the part is used as the reference point for the packing movement.     In order to ensure a unique correspondence in the process of matching the initial layout patterns, during the normalization process, the horizontal and vertical lines will automatically add points. As shown in Figure 2(a), where the lines P 1 P 2 , P 3 P 4 , P 5 P 6 , and P 7 P 8 are horizontal lines, and the lines P 1 P 8 , P 2 P 3 , P 4 P 5 , and P 6 P 7 are vertical lines, adding point processing is required for them. e method of increasing the midpoints is adopted. After processing, it is shown in Figure 2(b). Its role is to increase the number of discrete points in order to minimize the loss of information caused by the reduction of the vector graph to the discrete feature points representation and ensure the effectiveness of subsequent graphic matching and collision calculation. In order to reduce the recognition of the graphic features for packing, when the layout pieces contain arc features, the arc discretization will be used to divide the arc into discrete points and connect the discrete points with polylines for approximate replacement. After the packing is finished, the arc features are restored.

Matching Stitching of Graphics.
Since the two similar pieces can be reassembled into a more compact new piece, reassembling the similar pieces first and then arranging will greatly save the layout space and improve the utilization of the layout. In the packing process, in order to avoid similar parts as independent pieces to be individually packed, the graphics are matched and stitched during the preprocessing of the graphics. e principle of graphic matching is the preliminary arrangement of packing parts according to area and number of feature points; that is, two layout parts with the same area and the same number of feature points are treated as similar pieces, and the features with the highest degree of coincidence are used as matching objects. As shown in Figure 3(a), the highest coincidence characteristics of the layout pieces P and T are P 2 P 3 and T 1 T 3 , respectively. After the matching and stitching process, the layout pieces P and T are merged into a rectangular piece. e prepacking pieces in Figure 3(b) are not the same kind, but they belong to similar kinds. ey need to be matched and spliced in the preprocessing stage; otherwise, it will waste the packing space in the subsequent packing. When the moving parts P and T are matched by moving and touching, the feature point P 3 corresponding to the touching points are T 2 and T 3 , and there is a nonsingle correspondence relationship. At this time, such a point is not used as the touching feature point. e same is for points P 2 , P 4 , P 5 , and P 6 . By adding points as described in Section 2.1.1, we can use the newly added midpoints P 14 , P 15 , and P 16 as horizontal touchpoints for matching and stitching. In this way, we can complete the precise splicing of two layout parts and reduce unnecessary waste for the next optimization of packing.
In order to better adapt to the size of the board for packing, during the preprocessing of the graphics, the rectangular parts and rectangular-like parts are preferentially matched and stitched. As shown in Figure 3(c), the packing piece A is located in the smallest rectangular enclosing frame B. We define the approximation coefficient of a rectangular-like piece as s δ � s A /s B , where s A is the area of piece A and s B is the area of piece B. e value of s δ will directly affect the packing effect. rough a large number of experiments, an appropriate value of s δ is chosen as follows: if it is satisfied s δ ≥ 85%, then, A is called a rectangular-like piece. In the preprocessing stage, if a certain piece meets s δ ≥ 90%, it will be matched and spliced. e maximum length of the splicing is the width of the plate. e purpose is to make the bottom layer "fully packed" as much as possible to reduce the waste of the plate.

Constructing Packing Baseline Based on Geometric
Feature Points. In 2D regular parts packing, the strip model is commonly used to achieve layered packing. However, in irregular packing, it is difficult to form a clear strip model and the horizontality of the layered layout cannot be guaranteed, so this strategy is not suitable for the packing of two-dimensional irregular parts. However, the layout idea still has guiding significance. Based on this idea, the strategy of layering layout of the strip model is extended, and the idea of packing baseline based on geometric feature points is proposed. e packing baseline is not a traditional horizontal baseline, but a multipolyline and contour line updated in real time.  Figure 4.
Connecting all the current open points into a polyline in a certain order, that is, the packing baseline based on the geometric feature points, the feature points that make up the baseline are called the open points group and recorded as base_open_plst. Similarly, record all the points forming a closed-loop as close_plst. As shown in Figure 4, O 5 ⟶C 1 ⟶C 2 ⟶O 5 is a closed points group, which is called the packing closed area. e packing closed areas are also the source of waste of layout materials. e smaller the packing closed area, the better the layout effect and the higher the material utilization rate.
As shown in Figure 4, the current packing baseline is O 1 ⟶O 2 ⟶O 3 ⟶. . .⟶O 15 , and the currently scheduled piece is A. According to the BL principle, its initial position is the position of the dashed box in Figure 4. Obviously, this position is not the optimal layout, so the position needs to be adjusted by the assistance of a further heuristic collision strategy.

Sorting Descending Order.
In the graphic preprocessing, all parts have been normalized and matched and stitched, but the matching and stitching process will reorganize some of the layouts (shown in Figure 3), so we need to do a stitching process for the recombinant pieces before packing. e processed parts are used as the initial input graphics. e area of each recombinant part is calculated and packed in descending order according to their area.
According to Pick's theorem, we can transform n polygons into n-2 triangles and use the cross multiplication to calculate the area of each triangle in turn. e sum of the areas of triangles is the area of the polygon. e formula for calculating the area of the prepacking piece (polygon) is where x i and y i are the coordinates of each vertex of part A. e calculation formula for the centroid of the prepacking piece is where S A is the area of part A and x c and y c are the centroid coordinates of part A. e algorithm of the packing process is as follows: Step 1: calculate the areas of all the prepacking pieces (S A ), total length (L A ), and centroid coordinates (x c , y c ), extract feature points list (obj(i) plst), and save them into the data list obj(i) info lst(S A , L A , (x c , y c ), obj(i) plst).
Step 2: sort the data list obj(i) info lst(S A , L A , (x c , y c ), obj(i) plst) in descending order by S A .
Step 3: extract the feature points of the initial layout and record as base open plst(p lt , p lb , p rb ). Among them, p lt is the upper left corner point of the plate, p lb is the lower left corner point of the plate, and p rb is the lower Figure 4: Packing baseline with geometric feature points.  Step 4: take out a piece from the prepacking pieces information list as obj(i) info lst in order, and record it as the currently active prepacking piece as active obj(i) lst. Compare the area of the closed area in the current layout with the closed points group. If it can be placed, it will be preferentially located in the closed area. If it cannot be placed, perform virtual mobile packing calculation on the current layout part, virtually move the part to the reference point position of the current packing baseline, and wait for accurate calculation by collision.
Step 5: perform virtual precise collision calculation between the current layout position and the current packing baseline. By repeating the iteration of the calculation, the final layout position is determined, and the coordinates of the final layout position are computed.
Step Step 7: calculate whether the current part exceeds the plate size; if not, go to Step 4 and continue packing. If it exceeds the plate size, delete the current layout part, go to step 4 to find a suitable prepacking part, until the end of traversing all parts.

Discrete Virtual Packing Calculation.
In order to save the time of the moving and contacting test, the geometric feature points of the prepacking piece are extracted as the basis for computing of the virtual packing, and the virtual movement and virtual rotation and contacting test are performed through corresponding calculations. As shown in Figure 5(a), eight discrete feature points of the part are extracted as the feature information for packing. If you need to perform a moving and touching test on a prepacking piece, you only need to calculate the translation matrix of these points to get the new feature points coordinates after the piece moves. Similarly, after calculating the rotation of the centroid of Figure 5(a), the feature points of the virtual rotating arrangement can be obtained as shown in Figure 5(c). In this way, the computation of the contacting test of packing can be reduced, and the operation process of multiple physical translation can be avoided. It only needs to actually move and rotate once after getting the exact position, so this method can achieve precise packing in one step. e virtual translation calculation formula is where x, y are the original coordinates; x m , y m are the coordinates after moving; t x is the movement in x direction; and t y is the movement in y direction. e virtual rotation calculation formula is where x, y are the original coordinates; x r , y r are the coordinates after the centroid rotation; (t x , t y ) are centroid coordinates of the prepacking piece; and θ is the rotation angle:

Bottom Left and Center of Gravity Principles and
Packing Priorities. In the virtual packing calculation, the BL combined with the lowest center of gravity principle is used as the basis for determining the optimal packing. at is, in the virtual translation packing calculation, try to arrange the layout pieces to the leftmost and bottommost position of the plate, use the packing baseline as the benchmark, and try to squeeze it to the left and bottom. In the calculation of the virtual rotation packing, the rotation angle corresponding to the lowest position of the centroid is used as the angle value required for the optimal layout position. At the same time, material utilization is also an important indicator for evaluating the effect of packing. According to the principle of optimal packing for maximum plate utilization, the following layout priorities are set.
(1) e packing process is from left to right and from bottom to top. at is, when the heights of the center of gravity of the two prepacking pieces are equal, the left one takes precedence, and when the distances of the two prepacking pieces from the left boundary are equal, the lower height of the center of gravity takes precedence.
(2) e ranking of recombinant components priority over the area descending principle.
(3) e principle that the highest point is lower after the part is placed will take precedence over the principle of the lowest center of gravity. (4) According to the area descending principle, when the current part is placed and exceeds the highest point of the current packing baseline if it meets the plate utilization condition, it is allowed to continue packing once again. If the above situation is not caused by the principle of descending area, there is no such priority. Plate utilization conditions: n i�i s i ≥ s over � l width × h over , where n i�i s i is the sum of the areas of the remaining pieces to be arranged, s over is the overflow area caused by the current packing, l width is the width of the plate, and h over is the height difference between the highest point after the current packed part and the highest point of the current packing baseline. (5) If there are only two pieces to be packed at present, the principle of the lower highest point after the piece is placed is a priority to any other principles.

Moving and Collision
Computing. In order to achieve two-direction precise moving collision packing, a variable step size for horizontal moving layout is used, and then vertical moving and collision calculation is carried out to obtain the lowest collision position. As shown in Figure 6, the leftmost point of the bounding box of piece A is used as the initial position of horizontal movement; then, take accumulative horizontal movement with appropriate steps (δ � 0.5box width), take vertical collision calculations at each moving position, and compute the horizontal position corresponding to the minimum value of the observation point P bl of the packing piece (position A as shown in Figure 7). Use this position as the positioning reference for subsequent precise movement. Increase the width of the enclosing frame by 0.5 times to the left and right as the range of accurate horizontal movement. Shorten the step size and recalculate P bl . is method from coarse positioning to precise subdivision collision computing greatly reduces the computation for uniformly discrete and traversal collision. Moreover, in the vertical collision calculation, the calculation of the distances between the linear discrete points is replaced by the projection calculation of several geometric feature points face to face, which greatly reduces the time of the vertical collision distance calculation. In the calculation of the vertical collision distance, a "face-to-face" collision test is carried out by using a bounding box projection of prepacking piece to intercept a part of the packing baseline to reduce the computation.
ere are two types of collision detection calculations: vertical collision detection and horizontal collision detection. e specific detection and calculation processes are as follows: as shown in Figure 7, when part A to be scheduled moves to the location to be scheduled (black line frame in Figure 7), the key points (p 1 , p 2 , p 3 , p 4 ) of part A are projected onto the current packing baseline (O 1 ⟶O 2 ⟶O 3 ⟶. . .⟶O 10 ) for the vertical collision detection; the projection points (t 1 , t 2 , o 3 , t 3 ) are obtained, respectively; and the projection distances are p 1 t 1 , p 2 t 2 , p 3 o 3 , p 4 t 3 , respectively. Since the "face-to-face" collision detection is mutual, the back projection is performed in the same way, intercept the feature points (o 2 , o 3 , o 4 ) located on the packing baseline between the key points of part A, and project these feature points onto part A. e projected points (t 4 , t 4 , t 5 ) are obtained, respectively, and the projection distances are o 2 t 4 , o 3 t 4 , o 4 t 5 , respectively. Take the shortest distance of the vertical collision detection as the vertical movement amount, and record as L v .
In Figure 7, there is only one tough point for part A to be arranged, so the current layout position is not completely touched; it needs to cooperate with the horizontal collision detection for further collision computing.
In the calculation of the horizontal collision detection, the process is similar to the vertical collision detection, and it also uses two-way mutual projection to compute the shortest projection distance.
As shown in Figure 8, the movement amount of horizontal collision is L h � p 4 t 6 . Because the horizontal collision movement will cause the original vertical tough relationship to be invalidated, in order to automatically and repeatedly detect the vertical and horizontal collision and finally reach the best tough position, a suitable margin is set for the movement amount of the horizontal collision. After tests, when the actual horizontal movement amount is L h ′ � 0.5L h , it is beneficial to increase the speed of collision detection. After repeating vertical and horizontal collision detection calculations, the final packing position of part A is A3, as shown in Figure 9.

Rotating and Collision
Computing. When computing the lowest layout position, the 90°rotation angle is used for the general rectangular and rectangular-like parts (s δ ≥ 85%) to compute the collision position, and for nonrectangular parts, use any angles to rotate and contact. As shown in Figure 9, A3 is the best position for the two-direction movement after collision, but it is not the lowest position. It can rotate piece A around its centroid, then use vertical and horizontal collision detection, and find the lower position A4 as the final layout position. In order to save the time of packing, the above movements and rotations are performed in the form of virtual movement and rotation computing.

Results
In order to further verify the effectiveness of this proposed algorithm, the algorithm is tested on a general auxiliary design platform AutoCAD. e benchmark problems provided by the ESICUP (EUROSlCUP) are used as test cases. Some commonly used benchmark examples, blaz, marques, shirts, trousers, and so forth, are chosen for the packing test.
e packing results are shown in Figures 10-13.

Discussion
In order to facilitate comparison, the analysis results of this method, the literature [30,31], and commercial packing software of SigmaNest and NestLib are shown in Table 1 (packing density is the ratio of the sum of the area of the parts to the area of the plate).
It can be seen from Table 1 that the descending order packing algorithm is reliable. After comparison with Sig-maNest, NestLib, GEFHNA, HAPG_HRG, and other methods, the conclusion is drawn: irregular graphics descending packing algorithm based on geometric feature points is suitable for the problem of two-dimensional irregular graphics packing. e packing density is high, and it has obvious advantages in dealing with the problem of mixed layout of regular and irregular pieces. e algorithm is         general, simple to operate, and has good application economics.

Conclusions
A general geometric packing algorithm suitable for twodimensional irregular graphics is proposed in this paper. e packing order is guided by the descending order of the area of parts. rough the graphic preprocessing, rectangular pieces and rectangular-like pieces are automatically matched and spliced according to their sizes, which eliminate the waste of space caused by the single packing of pieces and improves the sheet utilization. e packing baseline is constructed by the geometric feature points of the layout parts, prepacking parts are moved according to the BL principle, and the geometric feature points of the part and the packing baseline are used as the key point for bidirectional collision computing. e portion of feature points of the packing baseline are intercepted for face-to-face calculation by way of the bounding box of the layout piece, which greatly reduce the traversal computation cost of the method of converting vector graphics to discrete points. e computing of the lowest packing position of parts is realized by using large-step positioning and small-step accurate collision computation, which avoids the traversal computing of NFP method. is paper has made some contributions in the following aspects: (1) is algorithm classifies graphics according to their geometric characteristics and performs graphic classification and recombination preprocessing before packing, which solves the problems caused by single packing of previous algorithms. (2) e adaptive vertical collision detection and horizontal collision detection methods can find more accurate and compact layout positions, which is an innovation of this paper. (3) e strip layout algorithm is extended, the layered packing strategy is extended, and the strategy of variable packing baseline is used to improve the compactness of the layout.
Future research will be carried out in the following aspects: optimize the algorithm for computing the packing baseline and rotation collision to further improve the screening efficiency of the initial packing of the layout pieces; design the adaptive adjustment method of the rotation angle of the graphics, and use the closed free spaces for packing. A better mechanism for rational selection of the layout order based on the principle of highest plate utilization will be studied. e idea of using low-dimensional computing of discrete points of geometrical graphic items to solve complex problems of measurement and positioning between geometric graphics will be applied to more engineering fields, and the approaching of geometrical computing better for solving geometry problems will continue to be promoted.

Data Availability
e data used to support the findings of this study are included within the article.