// Copyright ©2016 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package vg

// A Point is a location in 2d space.
//
// Points are used for drawing, not for data.  For
// data, see the XYer interface.
type Point struct {
	X, Y Length
}

// Dot returns the dot product of two points.
func ( Point) ( Point) Length {
	return .X*.X + .Y*.Y
}

// Add returns the component-wise sum of two points.
func ( Point) ( Point) Point {
	return Point{.X + .X, .Y + .Y}
}

// Sub returns the component-wise difference of two points.
func ( Point) ( Point) Point {
	return Point{.X - .X, .Y - .Y}
}

// Scale returns the component-wise product of a point and a scalar.
func ( Point) ( Length) Point {
	return Point{.X * , .Y * }
}

// A Rectangle represents a rectangular region of 2d space.
type Rectangle struct {
	Min Point
	Max Point
}

// Size returns the width and height of a Rectangle.
func ( Rectangle) () Point {
	return Point{
		X: .Max.X - .Min.X,
		Y: .Max.Y - .Min.Y,
	}
}

// Add returns the rectangle r translated by p.
func ( Rectangle) ( Point) Rectangle {
	return Rectangle{
		Min: .Min.Add(),
		Max: .Max.Add(),
	}
}

// Path returns the path of a Rect specified by its
// upper left corner, width and height.
func ( Rectangle) () ( Path) {
	.Move(.Min)
	.Line(Point{X: .Max.X, Y: .Min.Y})
	.Line(.Max)
	.Line(Point{X: .Min.X, Y: .Max.Y})
	.Close()
	return
}