Class: Magick::Geometry

### Home Classes Methods

### In Files

- lib/rmagick_internal.rb

### Parent

Object

### Methods

- ::from_s
- ::new
- #to_s

### Files

- Makefile

### Class/Module Index

Quicksearch

- Magick
- Magick::DestroyedImageError
- Magick::Draw
- Magick::Enum
- Magick::FatalImageMagickError
- Magick::Geometry
- Magick::GeometryValue
- Magick::GradientFill
- Magick::HatchFill
- Magick::IPTC
- Magick::IPTC::Application
- Magick::IPTC::Envelope
- Magick::IPTC::ObjectData
- Magick::IPTC::Post_ObjectData_Descriptor
- Magick::IPTC::Pre_ObjectData_Descriptor
- Magick::Image
- Magick::Image::DrawOptions
- Magick::Image::Info
- Magick::Image::PolaroidOptions
- Magick::Image::View
- Magick::Image::View::Pixels
- Magick::Image::View::Rows
- Magick::ImageList
- Magick::ImageList::Montage
- Magick::ImageMagickError
- Magick::OptionalMethodArguments
- Magick::Pixel
- Magick::RVG
- Magick::RVG::Circle
- Magick::RVG::ClipPath
- Magick::RVG::Describable
- Magick::RVG::Duplicatable
- Magick::RVG::Ellipse
- Magick::RVG::Embellishable
- Magick::RVG::Group
- Magick::RVG::Image
- Magick::RVG::ImageConstructors
- Magick::RVG::Line
- Magick::RVG::Path
- Magick::RVG::PathData
- Magick::RVG::Pattern
- Magick::RVG::PolyShape
- Magick::RVG::Polygon
- Magick::RVG::Polyline
- Magick::RVG::PreserveAspectRatio
- Magick::RVG::Rect
- Magick::RVG::ShapeConstructors
- Magick::RVG::Stretchable
- Magick::RVG::StructureConstructors
- Magick::RVG::Stylable
- Magick::RVG::Text
- Magick::RVG::TextBase
- Magick::RVG::TextConstructors
- Magick::RVG::Transformable
- Magick::RVG::Use
- Magick::RVG::UseConstructors
- Magick::RVG::Utility
- Magick::RVG::Utility::DefaultTextStrategy
- Magick::RVG::Utility::GraphicContext
- Magick::RVG::Utility::LRTextStrategy
- Magick::RVG::Utility::RLTextStrategy
- Magick::RVG::Utility::TBTextStrategy
- Magick::RVG::Utility::TextAttributes
- Magick::RVG::Utility::TextStrategy
- Magick::SolidFill
- Magick::TextureFill
- Object

No matching classes.

# Magick::Geometry

### Constants

FLAGS
H
RE
RFLAGS
W

  Construct an object from a geometry string

X
Y

### Attributes

flag[RW]
height[RW]
width[RW]
x[RW]
y[RW]

### Public Class Methods

from_s(str) click to toggle source

    # File lib/rmagick_internal.rb, line 98
    def Geometry.from_s(str)

        m = RE.match(str)
        if m
            width  = (m[1] || m[2]).to_f
            height = (m[3] || m[4]).to_f
            x      = m[5].to_i
            y      = m[6].to_i
            flag   = RFLAGS[m[7]]
        else
            Kernel.raise ArgumentError, "invalid geometry format"
        end
        if str['%']
          flag = PercentGeometry
        end
        Geometry.new(width, height, x, y, flag)
    end

new(width=nil, height=nil, x=nil, y=nil, flag=nil) click to toggle source

    # File lib/rmagick_internal.rb, line 62
    def initialize(width=nil, height=nil, x=nil, y=nil, flag=nil)
        raise(ArgumentError, "width set to #{width.to_s}") if width.is_a? GeometryValue
        raise(ArgumentError, "height set to #{height.to_s}") if height.is_a? GeometryValue
        raise(ArgumentError, "x set to #{x.to_s}") if x.is_a? GeometryValue
        raise(ArgumentError, "y set to #{y.to_s}") if y.is_a? GeometryValue

        # Support floating-point width and height arguments so Geometry
        # objects can be used to specify Image#density= arguments.
        if width == nil
            @width = 0
        elsif width.to_f >= 0.0
            @width = width.to_f
        else
            Kernel.raise ArgumentError, "width must be >= 0: #{width}"
        end
        if height == nil
            @height = 0
        elsif height.to_f >= 0.0
            @height = height.to_f
        else
            Kernel.raise ArgumentError, "height must be >= 0: #{height}"
        end

        @x    = x.to_i
        @y    = y.to_i
        @flag = flag

    end

### Public Instance Methods

to_s() click to toggle source

Convert object to a geometry string

    # File lib/rmagick_internal.rb, line 117
    def to_s
        str = ''
        if @width > 0
          fmt = @width.truncate == @width ? "%d" : "%.2f"
          str << sprintf(fmt, @width)
          str << '%' if @flag == PercentGeometry
        end

        if (@width > 0 && @flag != PercentGeometry) || (@height > 0)
          str << 'x'
        end

        if @height > 0
          fmt = @height.truncate == @height ? "%d" : "%.2f"
          str << sprintf(fmt, @height)
          str << '%' if @flag == PercentGeometry
        end
        str << sprintf("%+d%+d", @x, @y) if (@x != 0 || @y != 0)
        if @flag != PercentGeometry
          str << FLAGS[@flag.to_i]
        end
        str
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.