Documentation ¶
Overview ¶
Package r2 implements types and functions for working with geometry in ℝ².
See package s2 for a more detailed overview.
- Copyright 2005 Google Inc. *
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at *
- http://www.apache.org/licenses/LICENSE-2.0 *
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
Index ¶
- type Point
- type Rect
- func (r Rect) AddPoint(p Point) Rect
- func (r Rect) AddRect(other Rect) Rect
- func (r Rect) ApproxEquals(r2 Rect) bool
- func (r Rect) Center() Point
- func (r Rect) ClampPoint(p Point) Point
- func (r Rect) Contains(other Rect) bool
- func (r Rect) ContainsPoint(p Point) bool
- func (r Rect) Expanded(margin Point) Rect
- func (r Rect) ExpandedByMargin(margin float64) Rect
- func (r Rect) InteriorContains(other Rect) bool
- func (r Rect) InteriorContainsPoint(p Point) bool
- func (r Rect) InteriorIntersects(other Rect) bool
- func (r Rect) Intersection(other Rect) Rect
- func (r Rect) Intersects(other Rect) bool
- func (r Rect) IsEmpty() bool
- func (r Rect) IsValid() bool
- func (r Rect) Size() Point
- func (r Rect) String() string
- func (r Rect) Union(other Rect) Rect
- func (r Rect) Vertices() [4]Point
- type Vector
- func (v Vector) Abs() Vector
- func (v Vector) Add(ov Vector) Vector
- func (v Vector) CompareTo(other Vector) int
- func (v Vector) Cross(ov Vector) float64
- func (v Vector) Div(m float64) Vector
- func (v Vector) Dot(ov Vector) float64
- func (v Vector) Equals(other Vector) bool
- func (v Vector) LessThan(vb Vector) bool
- func (v Vector) Mul(m float64) Vector
- func (v Vector) Neg() Vector
- func (v Vector) Norm() float64
- func (v Vector) Norm2() float64
- func (v Vector) Normalize() Vector
- func (v Vector) String() string
- func (v Vector) Sub(ov Vector) Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Rect ¶
Rect represents a closed axis-aligned rectangle in the (x,y) plane.
func EmptyRect ¶
func EmptyRect() Rect
EmptyRect constructs the canonical empty rectangle. Use IsEmpty() to test for empty rectangles, since they have more than one representation. A Rect{} is not the same as the EmptyRect.
func RectFromCenterSize ¶
RectFromCenterSize constructs a rectangle with the given center and size. Both dimensions of size must be non-negative.
func RectFromPoints ¶
RectFromPoints constructs a rect that contains the given points.
func (Rect) AddPoint ¶
AddPoint expands the rectangle to include the given point. The rectangle is expanded by the minimum amount possible.
func (Rect) AddRect ¶
AddRect expands the rectangle to include the given rectangle. This is the same as replacing the rectangle by the union of the two rectangles, but is more efficient.
func (Rect) ApproxEquals ¶
ApproxEquals returns true if the x- and y-intervals of the two rectangles are the same up to the given tolerance.
func (Rect) ClampPoint ¶
ClampPoint returns the closest point in the rectangle to the given point. The rectangle must be non-empty.
func (Rect) ContainsPoint ¶
ContainsPoint reports whether the rectangle contains the given point. Rectangles are closed regions, i.e. they contain their boundary.
func (Rect) Expanded ¶
Expanded returns a rectangle that has been expanded in the x-direction by margin.X, and in y-direction by margin.Y. If either margin is empty, then shrink the interval on the corresponding sides instead. The resulting rectangle may be empty. Any expansion of an empty rectangle remains empty.
func (Rect) ExpandedByMargin ¶
ExpandedByMargin returns a Rect that has been expanded by the amount on all sides.
func (Rect) InteriorContains ¶
InteriorContains reports whether the interior of this rectangle contains all of the points of the given other rectangle (including its boundary).
func (Rect) InteriorContainsPoint ¶
InteriorContainsPoint returns true iff the given point is contained in the interior of the region (i.e. the region excluding its boundary).
func (Rect) InteriorIntersects ¶
InteriorIntersects reports whether the interior of this rectangle intersects any point (including the boundary) of the given other rectangle.
func (Rect) Intersection ¶
Intersection returns the smallest rectangle containing the intersection of this rectangle and the given rectangle.
func (Rect) Intersects ¶
Intersects reports whether this rectangle and the other rectangle have any points in common.
func (Rect) IsValid ¶
IsValid reports whether the rectangle is valid. This requires the width to be empty iff the height is empty.
func (Rect) Size ¶
Size returns the width and height of this rectangle in (x,y)-space. Empty rectangles have a negative width and height.
type Vector ¶
type Vector struct {
X, Y float64
}
*
- r2.Vector represents a vector in the two-dimensional space. It defines the
- basic geometrical operations for 2D vectors, e.g. cross product, addition,
- norm, comparison etc. *