Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell-cafe] An Haskell implementation of a sweep line algorithm for the detection of segments intersection

55 views
Skip to first unread message

vince vegga

unread,
Dec 6, 2010, 11:10:59 AM12/6/10
to haskel...@haskell.org
Hi,

Here is my Haskell implementation of the Shamos and Hoey algorithm for
detecting segments intersection in the plane:

http://neonstorm242.blogspot.com/2010/12/sweep-line-algorithm-for-detection-of.html

I'm new to Haskell, so any useful comments will be appreciated.

- Eran

Serguey Zefirov

unread,
Dec 6, 2010, 11:40:24 AM12/6/10
to vince vegga, haskel...@haskell.org
2010/12/6 vince vegga <megat...@gmail.com>:

> Here is my Haskell implementation of the Shamos and Hoey algorithm for
> detecting segments intersection in the plane:
>
> http://neonstorm242.blogspot.com/2010/12/sweep-line-algorithm-for-detection-of.html

Quite good, actually.

Myself, I rarely write code that is on par with yours. ;)

_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Henning Thielemann

unread,
Dec 7, 2010, 3:22:38 PM12/7/10
to vince vegga, haskel...@haskell.org

In sweepLine, things like

| a = False
| otherwise = x

can be written as (not a && x) and

if a then True else x

as (a || x).


In handleLeftEndpoint you can create (events,updateLine) outside the case
analysis, since this is common to all cases.

In general you can find hints in:
http://www.haskell.org/haskellwiki/Haskell_programming_tips
and in
http://www.haskell.org/haskellwiki/Category:Style

smkh...@gmail.com

unread,
Apr 7, 2012, 3:41:25 PM4/7/12
to vince vegga, haskel...@haskell.org
Hi, I tried the above algorithm with some inputs such as [((1.25, 1), (2.85, 3.8)), ((4.5, 2.13), (1.75, 2.65)), ((1.5, 0.5), (3.5, 2.5))] but I get the following error: "Program error: Map.findIndex: element is not in the map"

May I know what the problem is? The algorithm seems to work for some other inputs though.
0 new messages