{"id":20550228,"url":"https://github.com/dnmfarrell/math-shape-vector","last_synced_at":"2026-07-18T00:07:09.481Z","repository":{"id":20276282,"uuid":"23549469","full_name":"dnmfarrell/Math-Shape-Vector","owner":"dnmfarrell","description":"2d vector library in cartesian space","archived":false,"fork":false,"pushed_at":"2015-10-01T18:14:21.000Z","size":288,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-14T16:07:21.523Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://metacpan.org/pod/Math::Shape::Vector","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dnmfarrell.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-01T16:59:02.000Z","updated_at":"2014-09-20T21:51:18.000Z","dependencies_parsed_at":"2022-08-27T03:08:01.532Z","dependency_job_id":null,"html_url":"https://github.com/dnmfarrell/Math-Shape-Vector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dnmfarrell/Math-Shape-Vector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FMath-Shape-Vector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FMath-Shape-Vector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FMath-Shape-Vector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FMath-Shape-Vector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dnmfarrell","download_url":"https://codeload.github.com/dnmfarrell/Math-Shape-Vector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dnmfarrell%2FMath-Shape-Vector/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019556,"owners_count":26086749,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-11-16T02:23:56.396Z","updated_at":"2025-10-14T16:07:22.878Z","avatar_url":"https://github.com/dnmfarrell.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=encoding UTF-8\n\n=head1 NAME\n\nMath::Shape::Vector - A 2d vector library in cartesian space\n\n=head1 VERSION\n\nversion 0.15\n\n=head1 SYNOPSIS\n\n    use Math::Shape::Vector;\n\n    my $v1 = Math::Shape::Vector-\u003enew(3, 5);\n    my $v2 = Math::Shape::Vector-\u003enew(1, 17);\n\n    $v1-\u003eadd_vector($v2);\n    $v1-\u003enegate;\n    $v1-\u003emultiply(5);\n    $v1-\u003eis_equal($v2);\n\n=head1 DESCRIPTION\n\nThis module contains 2d vector-based objects intended as base classes for 2d games programming. Most of the objects have collision detection (among other methods). All objects are immutable in so far as their methods return new objects everytime. The objects available are:\n\n=over\n\n=item *\n\nL\u003cMath::Shape::Vector\u003e - a 2d vector (this package)\n\n=item *\n\nL\u003cMath::Shape::Line\u003e - an infinite 2d line\n\n=item *\n\nL\u003cMath::Shape::LineSegment\u003e - a finite 2d line (with a start and end)\n\n=item *\n\nL\u003cMath::Shape::Range\u003e - a number range (e.g 1 through 20)\n\n=item *\n\nL\u003cMath::Shape::Circle\u003e - a 2d Circle\n\n=item *\n\nL\u003cMath::Shape::Rectangle\u003e - a 2d axis-oriented rectangle\n\n=item *\n\nL\u003cMath::Shape::OrientedRectangle\u003e - a 2d oriented rectangle\n\n=back\n\n=for HTML \u003ca href=\"https://travis-ci.org/sillymoose/Math-Shape-Vector\"\u003e\u003cimg src=\"https://travis-ci.org/sillymoose/Math-Shape-Vector.svg?branch=master\"\u003e\u003c/a\u003e \u003ca href='https://coveralls.io/r/sillymoose/Math-Shape-Vector'\u003e\u003cimg src='https://coveralls.io/repos/sillymoose/Math-Shape-Vector/badge.png' alt='Coverage Status' /\u003e\u003c/a\u003e\n\n=head1 METHODS\n\n=head2 new\n\nCreate a new vector. Requires two numerical arguments for the origin and magnitude.\n\n    my $vector = Math::Shape::Vector-\u003enew(3, 5);\n\n=head2 add_vector\n\nAdds a vector to the vector object, returning a new vector object with the resulting x \u0026 y values.\n\n    my $new_vector = $vector-\u003eadd_vector($vector_2);\n\n=head2 subtract_vector\n\nSubtracts a vector from the vector object, returning a new vector object with the resulting x \u0026 y values.\n\n    my $new_vector = $vector-\u003esubtract_vector($vector_2);\n\n=head2 negate\n\nReturns a new vector with negated values values e.g. (1,3) becomes (-1, -3).\n\n    my $new_vector = $vector-\u003enegate();\n\n=head2 is_equal\n\nCompares a vector to the vector object, returning 1 if they are the same or 0 if they are different.\n\n    $vector-\u003eis_equal($vector_2);\n\n=head2 multiply\n\nReturns a new vector object with the x and y values multiplied by a number.\n\n    my $new_vector = $vector-\u003emultiply(3);\n\n=head2 divide\n\nReturns a new vector object with the x and y values divided by a number.\n\n    my $new_vector = $vector-\u003edivide(2);\n\n=head2 rotate\n\nReturns a new vector with the x and y values rotated in radians.\n\n    use Math::Trig ':pi';\n\n    my $new_vector = $vector-\u003erotate(pi);\n\n=head2 rotate_90\n\nReturns a new vector object with the x and y values rotated 90 degrees anti-clockwise.\n\n    my $new_vector = $vector-\u003erotate_90;\n\n=head2 dot_product\n\nReturns the dot product. Requires another Math::Shape::Vector object as an argument.\n\n=head2 length\n\nReturns the vector length.\n\n    my $length = $vector-\u003elength;\n\nUseful if you want to calculate the distance between two vectors:\n\n    my $vector_c = $vector_a-\u003esubtract_vector($vector_b);\n    my $distance_a_to_b = $vector_c-\u003elength;\n\n=head2 convert_to_unit_vector\n\nReturns a new vector object with a length of 1 (aka a normalized vector).\n\n    my $unit_vector = $vector-\u003econvert_to_unit_vector;\n\n=head2 project\n\nMaps the vector to another vector, returning a new vector object. Requires a Math::Shape::Vector object as an argument.\n\n    my $new_vector = $vector-\u003eproject($vector_2);\n\n=head2 is_parallel\n\nBoolean method that returns 1 if the vector is parallel with another vector else returns zero. Requires a Math::Shape::Vector object as an argument.\n\n    my $v2 = Math::Shape::Vector(1, 2);\n\n    if ($v-\u003eis_parallel($v2))\n    {\n        # do something\n    }\n\n=head2 enclosed_angle\n\nReturns the enclosed angle of another vector. Requires a Math::Shape::Vector object as an argument.\n\n    my $v2 = Math::Shape::Vector(4, 2);\n    my $enclosed_angle = $v-\u003eenclosed_angle($v2);\n\n=head2 radians\n\nReturns the angle of the vector expressed in radians (0 - 2 pi).\n\n    $vector-\u003eradians;\n\n=head2 header_vector\n\nReturns a unit (normalized) vector representing the direction towards another vector. This header_vector can be converted into radians using the C\u003cradians\u003e method. Requires an L\u003cMath::Shape::Vector\u003e object as an argument.\n\n    my $header_vector = $vector_a-\u003eheader_vector($vector_b);\n    my $radians_a_to_b = $header_vector-\u003eradians;\n\n=head2 collides\n\nBoolean method that returns 1 if the vector collides with another L\u003cMath::Shape::Vector\u003e library object or not or 0 if not. Requires a Math::Shape::Vectorlibrary object as an argument\n\n    my $v1 = Math::Shape::Vector(4, 2);\n    my $v2 = Math::Shape::Vector(4, 2);\n\n    $v1-\u003ecollides($v2); # 1\n\n    my $circle = Math::Shape::Circle-\u003enew(0, 0, 3); # x, y and radius\n    $v1-\u003ecollides($circle); # 0\n\n=head2 distance\n\nReturns the distance from the vector to the nearest point of another shape. Requires an L\u003cMath::Shape::Vector\u003e library object as an argument. Currently only implemented for vector and circle objects. For OrientedRectangle objects, distance uses the distance to the circle hull of the OrientedRectangle (not completely accurate).\n\n    my $distance = $vector-\u003edistance($other_vector);\n\n=head1 REPOSITORY\n\nL\u003chttps://github.com/sillymoose/Math-Shape-Vector.git\u003e\n\n=head1 THANKS\n\nThe source code for this class was inspired by the code in Thomas Schwarzl's 2d collision detection book L\u003chttp://www.collisiondetection2d.net\u003e.\n\n=head1 AUTHOR\n\nDavid Farrell \u003cdfarrell@cpan.org\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2015 by David Farrell.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnmfarrell%2Fmath-shape-vector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdnmfarrell%2Fmath-shape-vector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdnmfarrell%2Fmath-shape-vector/lists"}