Results 1 to 3 of 3

Thread: [RESOLVED] match a range of points?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    216

    Resolved [RESOLVED] match a range of points?

    Edit :
    nvm
    Last edited by CWITT; Aug 3rd, 2020 at 09:31 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: [RESOLVED] match a range of points?

    What does it even mean for a Point to be greater than or less than another Point? The Point structure doesn't implement IComparable for a reason. There is no standard meaning to a Point being "within a range" but I can think of two meanings that could be used in specific scenarios. It might mean for a Point to be on the line between two other Points or it might mean for a Point to be within the rectangle described by the other two Points. I'm guessing that you mean the latter. If so, I'd probably write the following extension method:
    vb.net Code:
    1. Imports System.Runtime.CompilerServices
    2.  
    3. Public Module PointExtensions
    4.  
    5.     <Extension>
    6.     Public Function IsInRange(source As Point, start As Point, [end] As Point) As Boolean
    7.         Dim box As New Rectangle(Math.Min(start.X, [end].X),
    8.                                  Math.Min(start.Y, [end].Y),
    9.                                  Math.Abs(start.X - [end].X),
    10.                                  Math.Abs(start.Y - [end].Y))
    11.  
    12.         Return box.Contains(source)
    13.     End Function
    14.  
    15. End Module
    You can then do this:
    vb.net Code:
    1. Dim p1 As New Point(1, 4)
    2. Dim p2 As New Point(0, 3)
    3. Dim p3 As New Point(8, 10)
    4.  
    5. If p1.IsInRange(p2, p3) Then
    6.     '...
    7. End If
    If "within a range" means something different to you, you just change the implementation of the IsInRange method.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2016
    Posts
    216

    Re: [RESOLVED] match a range of points?

    yea, the rectangle idea is where i was going with it.. and i had a similar function already for another program. But for whatever reason I kept dismissing it as unusable. It wasn't till i posted that I finally saw that it would work.

    TY for another approach though, will add it to my options list

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width