cleanup and optimization for Point.OnSegment
This commit is contained in:
parent
ad4d483bf8
commit
0fe8a6b5f0
1 changed files with 17 additions and 3 deletions
|
|
@ -199,9 +199,23 @@ func (p *Point) FormattedCoordinates() string {
|
||||||
return fmt.Sprintf("%d,%d", int(p.X), int(p.Y))
|
return fmt.Sprintf("%d,%d", int(p.X), int(p.Y))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Point) OnSegment(p, r *Point) bool {
|
// returns true if point p is on orthogonal segment between points a and b
|
||||||
return (q.X <= math.Max(p.X, r.X)) && (q.X >= math.Min(p.X, r.X)) &&
|
func (p *Point) OnOrthogonalSegment(a, b *Point) bool {
|
||||||
(q.Y <= math.Max(p.Y, r.Y)) && (q.Y >= math.Min(p.Y, r.Y))
|
if a.X < b.X {
|
||||||
|
if p.X < a.X || b.X < p.X {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else if p.X < b.X || a.X < p.X {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if a.Y < b.Y {
|
||||||
|
if p.Y < a.Y || b.Y < p.Y {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
} else if p.Y < b.Y || a.Y < p.Y {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a Vector pointing to point
|
// Creates a Vector pointing to point
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue