Module

Hylograph.Shape.Polygon

Package
purescript-hylograph-selection
Repository
afcondon/purescript-hylograph-selection

Pure PureScript Polygon Generators

Generates SVG polygon points strings for regular polygons and stars. No D3 dependency - pure trigonometry.

Usage

import Hylograph.Shape.Polygon (regularPolygonPoints, trianglePoints, starPoints)

-- Triangle centered at (100, 100) with radius 50
let points = trianglePoints 100.0 100.0 50.0
-- Result: "100,50 143.3,125 56.7,125"

-- Hexagon with 6 sides
let hex = regularPolygonPoints 100.0 100.0 50.0 6

-- 5-pointed star
let star = starPoints 100.0 100.0 50.0 25.0 5

Orientation: First vertex points upward (12 o'clock), vertices proceed clockwise. This matches D3's convention.

#regularPolygonPoints Source

regularPolygonPoints :: Number -> Number -> Number -> Int -> String

Generate points for a regular n-sided polygon

Arguments:

  • cx: Center x coordinate
  • cy: Center y coordinate
  • radius: Distance from center to vertices
  • sides: Number of sides (3 = triangle, 4 = square, etc.)

Returns: SVG points string "x1,y1 x2,y2 ..."

First vertex is at 12 o'clock (pointing up), vertices proceed clockwise.

#trianglePoints Source

trianglePoints :: Number -> Number -> Number -> String

Equilateral triangle (3 sides) First vertex points upward

#squarePoints Source

squarePoints :: Number -> Number -> Number -> String

Square (4 sides) First vertex points upward (like a diamond rotated 45°) For axis-aligned square, use diamondPoints

#diamondPoints Source

diamondPoints :: Number -> Number -> Number -> String

Diamond (4 sides, axis-aligned) Vertices at top, right, bottom, left This is the "natural" orientation for a diamond shape

#pentagonPoints Source

pentagonPoints :: Number -> Number -> Number -> String

Pentagon (5 sides)

#hexagonPoints Source

hexagonPoints :: Number -> Number -> Number -> String

Hexagon (6 sides) Flat-topped hexagon (first vertex at 12 o'clock)

#octagonPoints Source

octagonPoints :: Number -> Number -> Number -> String

Octagon (8 sides)

#starPoints Source

starPoints :: Number -> Number -> Number -> Number -> Int -> String

Generate points for a star shape

Arguments:

  • cx: Center x coordinate
  • cy: Center y coordinate
  • outerRadius: Distance to outer points
  • innerRadius: Distance to inner points (the "valleys")
  • points: Number of points (5 = classic 5-pointed star)

Returns: SVG points string for the star

A star alternates between outer and inner radii. A 5-pointed star has 10 vertices (5 outer, 5 inner).

#starPointsWithRotation Source

starPointsWithRotation :: Number -> Number -> Number -> Number -> Int -> Number -> String

Star with custom rotation

Arguments:

  • cx, cy: Center coordinates
  • outerRadius: Distance to outer points
  • innerRadius: Distance to inner points
  • numPoints: Number of points
  • rotation: Rotation in radians (0 = first point at 12 o'clock)

#pointsToString Source

pointsToString :: Array { x :: Number, y :: Number } -> String

Convert array of points to SVG points string

Modules
Data.DependencyGraph
Hylograph.AST
Hylograph.Axis.Axis
Hylograph.Brush
Hylograph.Brush.FFI
Hylograph.Brush.Types
Hylograph.Classify
Hylograph.Data.Graph
Hylograph.Data.Graph.Algorithms
Hylograph.Data.Node
Hylograph.Data.Tree
Hylograph.Expr.Animation
Hylograph.Expr.Attr
Hylograph.Expr.Datum
Hylograph.Expr.Expr
Hylograph.Expr.Friendly
Hylograph.Expr.Integration
Hylograph.Expr.Interpreter.CodeGen
Hylograph.Expr.Interpreter.Eval
Hylograph.Expr.Interpreter.Meta
Hylograph.Expr.Interpreter.PureSVG
Hylograph.Expr.Interpreter.SVG
Hylograph.Expr.Path
Hylograph.Expr.Path.Generators
Hylograph.Expr.Sugar
Hylograph.Expr.Units
Hylograph.HATS
Hylograph.HATS.Friendly
Hylograph.HATS.InterpreterTick
Hylograph.HATS.Transitions
Hylograph.Interaction.Brush
Hylograph.Interaction.Coordinated
Hylograph.Interaction.Pointer
Hylograph.Interaction.Zoom
Hylograph.Internal.Attribute
Hylograph.Internal.Behavior.FFI
Hylograph.Internal.Behavior.Types
Hylograph.Internal.Capabilities.Selection
Hylograph.Internal.Capabilities.Transition
Hylograph.Internal.FFI
Hylograph.Internal.Selection.Join
Hylograph.Internal.Selection.Operations
Hylograph.Internal.Selection.Operations.Conversions
Hylograph.Internal.Selection.Operations.Helpers
Hylograph.Internal.Selection.Operations.Selection
Hylograph.Internal.Selection.Query
Hylograph.Internal.Selection.Types
Hylograph.Internal.Transition.FFI
Hylograph.Internal.Transition.Manager
Hylograph.Internal.Transition.Scene
Hylograph.Internal.Transition.Types
Hylograph.Internal.Types
Hylograph.Interpreter.D3
Hylograph.Interpreter.English
Hylograph.Interpreter.Mermaid
Hylograph.Interpreter.MetaAST
Hylograph.Interpreter.SemiQuine
Hylograph.Interpreter.SemiQuine.TreeToCode
Hylograph.Interpreter.SemiQuine.Types
Hylograph.Render
Hylograph.Scale
Hylograph.Scale.FP
Hylograph.Shape.Arc
Hylograph.Shape.Pie
Hylograph.Shape.Polygon
Hylograph.Tooltip
Hylograph.Transform
Hylograph.TreeDSL
Hylograph.TreeDSL.ShapeTree
Hylograph.Unified
Hylograph.Unified.Attribute
Hylograph.Unified.DataDSL
Hylograph.Unified.Display
Hylograph.Unified.Examples
Hylograph.Unified.Join
Hylograph.Unified.Sugar