Coder Social home page Coder Social logo

ruby-geometry's Introduction

Geometry in Ruby

Implementation of basic 2D geometry algorithms in Ruby.

Installation

gem 'ruby-geometry', require: 'geometry'

Defined geometry objects

  • Point

  • Segment

  • Vector

  • Polygon

  • Line

Already implemented algorithms

  • Area of convex polygon Polygon#area

  • Distance from point to a line or segment Line#distance_to(point), Segment#distance_to(point)

  • Do segments overlap? Segments#overlaps?

  • Do segments lie on one line? Segment#lies_on_one_line_with?

  • Do segments intersect? Segment#intersects_with?

  • Segments intersection point Segment#intersection_point_with

  • Does segment contain given point? Segment#contains_point?

  • Are segments parallel? Segment#parallel_to?

  • Are vectors collinear? Vector#collinear_with?

  • Vectors cross product (outer product, vector product) Vector#cross_product

  • Vectors scalar product (inner product, dot product) Vector#scalar_product

  • Segment length Segment#length

  • Vector modulus Vector#modulus

  • Trivial vector arithmetics: summation, subtraction, vector-number multiplication Vector#+(vector); Vector#-(vector); Vector#*(numeric)

  • Euclid distance Geometry#distance

  • Line slope Line#slope

  • Y-intercept of a line Line#y_intercept

  • X-intercept of a line Line#x_intercept

  • Are lines parallel? Line#parallel_to?

  • What x-value do lines intersect at? Line#intersect_x

  • What is the angle between two lines? Line#angle_to

  • Rectangular bounds of polygon Polygon#bounding_box

  • Does polygon contain a given point? Polygon#contains?

Coming up

  • Is polygon self-intersecting?

  • Is polygon convex?

  • Do polygons intersect?

  • Does circle contain given point?

  • Do circles intersect?

Copyright (c) 2008 Daniel Vartanov, released under the MIT license

ruby-geometry's People

Contributors

danielvartanov avatar iqre8 avatar jayjlawrence avatar kaczowkad avatar kmmndr avatar pikachuexe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ruby-geometry's Issues

Gem files in load path can interfere with project files

When using ruby geometry in our project, the following entry is added to the ruby load path:

"/Users/amuino/.rvm/gems/ruby-2.1.6@cabify/gems/ruby-geometry-0.0.5/lib"

The issue is that the folder contains several files that shadow our own (or viceversa, depending on how we setup the load path) when using require. One such files is point.rb (we have our own point.rb in the project).

Just to clarify, this is not a problem with class names (we use Point, the gem provides Geometry::Point) but with loading of files.

A common practice with gems is to package the files in a subfolder (except for the main file).

This would translate into having:

lib/geometry.rb
lib/geometry/point.rb
lib/geometry/...
...

I can work on a PR for the changes, but first wanted to confirm that it is ok to follow this path.

PointInPolygon#choose_good_ray is too slow

I have modified PointInPolygon#point_location to use random_ray directly instead
Then it becomes very fast for me

And the result is acceptable too (observed on a map with markers and polygons)

So I wonder if it's possible to add an option to pass when calculating

I might make a PR later

Deprecated ActiveSupport::Memoizable

Hi

We got the follwowing warning, with the latest releases of ActiveSupport :

DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future releases,simply use Ruby memoization pattern instead. (called from require at [...]/gems/bundler-1.1.4/lib/bundler/runtime.rb:68)

Rails 3.2.0 says :

Deprecated ActiveSupport::Memoizable in favor of Ruby memoization pattern

Polygon.contains? bug

arr = [Geometry::Point.new(1.6, 1.0), Geometry::Point.new(1.6, 2.0), 
     Geometry::Point.new(1.2, 2.0), Geometry::Point.new(1.2, 1.0)]
point = Geometry::Point.new(1.5, 1.5)
result = Geometry::Polygon.new(arr).contains?(point)

Result = true. It's ok. But:

arr = [Geometry::Point.new(1.6, 1.0), Geometry::Point.new(1.6, 2.0),
     Geometry::Point.new(1.2, 2.0), Geometry::Point.new(1.2, 1.0)]
point = Geometry::Point.new(1.5, 1.5)
result = Geometry::Polygon.new(arr).contains?(point)
(0..100).each{result &&= Geometry::Polygon.new(arr).contains?(point)}

result = false

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.