{"id":22542535,"url":"https://github.com/maumagnaguagno/polygonoid","last_synced_at":"2025-07-13T16:35:12.952Z","repository":{"id":91399659,"uuid":"72687306","full_name":"Maumagnaguagno/Polygonoid","owner":"Maumagnaguagno","description":":triangular_ruler: Geometric library for Ruby","archived":false,"fork":false,"pushed_at":"2024-12-26T00:41:53.000Z","size":219,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T22:51:44.217Z","etag":null,"topics":["2d","geometry","ruby","svg"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Maumagnaguagno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-02T22:36:01.000Z","updated_at":"2024-12-26T00:41:57.000Z","dependencies_parsed_at":"2023-11-23T12:28:40.270Z","dependency_job_id":"9660637b-a74c-4ef5-9b1b-616f9e82c308","html_url":"https://github.com/Maumagnaguagno/Polygonoid","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maumagnaguagno%2FPolygonoid","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maumagnaguagno%2FPolygonoid/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maumagnaguagno%2FPolygonoid/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Maumagnaguagno%2FPolygonoid/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Maumagnaguagno","download_url":"https://codeload.github.com/Maumagnaguagno/Polygonoid/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125643,"owners_count":21051766,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["2d","geometry","ruby","svg"],"created_at":"2024-12-07T13:10:49.284Z","updated_at":"2025-04-09T22:51:55.369Z","avatar_url":"https://github.com/Maumagnaguagno.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Polygonoid [![Actions Status](https://github.com/Maumagnaguagno/Polygonoid/workflows/build/badge.svg)](https://github.com/Maumagnaguagno/Polygonoid/actions)\n**Geometric library for Ruby**\n\nGeometric library currently restricted to 2D operations supporting few primitives, SVG output and Float comparison.\nOther libraries, such as [bfoz/geometry](https://github.com/bfoz/geometry) and [DanielVartanov/ruby-geometry](https://github.com/DanielVartanov/ruby-geometry), do not offer Float comparison and may fail due to [rounding errors](http://floating-point-gui.de/).\nSVG output also provides a nice way of checking what is happening inside the box.\n\n## API\n\n### [Polygonoid](Polygonoid.rb)\n- ``Numeric.approx(other, relative_epsilon = 0.001, epsilon = 0.001)`` compares with epsilon for robustness.\n- ``svg_grid(step = 10, style = 'fill:none;stroke:gray;stroke-width:0.5')`` returns a SVG grid pattern with cells of size ``step``.\n- ``svg_text(x, y, text, style = 'font-family:Helvetica;font-size:8px')`` returns a SVG text element at the specified position.\n- ``svg_save(filename, svg, options = nil)`` saves SVG to file ``filename`` with specified ``options``.\n\n---\n\n### [Point class](src/Point.rb)\n**Attributes:**\n- ``attr_reader :x`` is the horizontal position along the X axis.\n- ``attr_reader :y`` is the vertical position along the Y axis.\n\n**Methods:**\n- ``initialize(x, y)`` creates an instance with the given ``x`` and ``y`` coordinates.\n- ``==(other)`` returns ``true`` if ``self`` is approximately equal to ``other`` point, ``false`` otherwise.\n- ``distance(other)`` returns distance to ``other`` point.\n- ``to_svg(style = 'fill:none;stroke:black;stroke-width:0.5')`` returns string with SVG description.\n\n---\n\n### [Line class](src/Line.rb)\n**Attributes:**\n- ``attr_reader :from`` is the segment origin, a point instance.\n- ``attr_reader :to`` is the segment end, a point instance.\n- ``attr_reader :slope`` the ratio between the y-change over the x-change of the origin and end points.\n- ``attr_reader :y_intercept`` is the position where the line intercepts the Y axis, ``nil`` for vertical lines.\n\n**Methods:**\n- ``initialize(from, to)`` creates an instance with the given ``from`` and ``to`` points.\n- ``==(other)`` returns ``true`` if ``self`` is approximately equal to ``other`` line, ``false`` otherwise.\n- ``perimeter`` returns distance between ``from`` and ``to``.\n- ``x_intercept`` returns position where ``self`` intercepts the X axis, ``nil`` for horizontal lines.\n- ``vertical?`` returns ``true`` if ``self`` is vertical, ``false`` otherwise.\n- ``horizontal?`` returns ``true`` if ``self`` is horizontal, ``false`` otherwise.\n- ``parallel_to?(other)`` returns ``true`` if ``self`` is parallel to ``other`` line, ``false`` otherwise.\n- ``point_side(point)`` returns less or greater than zero according to which side of ``self`` the ``point`` is, ``0`` if on ``self``.\n- ``contain_point?(point)`` returns ``true`` if ``point`` is on ``self``, ``false`` otherwise.\n- ``segment_contain_point?(point)`` returns ``true`` if ``point`` is on ``self``, ``false`` otherwise.\n- ``distance_to_point(point)`` returns distance between ``self`` and ``point``.\n- ``segment_distance_to_point(point)`` returns distance between ``self`` segment and ``point``.\n- ``intersect_line(other)`` returns intersection point of ``self`` and ``other`` line, ``self.from`` if coincident, ``nil`` if none.\n- ``intersect_line_non_vertical(other)`` faster than ``intersect_line(other)``, only applicable to non-vertical lines.\n- ``intersect_line_angle(other)`` returns angle between lines based on their slope.\n- ``to_svg(style = 'stroke:black')`` returns string with SVG description.\n\n---\n\n### [Polyline class](src/Polyline.rb)\n**Attributes:**\n- ``attr_reader :vertices`` is an array of point instances.\n- ``attr_reader :edges`` is an array of line instances.\n\n**Methods:**\n- ``initialize(*vertices)`` creates an instance with the given array of ``vertices``, each vertice is a point instance.\n- ``perimeter`` returns the sum of edge perimeters.\n- ``contain_point?(point)`` returns ``true`` if ``point`` is on ``self``, ``false`` otherwise.\n- ``to_svg(style = 'fill:none;stroke:black')`` returns string with SVG description.\n\n---\n\n### [Polygon class](src/Polygon.rb)\n**Attributes:**\n- ``attr_reader :vertices`` is an array of point instances.\n- ``attr_reader :edges`` is an array of line instances, last vertex is connected to first vertex.\n\n**Methods:**\n- ``initialize(*vertices)`` creates an instance with the given array of ``vertices``, each vertice is a point instance.\n- ``area`` returns area of simple polygon ``self``.\n- ``center`` returns centroid point of ``self``.\n- ``contain_point?(point)`` returns ``true`` if ``point`` is within area of ``self``, ``false`` otherwise.\n- ``to_svg(style = 'fill:gray;stroke:black')`` returns string with SVG description.\n\n---\n\n### [Circle class](src/Circle.rb)\n**Attributes:**\n- ``attr_reader :x`` is the center position along the X axis.\n- ``attr_reader :y`` is the center position along the Y axis.\n- ``attr_reader :radius`` is how far the circle extends from the center position ``x`` and ``y``.\n\n**Methods:**\n- ``initialize(x, y, radius)`` creates an instance with center at ``x`` and ``y`` with ``radius``.\n- ``==(other)`` returns ``true`` if ``self`` is approximately equal to ``other`` circle, ``false`` otherwise.\n- ``perimeter`` returns perimeter/circumference of ``self``.\n- ``area`` returns area of ``self``.\n- ``contain_point?(point)`` returns ``true`` if ``point`` is within area of ``self``, ``false`` otherwise.\n- ``distance_to_point(point)`` returns distance between ``self`` border and ``point``.\n- ``to_svg(style = 'fill:gray;stroke:black')`` returns string with SVG description.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaumagnaguagno%2Fpolygonoid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaumagnaguagno%2Fpolygonoid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaumagnaguagno%2Fpolygonoid/lists"}