Documentation ¶
Overview ¶
Package geom provides geometric primitives and containers
Index ¶
- type Board
- func (gb *Board) AddCircle(c *Circle)
- func (gb *Board) AddCircleTrace(c *Circle)
- func (gb *Board) AddHalfLine(h *HalfLine)
- func (gb *Board) AddLine(l *Line)
- func (gb *Board) AddLineTrace(l *Line)
- func (gb *Board) AddPoint(pt *Point)
- func (gb *Board) AddSegment(s *Segment)
- func (gb *Board) Clone() *Board
- func (gb *Board) GeneratePlot(folderName string) error
- func (gb *Board) GenerateRandomPoints() []*Point
- func (gb *Board) GenerateSinglePlot(fileName string, highlight bool) error
- func (gb *Board) RemoveLastGeometryObject()
- type Circle
- func (c *Circle) ContainsPoint(pt *Point) bool
- func (c *Circle) GetCenter() *Point
- func (c *Circle) GetRadius() float64
- func (c *Circle) GetRandomPoint() *Point
- func (c *Circle) IntersectCircle(c2 *Circle) *Intersection
- func (c *Circle) IntersectHalfLine(h *HalfLine) *Intersection
- func (c *Circle) IntersectLine(l *Line) *Intersection
- func (c *Circle) IntersectSegment(s *Segment) *Intersection
- func (c *Circle) Serialize() interface{}
- type HalfLine
- func (h *HalfLine) ContainsPoint(pt *Point) bool
- func (h *HalfLine) GetEndPoint() *Point
- func (h *HalfLine) GetRandomPoint() *Point
- func (h *HalfLine) IntersectCircle(c *Circle) *Intersection
- func (h *HalfLine) IntersectHalfLine(h2 *HalfLine) *Intersection
- func (h *HalfLine) IntersectLine(l *Line) *Intersection
- func (h *HalfLine) IntersectSegment(s *Segment) *Intersection
- func (h *HalfLine) PointInRange(pt *Point) bool
- func (h *HalfLine) Serialize() interface{}
- type Intersection
- type Line
- func (l *Line) ContainsPoint(pt *Point) bool
- func (l *Line) GetNormalVector() *Vector2D
- func (l *Line) GetParallelLineWithPoint(pt *Point) *Line
- func (l *Line) GetParallelVector() *Vector2D
- func (l *Line) GetRandomPoint() *Point
- func (l *Line) GetTangentLineWithPoint(pt *Point) *Line
- func (l *Line) IntersectCircle(c *Circle) *Intersection
- func (l *Line) IntersectHalfLine(h *HalfLine) *Intersection
- func (l *Line) IntersectLine(l2 *Line) *Intersection
- func (l *Line) IntersectSegment(s *Segment) *Intersection
- func (l *Line) Serialize() interface{}
- type Point
- func (pt *Point) DistanceToLine(l *Line) float64
- func (pt *Point) Equal(pt2 *Point) bool
- func (pt *Point) GetCoords() (float64, float64)
- func (pt *Point) InHalfLineRange(h *HalfLine) bool
- func (pt *Point) InSegmentRange(s *Segment) bool
- func (pt *Point) OnCircle(c *Circle) bool
- func (pt *Point) OnHalfLine(h *HalfLine) bool
- func (pt *Point) OnLine(l *Line) bool
- func (pt *Point) OnSegment(s *Segment) bool
- func (pt *Point) Serialize() interface{}
- type Segment
- func (s *Segment) Bisector() *Line
- func (s *Segment) ContainsPoint(pt *Point) bool
- func (s *Segment) GetEndPoints() (*Point, *Point)
- func (s *Segment) GetRandomPoint() *Point
- func (s *Segment) IntersectCircle(c *Circle) *Intersection
- func (s *Segment) IntersectHalfLine(h *HalfLine) *Intersection
- func (s *Segment) IntersectLine(l *Line) *Intersection
- func (s *Segment) IntersectSegment(s2 *Segment) *Intersection
- func (s *Segment) Length() float64
- func (s *Segment) PointInRange(pt *Point) bool
- func (s *Segment) Serialize() interface{}
- type Vector2D
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Board ¶
type Board struct { // real primitives Points *hashset.HashSet Lines *hashset.HashSet Circles *hashset.HashSet HalfLines *hashset.HashSet Segments *hashset.HashSet // contains filtered or unexported fields }
Board is a geometry board containing all geometry objects
func (*Board) AddCircle ¶
AddCircle adds a circle and calculates its intersections with existing objects
func (*Board) AddCircleTrace ¶
AddCircleTrace adds a circle and calculates its intersections with existing objects, adding it to highlight sequence
func (*Board) AddHalfLine ¶
AddHalfLine adds a half line and its end point, do nothing else
func (*Board) AddLineTrace ¶
AddLineTrace adds a line and calculates its intersections with existing objects, adding it to highlight sequence
func (*Board) AddSegment ¶
AddSegment adds a segment and its end points, do nothing else
func (*Board) GeneratePlot ¶
GeneratePlot creates a folder of plots showing steps of the construction
func (*Board) GenerateRandomPoints ¶
GenerateRandomPoints returns a set of random points, from each geometry object
func (*Board) GenerateSinglePlot ¶
GenerateSinglePlot creates a plot file with fileName
func (*Board) RemoveLastGeometryObject ¶
func (gb *Board) RemoveLastGeometryObject()
RemoveLastGeometryObject removes the last line or circle in the output sequence
type Circle ¶
type Circle struct { hashset.Serializable // contains filtered or unexported fields }
Circle is a circle is uniquely determined by its center point and radius
func NewCircleByPoint ¶
NewCircleByPoint creates a circle by its center and a point on its side
func NewCircleByRadius ¶
NewCircleByRadius creates a circle by its center and its radius
func (*Circle) ContainsPoint ¶
ContainsPoint checks if a point is on the circle
func (*Circle) GetRandomPoint ¶
GetRandomPoint returns a random point on the circle
func (*Circle) IntersectCircle ¶
func (c *Circle) IntersectCircle(c2 *Circle) *Intersection
IntersectCircle returns the intersections with another circle
func (*Circle) IntersectHalfLine ¶
func (c *Circle) IntersectHalfLine(h *HalfLine) *Intersection
IntersectHalfLine returns intersections with a half line
func (*Circle) IntersectLine ¶
func (c *Circle) IntersectLine(l *Line) *Intersection
IntersectLine returns the intersections with a line
func (*Circle) IntersectSegment ¶
func (c *Circle) IntersectSegment(s *Segment) *Intersection
IntersectSegment returns intersections with a segment
type HalfLine ¶
type HalfLine struct { hashset.Serializable // contains filtered or unexported fields }
HalfLine is determined uniquely by its starting point and normalized direction vector
func NewHalfLineFromDirection ¶
NewHalfLineFromDirection creates a half line from its end point and a direction
func NewHalfLineFromTwoPoints ¶
NewHalfLineFromTwoPoints creates a half line from two points, with source as end point
func (*HalfLine) ContainsPoint ¶
ContainsPoint checks if a point is on the half line
func (*HalfLine) GetEndPoint ¶
GetEndPoint returns its end point
func (*HalfLine) GetRandomPoint ¶
GetRandomPoint returns a random point on the half line
func (*HalfLine) IntersectCircle ¶
func (h *HalfLine) IntersectCircle(c *Circle) *Intersection
IntersectCircle returns intersections with a circle
func (*HalfLine) IntersectHalfLine ¶
func (h *HalfLine) IntersectHalfLine(h2 *HalfLine) *Intersection
IntersectHalfLine returns intersections with another half line
func (*HalfLine) IntersectLine ¶
func (h *HalfLine) IntersectLine(l *Line) *Intersection
IntersectLine returns intersections with a line
func (*HalfLine) IntersectSegment ¶
func (h *HalfLine) IntersectSegment(s *Segment) *Intersection
IntersectSegment returns intersections with a segment
func (*HalfLine) PointInRange ¶
PointInRange checks if a point is in the coordinates of a half line
type Intersection ¶
Intersection is a type that stores the resulting intersections of two geometry objects
func NewIntersection ¶
func NewIntersection(pts ...*Point) *Intersection
NewIntersection return a new Intersection object
type Line ¶
type Line struct { hashset.Serializable // contains filtered or unexported fields }
Line is a line represented as ax+by+c==0, it is unique when the max coefficient is normalized to a fixed number, and a being non-negative.
func NewLineAsAngleBisector ¶
NewLineAsAngleBisector returns a line as angle bisector of pt1,pt2,pt3
func NewLineFromCoefficients ¶
NewLineFromCoefficients creates a line from coefficients
func NewLineFromDirection ¶
NewLineFromDirection creates a line from a point and a vector as direction
func NewLineFromHalfLine ¶
NewLineFromHalfLine creates a line from a half line
func NewLineFromSegment ¶
NewLineFromSegment creates a line from a segment
func NewLineFromTwoPoints ¶
NewLineFromTwoPoints creates a line from two points
func (*Line) ContainsPoint ¶
ContainsPoint checks whether a point is on the line
func (*Line) GetNormalVector ¶
GetNormalVector returns a normal vector of the line, length not specified
func (*Line) GetParallelLineWithPoint ¶
GetParallelLineWithPoint returns a parallel line through a point
func (*Line) GetParallelVector ¶
GetParallelVector returns a parallel vector of the line, length not specified
func (*Line) GetRandomPoint ¶
GetRandomPoint returns a random point on the line
func (*Line) GetTangentLineWithPoint ¶
GetTangentLineWithPoint returns a tangent line through a point
func (*Line) IntersectCircle ¶
func (l *Line) IntersectCircle(c *Circle) *Intersection
IntersectCircle returns intersections with a circle
func (*Line) IntersectHalfLine ¶
func (l *Line) IntersectHalfLine(h *HalfLine) *Intersection
IntersectHalfLine returns intersections with a half line
func (*Line) IntersectLine ¶
func (l *Line) IntersectLine(l2 *Line) *Intersection
IntersectLine returns intersections with another line
func (*Line) IntersectSegment ¶
func (l *Line) IntersectSegment(s *Segment) *Intersection
IntersectSegment returns intersections with a segment
type Point ¶
type Point struct { hashset.Serializable // contains filtered or unexported fields }
Point is a object containing its two coordinates
func (*Point) DistanceToLine ¶
DistanceToLine calculates the distance from the point to a line
func (*Point) InHalfLineRange ¶
InHalfLineRange checks if the point in the coordinate range of a half line. This function should only be used when the point is guaranteed to be on the line which the half line belong to
func (*Point) InSegmentRange ¶
InSegmentRange checks if the point in the coordinate range of a segment. This function should only be used when the point is guaranteed to be on the line which the segment belong to
func (*Point) OnHalfLine ¶
OnHalfLine checks if the point is on a half line
type Segment ¶
type Segment struct { hashset.Serializable // contains filtered or unexported fields }
Segment is uniquely determined by its sorted endpoints
func NewSegment ¶
NewSegment creates a segment from two points
func NewSegmentFromDirection ¶
NewSegmentFromDirection creates a segment with one point, a direction and length
func (*Segment) ContainsPoint ¶
ContainsPoint checks if a point is on the segment
func (*Segment) GetEndPoints ¶
GetEndPoints returns both end points of a segment
func (*Segment) GetRandomPoint ¶
GetRandomPoint returns a random point on the segment
func (*Segment) IntersectCircle ¶
func (s *Segment) IntersectCircle(c *Circle) *Intersection
IntersectCircle returns intersections with a circle
func (*Segment) IntersectHalfLine ¶
func (s *Segment) IntersectHalfLine(h *HalfLine) *Intersection
IntersectHalfLine returns intersections with a half line
func (*Segment) IntersectLine ¶
func (s *Segment) IntersectLine(l *Line) *Intersection
IntersectLine returns intersections with a line
func (*Segment) IntersectSegment ¶
func (s *Segment) IntersectSegment(s2 *Segment) *Intersection
IntersectSegment returns intersections with a segment
func (*Segment) PointInRange ¶
PointInRange checks whether a point is in the coordinates range of the segment
type Vector2D ¶
type Vector2D struct {
// contains filtered or unexported fields
}
Vector2D is a 2D vector object
func NewVector2D ¶
NewVector2D creates a 2D vector from its components
func NewVector2DFromTwoPoints ¶
NewVector2DFromTwoPoints creates a 2D vector from two points, pt1 to pt2
func (*Vector2D) NormalVector ¶
NormalVector gets a new normal vector by rotating Pi/2 counter clockwise