|
-
Aug 24th, 2021, 06:52 AM
#6
Re: [RESOLVED] Rotating an array of points clockwise 90, 180, and 270 degrees
 Originally Posted by .paul.
Problem resolved... I managed to get myself tied up in point arrays. Didn't realise i already had the answer
Code:
Public Shared Function PlusNinety(ByVal p() As Point) As Point()
Dim newPoints() As Point = Array.ConvertAll(p, Function(pt) New Point(-pt.Y, pt.X))
Dim o As Integer = newPoints.Min(Function(pt2) pt2.X)
Return Array.ConvertAll(newPoints, Function(pt) New Point(pt.X - o, pt.Y))
End Function
Public Shared Function MinusNinety(ByVal p() As Point) As Point()
Dim newPoints() As Point = Array.ConvertAll(p, Function(pt) New Point(pt.Y, -pt.X))
Dim o As Integer = newPoints.Min(Function(pt2) pt2.Y)
Return Array.ConvertAll(newPoints, Function(pt) New Point(pt.X, pt.Y - o))
End Function
Public Shared Function PlusOneEighty(ByVal p() As Point) As Point()
Dim o As Integer = p.Max(Function(pt2) pt2.Y)
Return Array.ConvertAll(p, Function(pt) New Point(pt.X, o - pt.Y))
End Function
Do you think making these extension methods will make the code more clean? (sorry to rename your function names but for me digits are more readable )
VB.NET Code:
p1.Rotate180()
p2.RotateMinus90()
p3.RotatePlus90()
Code:
Imports System.Runtime.CompilerServices
Module PointsArrayExtensions
<Extension()>
Public Function RotatePlus90(ByVal p() As Point) As Point()
Dim newPoints() As Point = Array.ConvertAll(p, Function(pt) New Point(-pt.Y, pt.X))
Dim o As Integer = newPoints.Min(Function(pt2) pt2.X)
Return Array.ConvertAll(newPoints, Function(pt) New Point(pt.X - o, pt.Y))
End Function
<Extension()>
Public Shared Function RotateMinus90(ByVal p() As Point) As Point()
Dim newPoints() As Point = Array.ConvertAll(p, Function(pt) New Point(pt.Y, -pt.X))
Dim o As Integer = newPoints.Min(Function(pt2) pt2.Y)
Return Array.ConvertAll(newPoints, Function(pt) New Point(pt.X, pt.Y - o))
End Function
<Extension()>
Public Function Rotate180(ByVal p() As Point) As Point()
Dim o As Integer = p.Max(Function(pt2) pt2.Y)
Return Array.ConvertAll(p, Function(pt) New Point(pt.X, o - pt.Y))
End Function
End Module
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|