{
    "content": [
        {
            "type": "text",
            "text": "# GD::Polyline (perldoc)\n\n## NAME\n\nGD::Polyline - Polyline object and Polygon utilities (including splines) for use with GD\n\n## SYNOPSIS\n\nuse GD;\nuse GD::Polyline;\n# create an image\n$image = GD::Image->new (500,300);\n$white  = $image->colorAllocate(255,255,255);\n$black  = $image->colorAllocate(  0,  0,  0);\n$red    = $image->colorAllocate(255,  0,  0);\n# create a new polyline\n$polyline = GD::Polyline->new;\n# add some points\n$polyline->addPt(  0,  0);\n$polyline->addPt(  0,100);\n$polyline->addPt( 50,125);\n$polyline->addPt(100,  0);\n# polylines can use polygon methods (and vice versa)\n$polyline->offset(200,100);\n# rotate 60 degrees, about the centroid\n$polyline->rotate(3.14159/3, $polyline->centroid());\n# scale about the centroid\n$polyline->scale(1.5, 2, $polyline->centroid());\n# draw the polyline\n$image->polydraw($polyline,$black);\n# create a spline, which is also a polyine\n$spline = $polyline->addControlPoints->toSpline;\n$image->polydraw($spline,$red);\n# output the png\nbinmode STDOUT;\nprint $image->png;\n\n## DESCRIPTION\n\nPolyline.pm extends the GD module by allowing you to create polylines. Think of a polyline as\n\"an open polygon\", that is, the last vertex is not connected to the first vertex (unless you\nexpressly add the same value as both points).\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **The Polyline Object**\n- **Updated Polygon Methods**\n- **New Polygon Methods**\n- **New GD::Image Methods**\n- **Examples**\n- **Future Features**\n- **Author**\n- **Copyright Information**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "GD::Polyline",
        "section": "",
        "mode": "perldoc",
        "summary": "GD::Polyline - Polyline object and Polygon utilities (including splines) for use with GD",
        "synopsis": "use GD;\nuse GD::Polyline;\n# create an image\n$image = GD::Image->new (500,300);\n$white  = $image->colorAllocate(255,255,255);\n$black  = $image->colorAllocate(  0,  0,  0);\n$red    = $image->colorAllocate(255,  0,  0);\n# create a new polyline\n$polyline = GD::Polyline->new;\n# add some points\n$polyline->addPt(  0,  0);\n$polyline->addPt(  0,100);\n$polyline->addPt( 50,125);\n$polyline->addPt(100,  0);\n# polylines can use polygon methods (and vice versa)\n$polyline->offset(200,100);\n# rotate 60 degrees, about the centroid\n$polyline->rotate(3.14159/3, $polyline->centroid());\n# scale about the centroid\n$polyline->scale(1.5, 2, $polyline->centroid());\n# draw the polyline\n$image->polydraw($polyline,$black);\n# create a spline, which is also a polyine\n$spline = $polyline->addControlPoints->toSpline;\n$image->polydraw($spline,$red);\n# output the png\nbinmode STDOUT;\nprint $image->png;",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 38,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 10,
                "subsections": []
            },
            {
                "name": "The Polyline Object",
                "lines": 28,
                "subsections": []
            },
            {
                "name": "Updated Polygon Methods",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "New Polygon Methods",
                "lines": 127,
                "subsections": []
            },
            {
                "name": "New GD::Image Methods",
                "lines": 20,
                "subsections": []
            },
            {
                "name": "Examples",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "Future Features",
                "lines": 16,
                "subsections": []
            },
            {
                "name": "Author",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "Copyright Information",
                "lines": 7,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "GD::Polyline - Polyline object and Polygon utilities (including splines) for use with GD\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use GD;\nuse GD::Polyline;\n\n# create an image\n$image = GD::Image->new (500,300);\n$white  = $image->colorAllocate(255,255,255);\n$black  = $image->colorAllocate(  0,  0,  0);\n$red    = $image->colorAllocate(255,  0,  0);\n\n# create a new polyline\n$polyline = GD::Polyline->new;\n\n# add some points\n$polyline->addPt(  0,  0);\n$polyline->addPt(  0,100);\n$polyline->addPt( 50,125);\n$polyline->addPt(100,  0);\n\n# polylines can use polygon methods (and vice versa)\n$polyline->offset(200,100);\n\n# rotate 60 degrees, about the centroid\n$polyline->rotate(3.14159/3, $polyline->centroid());\n\n# scale about the centroid\n$polyline->scale(1.5, 2, $polyline->centroid());\n\n# draw the polyline\n$image->polydraw($polyline,$black);\n\n# create a spline, which is also a polyine\n$spline = $polyline->addControlPoints->toSpline;\n$image->polydraw($spline,$red);\n\n# output the png\nbinmode STDOUT;\nprint $image->png;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "Polyline.pm extends the GD module by allowing you to create polylines. Think of a polyline as\n\"an open polygon\", that is, the last vertex is not connected to the first vertex (unless you\nexpressly add the same value as both points).\n\nFor the remainder of this doc, \"polyline\" will refer to a GD::Polyline, \"polygon\" will refer to\na GD::Polygon that is not a polyline, and \"polything\" and \"$poly\" may be either.\n\nThe big feature added to GD by this module is the means to create splines, which are\napproximations to curves.\n",
                "subsections": []
            },
            "The Polyline Object": {
                "content": "GD::Polyline defines the following class:\n\n\"GD::Polyline\"\nA polyline object, used for storing lists of vertices prior to rendering a polyline into an\nimage.\n\n\"new\"\n\"GD::Polyline->new\" *class method*\n\nCreate an empty polyline with no vertices.\n\n$polyline = GD::Polyline->new;\n\n$polyline->addPt(  0,  0);\n$polyline->addPt(  0,100);\n$polyline->addPt( 50,100);\n$polyline->addPt(100,  0);\n\n$image->polydraw($polyline,$black);\n\nIn fact GD::Polyline is a subclass of GD::Polygon, so all polygon methods (such as offset\nand transform) may be used on polylines. Some new methods have thus been added to\nGD::Polygon (such as rotate) and a few updated/modified/enhanced (such as scale) *in this\nmodule*. See section \"New or Updated GD::Polygon Methods\" for more info.\n\nNote that this module is very \"young\" and should be considered subject to change in future\nreleases, and/or possibly folded in to the existing polygon object and/or GD module.\n",
                "subsections": []
            },
            "Updated Polygon Methods": {
                "content": "The following methods (defined in GD.pm) are OVERRIDDEN if you use this module.\n\nAll effort has been made to provide 100% backward compatibility, but if you can confirm that has\nnot been achieved, please consider that a bug and let the the author of Polyline.pm know.\n\n\"scale\"\n\"$poly->scale($sx, $sy, $cx, $cy)\" *object method -- UPDATE to GD::Polygon::scale*\n\nScale a polything in along x-axis by $sx and along the y-axis by $sy, about centery point\n($cx, $cy).\n\nCenter point ($cx, $cy) is optional -- if these are omitted, the function will scale about\nthe origin.\n\nTo flip a polything, use a scale factor of -1. For example, to flip the polything top to\nbottom about line y = 100, use:\n\n$poly->scale(1, -1, 0, 100);\n",
                "subsections": []
            },
            "New Polygon Methods": {
                "content": "The following methods are added to GD::Polygon, and thus can be used by polygons and polylines.\n\nDon't forget: a polyline is a GD::Polygon, so GD::Polygon methods like offset() can be used, and\nthey can be used in GD::Image methods like filledPolygon().\n\n\"rotate\"\n\"$poly->rotate($angle, $cx, $cy)\" *object method*\n\nRotate a polything through $angle (clockwise, in radians) about center point ($cx, $cy).\n\nCenter point ($cx, $cy) is optional -- if these are omitted, the function will rotate about\nthe origin\n\nIn this function and other angle-oriented functions in GD::Polyline, positive $angle\ncorresponds to clockwise rotation. This is opposite of the usual Cartesian sense, but that\nis because the raster is opposite of the usual Cartesian sense in that the y-axis goes\n\"down\".\n\n\"centroid\"\n\"($cx, $cy) = $poly->centroid($scale)\" *object method*\n\nCalculate and return ($cx, $cy), the centroid of the vertices of the polything. For\nexample, to rotate something 180 degrees about it's centroid:\n\n$poly->rotate(3.14159, $poly->centroid());\n\n$scale is optional; if supplied, $cx and $cy are multiplied by $scale before returning. The\nmain use of this is to shift an polything to the origin like this:\n\n$poly->offset($poly->centroid(-1));\n\n\"segLength\"\n\"@segLengths = $poly->segLength()\" *object method*\n\nIn array context, returns an array the lengths of the segments in the polything. Segment n\nis the segment from vertex n to vertex n+1. Polygons have as many segments as vertices;\npolylines have one fewer.\n\nIn a scalar context, returns the sum of the array that would have been returned in the\narray context.\n\n\"segAngle\"\n\"@segAngles = $poly->segAngle()\" *object method*\n\nReturns an array the angles of each segment from the x-axis. Segment n is the segment from\nvertex n to vertex n+1. Polygons have as many segments as vertices; polylines have one\nfewer.\n\nReturned angles will be on the interval 0 <= $angle < 2 * pi and angles increase in a\nclockwise direction.\n\n\"vertexAngle\"\n\"@vertexAngles = $poly->vertexAngle()\" *object method*\n\nReturns an array of the angles between the segment into and out of each vertex. For\npolylines, the vertex angle at vertex 0 and the last vertex are not defined; however\n$vertexAngle[0] will be undef so that $vertexAngle[1] will correspond to vertex 1.\n\nReturned angles will be on the interval 0 <= $angle < 2 * pi and angles increase in a\nclockwise direction.\n\nNote that this calculation does not attempt to figure out the \"interior\" angle with respect\nto \"inside\" or \"outside\" the polygon, but rather, just the angle between the adjacent\nsegments in a clockwise sense. Thus a polygon with all right angles will have vertex angles\nof either pi/2 or 3*pi/2, depending on the way the polygon was \"wound\".\n\n\"toSpline\"\n\"$poly->toSpline()\" *object method & factory method*\n\nCreate a new polything which is a reasonably smooth curve using cubic spline algorithms,\noften referred to as Bezier curves. The \"source\" polything is called the \"control\npolything\". If it is a polyline, the control polyline must have 4, 7, 10, or some number of\nvertices of equal to 3n+1. If it is a polygon, the control polygon must have 3, 6, 9, or\nsome number of vertices of equal to 3n.\n\n$spline = $poly->toSpline();\n$image->polydraw($spline,$red);\n\nIn brief, groups of four points from the control polyline are considered \"control points\"\nfor a given portion of the spline: the first and fourth are \"anchor points\", and the spline\npasses through them; the second and third are \"director points\". The spline does not pass\nthrough director points, however the spline is tangent to the line segment from anchor\npoint to adjacent director point.\n\nThe next portion of the spline reuses the previous portion's last anchor point. The spline\nwill have a cusp (non-continuous slope) at an anchor point, unless the anchor points and\nits adjacent director point are colinear.\n\nIn the current implementation, toSpline() return a fixed number of segments in the returned\npolyline per set-of-four control points. In the future, this and other parameters of the\nalgorithm may be configurable.\n\n\"addControlPoints\"\n\"$polyline->addControlPoints()\" *object method & factory method*\n\nSo you say: \"OK. Splines sound cool. But how can I get my anchor points and its adjacent\ndirector point to be colinear so that I have a nice smooth curves from my polyline?\" Relax!\nFor The Lazy: addControlPoints() to the rescue.\n\naddControlPoints() returns a polyline that can serve as the control polyline for\ntoSpline(), which returns another polyline which is the spline. Is your head spinning yet?\nThink of it this way:\n\n+    If you have a polyline, and you have already put your control points where you want\nthem, call toSpline() directly. Remember, only every third vertex will be \"on\" the\nspline.\n\nYou get something that looks like the spline \"inscribed\" inside the control polyline.\n\n+    If you have a polyline, and you want all of its vertices on the resulting spline, call\naddControlPoints() and then toSpline():\n\n$control = $polyline->addControlPoints();\n$spline  = $control->toSpline();\n$image->polyline($spline,$red);\n\nYou get something that looks like the control polyline \"inscribed\" inside the spline.\n\nAdding \"good\" control points is subjective; this particular algorithm reveals its author's\ntastes. In the future, you may be able to alter the taste slightly via parameters to the\nalgorithm. For The Hubristic: please build a better one!\n\nAnd for The Impatient: note that addControlPoints() returns a polyline, so you can pile up\nthe call like this, if you'd like:\n\n$image->polyline($polyline->addControlPoints()->toSpline(),$mauve);\n",
                "subsections": []
            },
            "New GD::Image Methods": {
                "content": "\"polyline\"\n\"$image->polyline(polyline,color)\" *object method*\n\n$image->polyline($polyline,$black)\n\nThis draws a polyline with the specified color. Both real color indexes and the special\ncolors gdBrushed, gdStyled and gdStyledBrushed can be specified.\n\nNeither the polyline() method or the polygon() method are very picky: you can call either\nmethod with either a GD::Polygon or a GD::Polyline. The *method* determines if the shape is\n\"closed\" or \"open\" as drawn, *not* the object type.\n\n\"polydraw\"\n\"$image->polydraw(polything,color)\" *object method*\n\n$image->polydraw($poly,$black)\n\nThis method draws the polything as expected (polygons are closed, polylines are open) by\nsimply checking the object type and calling either $image->polygon() or $image->polyline().\n",
                "subsections": []
            },
            "Examples": {
                "content": "Please see file \"polyline-examples.pl\" that is included with the distribution.\n\nSee Also\nFor more info on Bezier splines, see http://www.webreference.com/dlab/9902/bezier.html.\n",
                "subsections": []
            },
            "Future Features": {
                "content": "On the drawing board are additional features such as:\n\n- polygon winding algorithms (to determine if a point is \"inside\" or \"outside\" the polygon)\n\n- new polygon from bounding box\n\n- find bounding polygon (tightest fitting simple convex polygon for a given set of vertices)\n\n- addPts() method to add many points at once\n\n- clone() method for polygon\n\n- functions to interwork GD with SVG\n\nPlease provide input on other possible features you'd like to see.\n",
                "subsections": []
            },
            "Author": {
                "content": "This module has been written by Daniel J. Harasty. Please send questions, comments, complaints,\nand kudos to him at harasty@cpan.org.\n\nThanks to Lincoln Stein for input and patience with me and this, my first CPAN contribution.\n",
                "subsections": []
            },
            "Copyright Information": {
                "content": "The Polyline.pm module is copyright 2002, Daniel J. Harasty. It is distributed under the same\nterms as Perl itself. See the \"Artistic License\" in the Perl source code distribution for\nlicensing terms.\n\nThe latest version of Polyline.pm is available at your favorite CPAN repository and/or along\nwith GD.pm by Lincoln D. Stein at http://stein.cshl.org/WWW/software/GD.\n",
                "subsections": []
            }
        }
    }
}